工作日记

来源:互联网 发布:青岛seo网络优化 编辑:程序博客网 时间:2024/05/20 06:38

Git

  • git reset --hard 引入的一个问题
  • git rebase 压缩提交及其基本原理
  • git fast forward基本原理
  • git merge tools p4merge基本介绍
  • git revert merge commit

C++

C++11 和 C++14 对于sizeof的功能有差异,如下:

#include <iostream>#include <unistd.h>#define SOCKET_BUFFER_SIZE (getpagesize() < 8192L ? getpagesize() : 8192L)void test(uint8_t* buf, ssize_t len) {  std::cout << len << std::endl;}int main() {  uint8_t recv_buf[SOCKET_BUFFER_SIZE] = {0};  test(recv_buf, sizeof(recv_buf));  return 0;}[tianqian.zyf@e010125028182.bja /home/tianqian.zyf]$g++ -std=c++11 test.cc [tianqian.zyf@e010125028182.bja /home/tianqian.zyf]$./a.out 4096[tianqian.zyf@e010125028182.bja /home/tianqian.zyf]$g++ -std=c++14 test.cc test.cc: In function ‘int main()’:test.cc:13:33: warning: taking sizeof array of runtime bound [-Wvla]   test(recv_buf, sizeof(recv_buf));                                 ^[tianqian.zyf@e010125028182.bja /home/tianqian.zyf]$./a.out 1

这里写图片描述

Http

  • POST 和 Url Encode
       POST data时是否要url encode,这取决于POST数据时带的header,如果是application/x-www-form-urlencoded 这是需要进行url encode的,因为本质上要提交的数据就是一个QueryString,使用&分割,这个头部是默认的,如果是 multipart/form-data就不需要进行url encode。
       要进行url encode的原因是url的格式有规范的,根据规范url只能包含 alpha | digit | safe | extra | escape 这类字符,如果用户输入的内容不在这个范围内就需要进行转义,这就是url encode的由来。
       虽然通过url encode可以保证用户输入的数据可以组合成一个合法的url,但是这个encode的代价有点大,一个字节的特殊字符encode后变成了了三个字节的字符,通常encode成%开头后面是两个十六进制的数值(具体转换见Reference [2]),那么对于二进制来说这个代价就有点大了,二进制数据中会存在很多不可见的特殊字符,如果按照1个字节转换为3个字节来算的话,那么大小就成了问题,所以引入了multipart/form-data头部,避免了数据的encode开销,一般上传数据的时候使用的就是这个头部。使用这个头部POST数据时也是以多个key,value的组合,不过这里的每一组key,value有自己的专属类型MIME,根据这个MIME可以解析POST上来的数据,可以是image、base64、mp4等等,每一组key,value以一个特殊的字符分割。

Reference
[1] application/x-www-form-urlencoded or multipart/form-data?
[2] Introduction to URL Encoding
[3] MIME

系统编程

MSG_NOSIGNAL (since Linux 2.2)    Requests not to send SIGPIPE on errors on stream oriented sockets when the other end breaks     the connection.  The EPIPE error is still returned.

   默认情况,send发送网络数据包时,如果说这个链接已经被对端close掉了,那么send发送数据会触发SIGPIPE信号,所以一般服务器都会ignore SIGPIPE,但是Linux2.2提供了MSG_NOSIGNAL选项,可以在send的时候即使链接被对端close掉了,也不会触发SIGPIPE信号,而是返回一个EPIPE error。

   setrlimit 设置RLIMIT_STACK的时候,必须在程序未执行之前进行设置,否则并不生效,如果是在程序启动后在程序
内部调用setrlimit RLIMIT_STACK的时候,只会改变当前进程的stack size的属性,但是没有生效,只有通过这个程序
execve派生的进程才会继承这个堆栈属性值,并生效。

  -  If the stack size soft resource limit (see the description of     RLIMIT_STACK in setrlimit(2)) is set to a value other than unlim‐     ited, then this value defines the default stack size for new     threads.  To be effective, this limit must be set before the pro‐     gram is executed, perhaps using the ulimit -s shell built-in com‐     mand (limit stacksize in the C shell).

Third Party Library

重构与测试