Changeset 59 in cheroxy


Ignore:
Timestamp:
12/26/12 11:00:40 (11 years ago)
Author:
cheese
Message:

#1 add SetOption in CRXSocket

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/CRXSocket.h

    r57 r59  
    8787    CRXSocket   & operator =    (int aSocket);
    8888
     89    int         SetOption       (const int      aOptName,
     90                                 const void     * aOptVal,
     91                                 const size_t   aOptLen);
     92
    8993    int         SetTimeout      (const int aTimeout);
    9094
  • trunk/src/CRXSocket.cpp

    r58 r59  
    7676    /*----------------------------------------------------------------*/
    7777    return *this;
     78}
     79
     80int
     81CRXSocket::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;
    78104}
    79105
     
    98124        return 0;
    99125
    100     aResult = setsockopt (mSocket,
    101                           SOL_SOCKET,
    102                           SO_RCVTIMEO,
     126    aResult = SetOption (SO_RCVTIMEO,
    103127#ifdef _WIN32
    104                           (char *) &aTimeMilliSec,
    105                           sizeof (aTimeMilliSec));
     128                         &aTimeMilliSec,
     129                         sizeof (aTimeMilliSec));
    106130#else
    107                           &aTimeVal,
    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.");
    114138    }
    115139    /*----------------------------------------------------------------*/
     
    242266    aLinger.l_onoff = 1;
    243267    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,
    250269                          &aLinger,
    251 #endif
    252                           (socklen_t) sizeof (aLinger));
     270                          sizeof (aLinger));
    253271    if (aResult < 0)
    254272    {
     
    271289        CRX_ERROR_SET (aResult, "Failed to connect (%d).", GetSystemErrorCode ());
    272290    }
    273 
    274     /*----------------------------------------------------------------*/
     291    /*----------------------------------------------------------------*/
     292
    275293    return aResult;
    276294}
     
    294312    }
    295313
    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));
    305317    if (aResult < 0)
    306318    {
Note: See TracChangeset for help on using the changeset viewer.