网站空间是什么意思,易企秀在线制作免费,wordpress禁用媒体库,特色专业建设展示网站#xff08;1#xff09; 先介绍下后面的代码里要用到的基础函数#xff1a; 以及#xff1a; #xff08;2#xff09; 接着给出现代版的 读写 socket 参数的系统函数 #xff1a; 以及#xff1a; #xff08;3#xff09; 给出 一言的 范例代码#xff0c;获取…1 先介绍下后面的代码里要用到的基础函数 以及 2 接着给出现代版的 读写 socket 参数的系统函数 以及 3 给出 一言的 范例代码获取当代 linux 系统的 tcp 套接字的缓存大小
#include stdio.h
#include stdlib.h
#include string.h
#include unistd.h
#include arpa/inet.h
#include sys/socket.h
#include sys/types.hint main()
{int sockfd , sndbuf, rcvbuf ; socklen_t optlen;sockfd socket(AF_INET, SOCK_STREAM, 0); // 创建一个 TCP 套接字if (sockfd 0) { perror(socket); exit(EXIT_FAILURE); }// 获取发送缓存大小optlen sizeof(sndbuf);if (getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (void *)sndbuf, optlen) 0) {perror(getsockopt SO_SNDBUF);close(sockfd); exit(EXIT_FAILURE);}printf(Send buffer size: %d bytes\n, sndbuf);// 获取接收缓存大小optlen sizeof(rcvbuf);if (getsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, (void *)rcvbuf, optlen) 0) {perror(getsockopt SO_RCVBUF);close(sockfd); exit(EXIT_FAILURE);}printf(Receive buffer size: %d bytes\n, rcvbuf);close(sockfd); // 关闭套接字return 0;
}给出 ubantu 的打印结果 跟 30 年前的 伯克利系统里的缓存设置已经有了很大的差别 以下是 30 年前的 tcp/ip 协议的系统缓存设置 4
谢谢