b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

socket setsockopt_setsockopt设置超时_socket阻塞时间设置(5)

电脑杂谈  发布时间:2017-05-14 03:06:00  来源:网络整理

从这里我们可以看出SO_SNDBUF的选项值只是所用的一个提示值。内核会最终确定为SO_SNDBUF所用的最佳值。

查看更多的内核源码,我们可以看到类似的情况也适用于SO_RCVBUF选项。如下面的一段摘录的代码:

427 case SO_RCVBUF:

428 /* Don't error on this BSD doesn't and if you think

429 about it this is right. Otherwise apps have to

430 play 'guess the biggest size' games. RCVBUF/SNDBUF

431 are treated in BSD as hints */

432

433 if (val > sysctl_rmem_max)

434 val = sysctl_rmem_max;

435 set_rcvbuf:

436 sk->sk_userlocks |= SOCK_RCVBUF_LOCK;

437 /*

438 * We double it on the way in to account for

439 * "struct sk_buff" etc. overhead. Applications

440 * assume that the SO_RCVBUF setting they make will

441 * allow that much actual data to be received on that

442 * socket.

443 *

444 * Applications are unaware that "struct sk_buff" and

445 * other overheads allocate from the receive buffer

446 * during socket buffer allocation.

447 *

448 * And after considering the possible alternatives,

449 * returning the value we actually used in getsockopt

450 * is the most desirable behavior.

451 */

452 if ((val * 2) < SOCK_MIN_RCVBUF)

453 sk->sk_rcvbuf = SOCK_MIN_RCVBUF;

454 else

455 sk->sk_rcvbuf = val * 2;

456 break;

取得套接口类型

实际上我们只可以得到一些套接口选项。SO_TYPE就是其中的一例。这个选项会允许传递套接口的一个子函数来确定正在处理的是哪一种套接口类型。

如下面是一段得到套接口s类型的示例代码:

/*gettype.c

*

* Get SO_TYPE Option:

*/

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <string.h>

#include <errno.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <assert.h>

/*

* This function report the error and


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-46983-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 田邦杰
      田邦杰

      我相信我们的政府一定能有不战而屈人之兵的智慧

    • 何盼
      何盼

      高铁坐吗

    • 莫将
      莫将

      为什么还会失败

    热点图片
    拼命载入中...