SO_RCVBUF:接受缓冲区大小
SO_SNDBUF: 发送缓冲区大小
操作程序举例:
socklen_t optlen;
optlen = sizeof(int);
/*get SO_RCVBUF*/
int rcvbuflen;
if(0 != getsockopt(listenfd,SOL_SOCKET,SO_RCVBUF,&rcvbuflen,&optlen)){
printf("Getsockopt error.\n");
exit(1);
}
/*get SO_SNDBUF*/
int sndbuflen;
if(0 != getsockopt(listenfd,SOL_SOCKET,SO_SNDBUF,&sndbuflen,&optlen)){
printf("Getsockopt error.\n");
exit(1);
}
printf("before-->receive:%d,send:%d\n",rcvbuflen,sndbuflen);
/*set SO_RCVBUF*/
rcvbuflen = 512000;
if(0 != setsockopt(listenfd,SOL_SOCKET,SO_RCVBUF,&rcvbuflen,optlen)){
printf("Setsockopt error.\n");
exit(1);
}
/*set SO_SNDBUF*/
sndbuflen = 512000;
if(0 != setsockopt(listenfd,SOL_SOCKET,SO_SNDBUF,&sndbuflen,optlen)){
printf("Setsockopt error.\n");
exit(1);
}
if(0 != getsockopt(listenfd,SOL_SOCKET,SO_RCVBUF,&sndbuflen,&optlen)){
printf("Getsockopt error.\n");
exit(1);
}
if(0 != getsockopt(listenfd,SOL_SOCKET,SO_SNDBUF,&sndbuflen,&optlen)){
printf("Getsockopt error.\n");
exit(1);
}
printf("after-->receive:%d,send:%d\n",rcvbuflen,sndbuflen);