Changeset 48 in libcf
- Timestamp:
- 03/29/13 16:04:12 (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cf_socket.c
r47 r48 72 72 73 73 static int 74 CF_Socket_Local_SetLinger (const int sock) 75 { 76 struct linger linger; 77 78 linger.l_onoff = 1; 79 linger.l_linger = 0; 80 81 return CF_Socket_SetOption (sock, 82 SO_LINGER, 83 &linger, 84 sizeof (linger)); 85 } 86 87 static int 88 CF_Socket_Local_SetReUseAddr (const int sock) 89 { 90 int reuseaddr = 1; 91 92 return CF_Socket_SetOption (sock, 93 SO_REUSEADDR, 94 &reuseaddr, 95 sizeof (reuseaddr)); 96 } 97 98 static int 74 99 CF_Socket_Local_CheckTimeout (const int sock, 75 100 const int timeout) … … 281 306 struct sockaddr_in address; 282 307 struct hostent * hostEnt; 283 struct linger linger;284 308 285 309 int retval = 0; … … 300 324 address.sin_port = htons (port); 301 325 address.sin_addr.s_addr = inet_addr (ip); 302 303 linger.l_onoff = 1;304 linger.l_linger = 0;305 326 306 327 TRY … … 323 344 324 345 /* 4. set options */ 325 result = CF_Socket_SetOption (sock, SO_LINGER, &linger, sizeof (linger));326 if (result < 0)346 if (CF_Socket_Local_SetLinger (sock) < 0 || 347 CF_Socket_Local_SetReUseAddr (sock) < 0 ) 327 348 { 328 349 result = CF_ERROR_SOCKET_SET_OPTION; … … 425 446 TRY 426 447 { 448 if (CF_Socket_Local_SetLinger (sock) < 0 || 449 CF_Socket_Local_SetReUseAddr (sock) < 0 ) 450 { 451 result = CF_ERROR_SOCKET_SET_OPTION; 452 TRY_BREAK; 453 } 454 427 455 result = bind (sock, (struct sockaddr *) &address, sizeof (struct sockaddr)); 428 456 if (result < 0) -
trunk/test/socket_client.c
r46 r48 32 32 fprintf (stderr, "error : recv (%d)\n", result); 33 33 } 34 fprintf (stderr, "client recv : %s(%d)\n", buf, ,result);34 fprintf (stderr, "client recv : %s(%d)\n", buf, result); 35 35 36 36 CF_Socket_Close (sock);
Note:
See TracChangeset
for help on using the changeset viewer.