#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>
int main(int argc,char **argv)
{
int err = -1; /* 返回值 */
int socketID = -1; /* socket描述符 */
int snd_size = 0; /* 发送缓冲区大小 */
int rcv_size = 0; /* 接收缓冲区大小 */
socklen_t optlen; /* 选项值长度 */
/*
* 建立一个TCP套接字
*/
socketID = socket(PF_INET,SOCK_STREAM,0);
if( socketID == -1)
{
printf("建立套接字错误\n");
return -1;
}
/*
* 获取原始发送缓冲区大小
*/
optlen = sizeof(snd_size);
err = getsockopt(socketID, SOL_SOCKET, SO_SNDBUF,&snd_size, &optlen);
if(err<0)
{
printf("获取发送缓冲区大小错误\n");
close(socketID);
return -1;
}
/*
* 获取原始接收缓冲区大小
*/
optlen = sizeof(rcv_size);
err &
Linux下设置socket的发送和接收缓冲区
于 2023-03-15 19:18:08 首次发布