sprint 1-alpha
sprint/io/network/async_socket.h
00001 #ifndef _ASYNC_SOCKET_H
00002 #define _ASYNC_SOCKET_H
00003 
00004 namespace sprint {
00005 
00006 #ifdef WIN32
00007 
00008 template<class T>
00009 class async_socket: public T {
00010         HANDLE hEvent;
00011         //char *in_buffer;
00012 public:
00013         inline DWORD Wait(UINT uTimeOut)        {
00014                 return ::WaitForSingleObject(hEvent, uTimeOut);
00015         }
00016         /*ATTENZIONE: EnumNetworkEvents resetta l'handle degli eventi */
00017         inline int EnumNetworkEvents(LPWSANETWORKEVENTS lpNetworkEvents)
00018         {
00019                 return ::WSAEnumNetworkEvents(this->s, hEvent, lpNetworkEvents);
00020         }
00021 
00022         /* PeekNetworkEvents non resetta */
00023         inline int PeekNetworkEvents(LPWSANETWORKEVENTS lpNetworkEvents)
00024         {
00025                 return ::WSAEnumNetworkEvents(this->s, NULL, lpNetworkEvents);
00026         }
00027 
00028         inline HANDLE GetHandle()       { return hEvent;}
00029 
00030         inline int SetWaitForNothing()  {
00031                 return ::WSAEventSelect(this->s, hEvent, 0);
00032         }
00033 
00034         inline int SetWaitForRead()     {
00035                 return ::WSAEventSelect(this->s, hEvent, FD_READ | FD_CLOSE);
00036         }
00037         inline int SetWaitForAccept()   {
00038                 return ::WSAEventSelect(this->s, hEvent, FD_ACCEPT);
00039         }
00040 
00041         inline int SetWaitForWrite()    {
00042                 return ::WSAEventSelect(this->s, hEvent, FD_WRITE);
00043         }
00044 
00045         inline BOOL SetEvent()  {
00046                 return ::WSASetEvent(hEvent);
00047         };
00048 
00049         inline BOOL ResetEvent()        {
00050                 return ::WSAResetEvent(hEvent);
00051         };
00052         
00053 };
00054 #endif
00055 
00056 }
00057 
00058 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines