功能:设置客户端链接属性,但是编译的时候发现没有IPPROTO_TCP,而且 提示Error while seting the client socket,意思就算后面的设置也有错误, C/C++ code:
void set_client_opt(const int client_id) { int value=0; int time = SENDTIMEOUT; int flag = 1; struct linger linger_c;
if (client_id <=0) exit_fatal("Error client id while set the opt");
linger_c.l_onoff = 1; linger_c.l_linger = 0 ;
/*value += setsockopt(client_id,IPPROTO_TCP,TCP_NODELAY,(const char *)&flag,sizeof(int));*/ value += setsockopt(client_id,SOL_SOCKET,SO_LINGER,(const char *)&linger_c,sizeof(linger_c)); value += setsockopt(client_id,SOL_SOCKET,SO_SNDTIMEO,(const char *)&time,sizeof(time));
if (value < 0) /*exit_fatal("Error while seting the client socket");*/ printf("Error while seting the client socket\n"); else printf("Seting the client socket success \n"); }