Changeset 59 in cheroxy
- Timestamp:
- 12/26/12 11:00:40 (11 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/CRXSocket.h
r57 r59 87 87 CRXSocket & operator = (int aSocket); 88 88 89 int SetOption (const int aOptName, 90 const void * aOptVal, 91 const size_t aOptLen); 92 89 93 int SetTimeout (const int aTimeout); 90 94 -
trunk/src/CRXSocket.cpp
r58 r59 76 76 /*----------------------------------------------------------------*/ 77 77 return *this; 78 } 79 80 int 81 CRXSocket::SetOption (const int aOptName, 82 const void * aOptVal, 83 const size_t aOptLen) 84 { 85 int aResult = 0; 86 /*----------------------------------------------------------------*/ 87 aResult = setsockopt (mSocket, 88 SOL_SOCKET, 89 aOptName, 90 #ifdef _WIN32 91 (char *) aOptVal, 92 #else 93 aOptVal, 94 #endif 95 (socklen_t) aOptLen); 96 if (aResult < 0) 97 { 98 aResult = ERROR_TCPSOCKET_FAILED_TO_SET_SOCKOPT; 99 CRX_ERROR_SET (aResult, "Failed to set socket option."); 100 } 101 /*----------------------------------------------------------------*/ 102 103 return aResult; 78 104 } 79 105 … … 98 124 return 0; 99 125 100 aResult = setsockopt (mSocket, 101 SOL_SOCKET, 102 SO_RCVTIMEO, 126 aResult = SetOption (SO_RCVTIMEO, 103 127 #ifdef _WIN32 104 (char *)&aTimeMilliSec,105 128 &aTimeMilliSec, 129 sizeof (aTimeMilliSec)); 106 130 #else 107 108 (socklen_t)sizeof (aTimeVal));109 #endif 110 if (aResult < 0) 111 { 112 aResult = ERROR_TCPSOCKET_FAILED_TO_SET_ SOCKOPT;113 CRX_ERROR_SET (aResult, "Failed to set socket option.");131 &aTimeVal, 132 sizeof (aTimeVal)); 133 #endif 134 if (aResult < 0) 135 { 136 aResult = ERROR_TCPSOCKET_FAILED_TO_SET_TIMEOUT; 137 CRX_ERROR_SET (aResult, "Failed to set socket tieout."); 114 138 } 115 139 /*----------------------------------------------------------------*/ … … 242 266 aLinger.l_onoff = 1; 243 267 aLinger.l_linger = 0; 244 aResult = setsockopt (mSocket, 245 SOL_SOCKET, 246 SO_LINGER, 247 #ifdef _WIN32 248 (char *) &aLinger, 249 #else 268 aResult = SetOption (SO_LINGER, 250 269 &aLinger, 251 #endif 252 (socklen_t) sizeof (aLinger)); 270 sizeof (aLinger)); 253 271 if (aResult < 0) 254 272 { … … 271 289 CRX_ERROR_SET (aResult, "Failed to connect (%d).", GetSystemErrorCode ()); 272 290 } 273 274 /*----------------------------------------------------------------*/ 291 /*----------------------------------------------------------------*/ 292 275 293 return aResult; 276 294 } … … 294 312 } 295 313 296 aResult = setsockopt (mSocket, 297 SOL_SOCKET, 298 SO_REUSEADDR, 299 #ifdef _WIN32 300 (char *) &aReuseAddress, 301 #else 302 &aReuseAddress, 303 #endif 304 (socklen_t) sizeof (aReuseAddress)); 314 aResult = SetOption (SO_REUSEADDR, 315 &aReuseAddress, 316 sizeof (aReuseAddress)); 305 317 if (aResult < 0) 306 318 {
Note:
See TracChangeset
for help on using the changeset viewer.