Changeset 38 in cheroxy


Ignore:
Timestamp:
11/21/12 09:23:50 (11 years ago)
Author:
cheese
Message:

#1 more mutex interface and add debugging code to check connection port number

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/CRXMutex.h

    r10 r38  
    1414{
    1515private:
    16     CRX_MUTEX mMutex;
     16    bool        mIsCreated;
     17    CRX_MUTEX   mMutex;
    1718
    1819public:
     
    2122
    2223public:
     24    bool    IsCreated   (void) const;
    2325    int     Create      (void);
    2426    int     Destroy     (void);
  • trunk/include/CRXSocket.h

    r30 r38  
    99#ifdef WIN32
    1010# include <WinSock2.h>
     11typedef int socklen_t;
    1112#else
    1213# include <netinet/in.h>
  • trunk/src/CRXMutex.cpp

    r12 r38  
    33
    44CRXMutex::CRXMutex (void)
     5    : mIsCreated (false),
     6#ifdef _WIN32
     7      mMutex (NULL)
     8#endif
    59{
    6 #ifdef _WIN32
    7     mMutex = NULL;
    8 #endif
     10    /*----------------------------------------------------------------*/
     11    /*----------------------------------------------------------------*/
    912}
    1013
    1114CRXMutex::~CRXMutex (void)
    1215{
     16    /*----------------------------------------------------------------*/
    1317    this->Unlock ();
    1418    this->Destroy ();
    15 #ifdef _WIN32
    16 #else
    17 #endif
     19    /*----------------------------------------------------------------*/
    1820}
    1921
    20 int CRXMutex::Create (void)
     22bool
     23CRXMutex::IsCreated (void) const
    2124{
     25    /*----------------------------------------------------------------*/
     26    /*----------------------------------------------------------------*/
     27
     28    return mIsCreated;
     29}
     30
     31int
     32CRXMutex::Create (void)
     33{
     34    int     aResult = 0;
     35
     36    /*----------------------------------------------------------------*/
    2237#ifdef _WIN32
    2338    if ((mMutex = ::CreateMutexA (NULL, FALSE, NULL)) == NULL)
    24         return GetLastError ();
    25     else
    26         return 0;
     39        aResult = GetLastError ();
    2740#else
    28     return pthread_mutex_init (&mMutex, NULL);
     41    aResult = pthread_mutex_init (&mMutex, NULL);
    2942#endif
     43
     44    mIsCreated = true;
     45    /*----------------------------------------------------------------*/
     46
     47    return aResult;
    3048}
    3149
    32 int CRXMutex::Destroy (void)
     50int
     51CRXMutex::Destroy (void)
    3352{
     53    int     aResult = 0;
     54
     55    /*----------------------------------------------------------------*/
    3456#ifdef _WIN32
    3557    if (::CloseHandle (mMutex))
    36         return GetLastError ();
    37     else
    38         return 0;
     58        aResult = GetLastError ();
    3959#else
    40     return pthread_mutex_destroy (&mMutex);
     60    aResult = pthread_mutex_destroy (&mMutex);
    4161#endif
     62
     63    mIsCreated = false;
     64    /*----------------------------------------------------------------*/
     65
     66    return aResult;
    4267}
    4368
    44 void CRXMutex::Lock (void)
     69void
     70CRXMutex::Lock (void)
    4571{
     72    /*----------------------------------------------------------------*/
    4673#ifdef _WIN32
    4774    ::WaitForSingleObject (mMutex, INFINITE);
     
    4976    pthread_mutex_lock (&mMutex);
    5077#endif
     78    /*----------------------------------------------------------------*/
    5179}
    5280
    53 void CRXMutex::Unlock (void)
     81void
     82CRXMutex::Unlock (void)
    5483{
     84    /*----------------------------------------------------------------*/
    5585#ifdef _WIN32
    5686    if (mMutex != NULL)
     
    5989    pthread_mutex_unlock (&mMutex);
    6090#endif
     91    /*----------------------------------------------------------------*/
    6192}
  • trunk/src/CRXProxy.cpp

    r36 r38  
    77#include <string.h>
    88
    9 CRXFilter CRXProxy::mFilter;
     9CRXFilter   CRXProxy::mFilter;
    1010
    1111CRXProxy::CRXProxy (void)
     
    2626
    2727CRXProxy *
    28 CRXProxy::GetNewInstance(void)
     28CRXProxy::GetNewInstance (void)
    2929{
    3030    /*----------------------------------------------------------------*/
     
    277277    int     aSize   = mHttpRequest.GetHeader ().length ();
    278278
     279    struct sockaddr_in  aSockName;
     280    socklen_t           aSockLen = sizeof (aSockName);
     281
    279282    /*----------------------------------------------------------------*/
    280283    if (!mServer)
     
    291294    }
    292295
     296    getsockname (mServer, (struct sockaddr *) &aSockName, &aSockLen);
     297    CRX_DEBUG_TRACE ("Connected on port number (%d)\n", ntohs (aSockName.sin_port));
     298
    293299    aResult = mServer.Send (mHttpRequest.GetHeader ().c_str (), aSize);
    294300    if (aResult != aSize)
  • trunk/src/CRXSocket.cpp

    r35 r38  
    99# pragma comment (lib, "ws2_32.lib")
    1010# define close(__socket) closesocket(__socket)
    11 typedef int socklen_t;
    1211#endif
    1312
Note: See TracChangeset for help on using the changeset viewer.