I have a test unix domain server which has the following SO_SNDBUF is set to 1024000 while connection come in :
for ( ; ; ) {
connfd = accept(fdfromps, 0, 0);
int new_size = 1024000 ;
setsockopt(connfd, SOL_SOCKET, SO_SNDBUF , &new_size, sizeof(new_size));
SetSocketBlockingEnabled(connfd,false) ;
FDArray[connfd] = 1 ;
} //for
also set this fd to be nonblocking
The client won't recv any package what server send to client , so I can measure the counters while server send encounter error(errno=11) , the source is as the following :
Test1 :
strcpy(msg,"1234567890");
Test2 :
sprintf(msg,"%s%s%s%s%s",
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890") ;
and the test code :
sprintf(strsend,"%04d%s",strlen(msg),msg) ;
int icnt = 0 ;
pthread_detach(pthread_self());
while( 1 ){
for(int idx=0;idx<20;idx++){
if( FDArray[idx] == 1 ){
int nread = send(idx,strsend,strlen(strsend),MSG_NOSIGNAL);
if( nread < 0 ){
printf("send to (%d) ...errno=(%d) \n",idx,errno );
FDArray[idx] = 0 ;
}else{
printf("send to (%d) ... nread=(%d) \n", idx ,nread ) ;
++icnt ;
}
}
}
printf("......(%d) \n",icnt) ;
usleep( 10000 ) ;
}
Test1 which msg has 14 bytes , the icnt is 2667 , Test2 which msg has 504 bytes, the icnt is 1600 .
I am confused by the number 2667 and 1600 , since 504 bytes are much more than 14 bytes , I expect icnt of Test2 should be much bigger than icnt in Test1 , anything can explain that ?!
Env :
sysctl -a | grep "mem"
:
net.core.rmem_default = 212992
net.core.rmem_max = 1024000
net.core.wmem_default = 212992
net.core.wmem_max = 1024000
uname -a
:
3.10.0-327.el7.x86_64
Edit :
int res = 0 ;
optlen = sizeof(sendbuff);
getsockopt(connfd, SOL_SOCKET, SO_SNDBUF , &sendbuff, &optlen);
if(res == -1)
printf("Error getsockopt one");
else
printf("send buffer size = %d\n", sendbuff);
int new_size = 512000 ;
setsockopt(connfd, SOL_SOCKET, SO_SNDBUF , &new_size, sizeof(new_size));
getsockopt(connfd, SOL_SOCKET, SO_SNDBUF , &sendbuff, &optlen);
if(res == -1)
printf("Error getsockopt one");
else
printf("send buffer size = %d\n", sendbuff);
Edit 2 :
ss -ax | grep "testud" ## testud is the nnix domain name
will show while Send-Q is around 1024000 , the nonblocking send get errno =11 ever since , that is what I observed and don't know would it help .