Changeset 61 in cheroxy
- Timestamp:
- 01/25/13 17:54:39 (11 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/CRXException.h
r35 r61 59 59 } while (0) 60 60 61 62 #define CRX_SYSTEM_ERROR() CRXException::GetSystemErrorCode () 63 61 64 class CRXException 62 65 { … … 70 73 71 74 public: 75 static int GetSystemErrorCode (void); 76 77 public: 72 78 /* get */ 73 79 int GetErrorCode (void) const; 74 80 75 81 std::string GetErrorMessage (void) const; 76 77 int GetSystemErrorCode (void) const;78 82 79 83 /* set */ -
trunk/include/CRXSocket.h
r59 r61 36 36 #define ERROR_TCPSOCKET_FAILED_TO_SET_SOCKOPT ERROR_TCPSOCKET - 12 37 37 #define ERROR_TCPSOCKET_FAILED_TO_SET_TIMEOUT ERROR_TCPSOCKET - 13 38 #define ERROR_TCPSOCKET_FAILED_TO_GET_SOCKOPT ERROR_TCPSOCKET - 14 38 39 39 40 class CRXSocket : public CRXException 40 41 { 41 42 private: 42 static bool mInitialized;43 43 struct sockaddr_in mAddress; 44 44 int mSocket; … … 73 73 * common functions 74 74 */ 75 CRXSocket (int aSocket = 0);75 CRXSocket (int aSocket = -1); 76 76 77 77 ~CRXSocket (void); … … 86 86 87 87 CRXSocket & operator = (int aSocket); 88 89 int GetOption (const int aOptName, 90 void * aOptVal, 91 size_t * aOptLen); 88 92 89 93 int SetOption (const int aOptName, -
trunk/src/CRXException.cpp
r27 r61 43 43 44 44 int 45 CRXException::GetSystemErrorCode (void) const45 CRXException::GetSystemErrorCode (void) 46 46 { 47 47 /*----------------------------------------------------------------*/ -
trunk/src/CRXProxy.cpp
r56 r61 96 96 { 97 97 aResult = mClient.Receive (&aBuffer, 1); 98 if (aResult < 0)98 if (aResult == -1) 99 99 { 100 100 aResult = ERROR_PROXY_FAILED_TO_RECEIVE_REQUEST; … … 159 159 CRX_ADD_SUBCLASS_ERROR (mServer); 160 160 CRX_ERROR_SET (aResult, "Failed to receive from server."); 161 return aResult;161 break; 162 162 } 163 163 else if (aResult == 0) … … 184 184 aResult = ERROR_PROXY_FAILED_TO_SET_RESPONSE; 185 185 CRX_ERROR_SET (aResult, "Failed to set response."); 186 return aResult;186 break; 187 187 } 188 188 else if (aResult == 0) … … 200 200 int aResult = 0; 201 201 int aLength = 0; 202 202 203 /*----------------------------------------------------------------*/ 203 204 aLength = mHttpResponse.GetHeader ().length (); -
trunk/src/CRXSocket.cpp
r59 r61 11 11 #endif 12 12 13 bool CRXSocket::mInitialized = false;13 bool gInitialized = false; 14 14 15 15 CRXSocket::CRXSocket (int aSocket) 16 : mSocket (aSocket)17 16 { 18 17 /*----------------------------------------------------------------*/ … … 20 19 21 20 memset ((void *)&mAddress, 0x0, sizeof (struct sockaddr_in)); 21 22 Attach (aSocket); 22 23 /*----------------------------------------------------------------*/ 23 24 } … … 33 34 CRXSocket::Attach (int aSocket) 34 35 { 36 int aResult = 0; 37 int aReuseAddress = 0; 38 size_t aReuseAddressLength = sizeof (aReuseAddress); 39 35 40 /*----------------------------------------------------------------*/ 36 41 mSocket = aSocket; 42 43 if (mSocket < 0) 44 return ; 45 46 aResult = GetOption (SO_REUSEADDR, 47 &aReuseAddress, 48 &aReuseAddressLength); 49 if (aResult < 0) 50 { 51 aResult = ERROR_TCPSOCKET_FAILED_TO_GET_SOCKOPT; 52 CRX_ERROR_SET (aResult, "Failed to get socket option (reuseaddr).(%d)", mSocket); 53 } 54 55 if (aReuseAddress == 1) 56 return ; 57 58 aReuseAddress = 1; 59 60 aResult = SetOption (SO_REUSEADDR, 61 &aReuseAddress, 62 sizeof (aReuseAddress)); 63 if (aResult < 0) 64 { 65 aResult = ERROR_TCPSOCKET_FAILED_TO_SET_SOCKOPT; 66 CRX_ERROR_SET (aResult, "Failed to set socket option (reuseaddr).(%d)", mSocket); 67 } 37 68 /*----------------------------------------------------------------*/ 38 69 } … … 45 76 /*----------------------------------------------------------------*/ 46 77 mSocket = 0; 47 48 78 /*----------------------------------------------------------------*/ 49 79 return aSocket; … … 76 106 /*----------------------------------------------------------------*/ 77 107 return *this; 108 } 109 110 int 111 CRXSocket::GetOption (const int aOptName, 112 void * aOptVal, 113 size_t * aOptLen) 114 { 115 int aResult = 0; 116 117 /*----------------------------------------------------------------*/ 118 aResult = getsockopt (mSocket, 119 SOL_SOCKET, 120 aOptName, 121 #ifdef _WIN32 122 (char *) aOptVal, 123 #else 124 aOptVal, 125 #endif 126 (socklen_t *) aOptLen); 127 if (aResult < 0) 128 { 129 aResult = ERROR_TCPSOCKET_FAILED_TO_GET_SOCKOPT; 130 CRX_ERROR_SET (aResult, "Failed to get socket option."); 131 } 132 /*----------------------------------------------------------------*/ 133 134 return aResult; 78 135 } 79 136 … … 84 141 { 85 142 int aResult = 0; 143 86 144 /*----------------------------------------------------------------*/ 87 145 aResult = setsockopt (mSocket, … … 162 220 #endif 163 221 164 mInitialized = true;222 gInitialized = true; 165 223 166 224 /*----------------------------------------------------------------*/ … … 183 241 /*----------------------------------------------------------------*/ 184 242 /*----------------------------------------------------------------*/ 185 return mInitialized;243 return gInitialized; 186 244 } 187 245 … … 206 264 { 207 265 int aResult = -1; 266 int aReuseAddress = 1; 208 267 209 268 /*----------------------------------------------------------------*/ … … 219 278 { 220 279 aResult = ERROR_TCPSOCKET_FAILED_TO_CREATE_SOCKET; 221 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", GetSystemErrorCode());280 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", CRX_SYSTEM_ERROR ()); 222 281 return aResult; 223 282 } … … 225 284 mSocket = aResult; 226 285 227 /*----------------------------------------------------------------*/ 286 aResult = SetOption (SO_REUSEADDR, 287 &aReuseAddress, 288 sizeof (aReuseAddress)); 289 if (aResult < 0) 290 { 291 aResult = ERROR_TCPSOCKET_FAILED_TO_SET_SOCKOPT; 292 CRX_ERROR_SET (aResult, "Failed to set socket option (reuseaddr)."); 293 } 294 /*----------------------------------------------------------------*/ 295 228 296 return aResult; 229 297 } … … 243 311 { 244 312 aResult = ERROR_TCPSOCKET_FAILED_TO_CREATE_SOCKET; 245 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", GetSystemErrorCode());313 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", CRX_SYSTEM_ERROR ()); 246 314 return aResult; 247 315 } … … 267 335 aLinger.l_linger = 0; 268 336 aResult = SetOption (SO_LINGER, 269 270 337 &aLinger, 338 sizeof (aLinger)); 271 339 if (aResult < 0) 272 340 { … … 279 347 { 280 348 aResult = ERROR_TCPSOCKET_FAILED_TO_SET_TIMEOUT; 281 CRX_ERROR_SET (aResult, "Failed to set timeout (%d).", GetSystemErrorCode());349 CRX_ERROR_SET (aResult, "Failed to set timeout (%d).", CRX_SYSTEM_ERROR ()); 282 350 return aResult; 283 351 } … … 287 355 { 288 356 aResult = ERROR_TCPSOCKET_FAILED_TO_CONNECT; 289 CRX_ERROR_SET (aResult, "Failed to connect (%d).", GetSystemErrorCode());357 CRX_ERROR_SET (aResult, "Failed to connect (%d).", CRX_SYSTEM_ERROR ()); 290 358 } 291 359 /*----------------------------------------------------------------*/ … … 301 369 int aResult = -1; 302 370 303 int aReuseAddress = 1;304 305 371 /*----------------------------------------------------------------*/ 306 372 aResult = CreateSocket (); … … 308 374 { 309 375 aResult = ERROR_TCPSOCKET_FAILED_TO_CREATE_SOCKET; 310 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", GetSystemErrorCode ()); 311 return aResult; 312 } 313 314 aResult = SetOption (SO_REUSEADDR, 315 &aReuseAddress, 316 sizeof (aReuseAddress)); 317 if (aResult < 0) 318 { 319 aResult = ERROR_TCPSOCKET_FAILED_TO_SET_SOCKOPT; 320 CRX_ERROR_SET (aResult, "Failed to set socket option (reuseaddr)."); 376 CRX_ERROR_SET (aResult, "Failed to create socket(%d).", CRX_SYSTEM_ERROR ()); 377 return aResult; 321 378 } 322 379 … … 329 386 { 330 387 aResult = ERROR_TCPSOCKET_FAILED_TO_BIND; 331 CRX_ERROR_SET (aResult, "Failed to bind(%d).", GetSystemErrorCode());388 CRX_ERROR_SET (aResult, "Failed to bind(%d).", CRX_SYSTEM_ERROR ()); 332 389 return aResult; 333 390 } … … 337 394 { 338 395 aResult = ERROR_TCPSOCKET_FAILED_TO_LISTEN; 339 CRX_ERROR_SET (aResult, "Failed to listen(%d).", GetSystemErrorCode());396 CRX_ERROR_SET (aResult, "Failed to listen(%d).", CRX_SYSTEM_ERROR ()); 340 397 return aResult; 341 398 } … … 346 403 memcpy ((void *)aAddress, (void *)&mAddress, sizeof (struct sockaddr_in)); 347 404 } 348 349 /*----------------------------------------------------------------*/ 405 /*----------------------------------------------------------------*/ 406 350 407 return aResult; 351 408 } … … 359 416 struct sockaddr_in aAddress; 360 417 socklen_t aLength = sizeof (aAddress); 361 362 418 /*----------------------------------------------------------------*/ 363 419 if (!IsReady ()) … … 368 424 { 369 425 aResult = ERROR_TCPSOCKET_FAILED_TO_ACCEPT; 370 CRX_ERROR_SET (aResult, "Failed to accept(%d).", GetSystemErrorCode());426 CRX_ERROR_SET (aResult, "Failed to accept(%d).", CRX_SYSTEM_ERROR ()); 371 427 return aResult; 372 428 } … … 380 436 if (aAddressLength != NULL) 381 437 *aAddressLength = aLength; 382 383 /*----------------------------------------------------------------*/ 438 /*----------------------------------------------------------------*/ 439 384 440 return aResult; 385 441 } … … 399 455 { 400 456 aResult = ERROR_TCPSOCKET_FAILED_TO_SEND; 401 CRX_ERROR_SET (aResult, "Failed to send(%d).", GetSystemErrorCode ()); 402 return aResult; 403 } 404 405 /*----------------------------------------------------------------*/ 457 CRX_ERROR_SET (aResult, "Failed to send(%d).", CRX_SYSTEM_ERROR ()); 458 } 459 /*----------------------------------------------------------------*/ 460 406 461 return aResult; 407 462 } … … 421 476 { 422 477 aResult = ERROR_TCPSOCKET_FAILED_TO_RECEIVE; 423 CRX_ERROR_SET (aResult, "Failed to receive(%d).", GetSystemErrorCode ()); 424 return aResult; 425 } 426 427 /*----------------------------------------------------------------*/ 428 return aResult; 429 } 478 CRX_ERROR_SET (aResult, "Failed to receive(%d).", CRX_SYSTEM_ERROR ()); 479 } 480 /*----------------------------------------------------------------*/ 481 482 return aResult; 483 }
Note:
See TracChangeset
for help on using the changeset viewer.