setsockopt函数的第4个参数,也就是optval(选项值)的实参,在调用完setsockopt函数之后便可弃用。因此这个实参可使用一个局部变量来充当,如果是由新分配的内存来充当这个实参的话,那就要在调用完setsockopt之后释放对应的内存,否则就泄漏咯。
http://blog.csdn.net/chary8088/article/details/2486377
亮点:
示例代码如下:
intfd, on = 1;
…
/* 此处是创建套接字等操作,出于篇幅的考虑省略*/
…
setsockopt (fd, SOL_TCP, TCP_CORK, &on, sizeof (on)); /* cork */
write (fd, …);
fprintf (fd, …);
sendfile (fd, …);
write (fd, …);
sendfile (fd, …);
…
on = 0;
setsockopt (fd, SOL_TCP, TCP_CORK, &on, sizeof (on)); /* 拔去塞子 */
HxLauncher: Launch Android applications by voice commands