Changeset 14 in cheroxy for trunk/src/main.cpp


Ignore:
Timestamp:
10/24/12 11:12:11 (12 years ago)
Author:
cheese
Message:

#1 add timeout to socket connection and fix test label in makefile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/main.cpp

    r6 r14  
    4242        __stream << __message;                                                                          \
    4343        string __string = __stream.str ();                                                              \
    44         sprintf (__error, "[%s][%d] %d : %s\n", __func__, __LINE__, __code, __string.c_str ());         \
     44        sprintf (__error, "[%s][%d] (%d) %s\n", __func__, __LINE__, __code, __string.c_str ());         \
    4545        cout << __error;                                                                                \
    4646    } while (0)
     
    5454int main (int argc, char* argv[])
    5555{
    56     int                 aResult = 0;
    57     const ushort        aPort   = 8080;
     56    int                     aResult = 0;
     57    const unsigned short    aPort   = 8080;
    5858
    5959    CRXSocket           aSocket;
     
    119119CRXProxyThread (void * aThreadArg)
    120120{
    121     int             aResult         = 0;
    122     int             aReceivedSize   = 0;
    123     int             aSentSize       = 0;
    124 
    125     const uint      aBufferSize     = 1024 * 64;
    126     char            aBuffer[aBufferSize] = {0x00, };
    127 
    128     CRXHttpRequest  aHttpRequest;
    129     CRXHttpResponse aHttpResponse;
    130     string          aUrl    = "";
    131     string          aHost   = "";
    132     int             aPort   = 0;
    133 
    134     CRXSocket       aWebServer;
    135     CRXSocket       aWebBrowser = ((CRXProxyThreadArgs *)aThreadArg)->mSocket;
    136 
    137     bool            aIsMoreRequest = false;
     121    int                 aResult         = 0;
     122    int                 aReceivedSize   = 0;
     123    int                 aSentSize       = 0;
     124
     125    const unsigned int  aBufferSize     = 1024 * 64;
     126    char                aBuffer[aBufferSize] = {0x00, };
     127
     128    CRXHttpRequest      aHttpRequest;
     129    CRXHttpResponse     aHttpResponse;
     130    string              aUrl    = "";
     131    string              aHost   = "";
     132    int                 aPort   = 0;
     133
     134    CRXSocket           aWebServer;
     135    CRXSocket           aWebBrowser = ((CRXProxyThreadArgs *)aThreadArg)->mSocket;
     136
     137    bool                aIsMoreRequest = false;
    138138    /*----------------------------------------------------------------*/
    139139    delete (CRXProxyThreadArgs *)aThreadArg;
     
    145145        if (aReceivedSize < 0)
    146146        {
    147             CRX_PRINT_ERROR (aReceivedSize, "failed to receive from client");
    148             aResult = CRX_ERROR ();
     147            CRX_PRINT_ERROR (aReceivedSize, "failed to receive from client (" << CRX_ERROR () << ")");
    149148            return aResult;
    150149        }
     
    157156
    158157            /* connect */
    159             aResult = aWebServer.Connect (aHttpRequest.GetHost (), aHttpRequest.GetPort ());
     158            aResult = aWebServer.Connect (aHttpRequest.GetHost (), aHttpRequest.GetPort (), 1);
    160159            if (aResult < 0)
    161160            {
    162                 CRX_PRINT_ERROR (aResult, "failed to connect to server <" << aHost << ":" << aPort << ">");
    163                 aResult = CRX_ERROR ();
     161                CRX_PRINT_ERROR (aResult, "failed to connect to server <" << aHost << ":" << aPort << "> (" << CRX_ERROR () << ")");
    164162                return aResult;
    165163            }
     
    170168        if (aSentSize != aReceivedSize)
    171169        {
    172             CRX_PRINT_ERROR (aResult, "failed to send to server");
    173             aResult = CRX_ERROR ();
     170            CRX_PRINT_ERROR (aResult, "failed to send to server (" << CRX_ERROR () << ")");
    174171            return aResult;
    175172        }
     
    183180            if (aReceivedSize < 0)
    184181            {
    185                 CRX_PRINT_ERROR (aReceivedSize, "failed to receive");
    186                 aResult = CRX_ERROR ();
     182                CRX_PRINT_ERROR (aReceivedSize, "failed to receive (" << CRX_ERROR () << ")");
    187183                break;
    188184            }
     
    196192            if (aSentSize != aReceivedSize)
    197193            {
    198                 CRX_PRINT_ERROR (aSentSize, "failed to send");
    199                 aResult = CRX_ERROR ();
     194                CRX_PRINT_ERROR (aSentSize, "failed to send (" << CRX_ERROR () << ")");
    200195                break;
    201196            }
Note: See TracChangeset for help on using the changeset viewer.