#include int main(void)
{
int socketFd;
if ((socketFd = socket(PF_INET, SOCK_STREAM,0)) < 0)
{
/* 获取socket发送和接收缓冲区的大小 */
optlen = sizeof(snd_size);
err = getsockopt(socketFd, SOL_SOCKET, SO_SNDBUF, &snd_size, &optlen);
if (err < 0)
{
printf("get send buff failed!\n");
}
optlen = sizeof(rcv_size);
err = getsockopt(socketFd, SOL_SOCKET, SO_RCVBUF, &rcv_size, &optlen);
if (err < 0)
{
printf("get rev buff failed!\n");
}
printf("senBuffLen:%d\n", snd_size);
printf("recBuffLen:%d\n", rcv_size);
/* 设置socket发送和接收缓冲区大小都为8K */
snd_size = 8*1024;
optlen = sizeof(rcv_size);
err = setsockopt(socketFd, SOL_SOCKET, SO_SNDBUF, &snd_size, optlen);
if(err<0)
{
printf("set send buff failed!\n");
}
rcv_size = 8*1024;
optlen = sizeof(rcv_size);
err = setsockopt(socketFd,SOL_SOCKET,SO_RCVBUF, (char *)&rcv_size, optlen);
if(err<0){
printf("set rev buff failed!\n");
}
/* 获取socket接收和发送缓冲区大小 */
optlen = sizeof(snd_size);
err = getsockopt(socketFd, SOL_SOCKET, SO_SNDBUF, &snd_size, &optlen);
if (err < 0)
{
printf("get send buff failed!\n");
}
optlen = sizeof(rcv_size);
err = getsockopt(socketFd, SOL_SOCKET, SO_RCVBUF, &rcv_size, &optlen);
if (err < 0)
{
printf("get rev buff failed!\n");
}
printf("senBuffLen:%d\n", snd_size);
printf("recBuffLen:%d\n", rcv_size);
return 0;
}