Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members Related Pages

# Socket.h

Go to the documentation of this file.

    00001
    00002
    00003
    00004 #ifndef SOCKET_H
    00005 #define SOCKET_H
    00006
    00007 #include <winsock.h>
    00008
    00009 namespace wkgl {
    00010
    00011 #define UINT unsigned int
    00012 #define SFLAG unsigned short
    00013
    00014 #define SERROR_NOERROR   0
    00015 #define SERROR_CONNECT  -2
    00016 #define SERROR_HOST     -3
    00017 #define SERROR_NOCREATE -4
    00018 #define SERROR_NOCLOSE  -5
    00019 #define SERROR_TYPE     -6
    00020 #define SERROR_SEND     -7
    00021 #define SERROR_RECV     -8
    00022
    00026 #define SERROR_CLOSED   -1
    00027
    00031 #define STYPE_IP        1
    00032
    00036 #define STYPE_HOSTNAME  2
    00037
    00063 class Socket
    00064 {
    00065   protected:
    00066     SOCKET  sock;
    00067     char*   addr;
    00068     UINT    port;
    00069     SFLAG   addr_type;
    00070
    00074     static char lasterror[256];
    00075
    00080     static UINT ref_count;
    00081
    00085     static BOOL winsock_init;
    00086
    00087   public:
    00091     Socket();
    00092
    00096     Socket( const char* addr, UINT port, SFLAG addr_type = STYPE_IP );
    00097
    00101     Socket( const Socket& s );
    00102
    00106     Socket( SOCKET s );
    00107
    00110     ~Socket(void);
    00111
    00115     virtual int connect();
    00116
    00120     virtual int send( const char* buf, UINT len );
    00121
    00125     virtual int recv( char* buf, UINT len );
    00126
    00130     virtual int close();
    00131
    00135     virtual int operator <<( const char* data );
    00136
    00140     virtual int operator <<( char data );
    00141
    00145     virtual int operator >>( char& c );
    00146
    00150     virtual int operator >>( char*& data );
    00151
    00155     static char* getLocalHost();
    00156
    00160     static const char* getLastError();
    00161
    00165     virtual BOOL isConnected();
    00166
    00170     static void reportError( const char* where, const char* desc,
    00171                              const char* code, BOOL winerror = TRUE );
    00172
    00173     static void initWinSock();
    00174     static void cleanup();
    00175     static void addRef();
    00176     static void releaseRef();
    00177     static UINT getRefCount();
    00178 };
    00179 }
    00180 #endif