XPSocketClass.h

00001 /* START_LICENSE_HEADER
00002 
00003 Copyright (C) 2000 Martin Piper, original design and program code
00004 Copyright (C) 2001 Replica Software
00005 
00006 This program file is copyright (C) Replica Software and can only be used under license.
00007 For more information visit: http://www.replicanet.com/
00008 Or email: info@replicanet.com
00009 
00010 END_LICENSE_HEADER */
00011 /* A class implementation of the C style XPSocket library */
00012 #ifndef __XPSOCKETCLASS_H__
00013 #define __XPSOCKETCLASS_H__
00014 #include "RNPlatform/Inc/DLLExportAPI.h"
00015 
00016 #include "XPSocket.h"
00017 
00018 namespace RNReplicaNet
00019 {
00020 
00028 class XPSocket
00029 {
00030 public:
00031 friend class XPSocketUrgent;
00032 //friend class XPStream;
00037     XPSocket();
00038 
00043     virtual ~XPSocket();
00044 
00049     static int GetLastError(void);
00050 
00055     virtual int Create(void);
00056 
00062     int Connect(const XPAddress &addr);
00063 
00069     int Send(const char *data);
00070 
00077     int Send(const char *data,const int len);
00078 
00085     int Recv(char *const data,const int maxlen);
00086 
00091     int Close(void);
00092 
00098     int Listen(const int port = XPSOCK_PORT_ANY);
00099 
00105     int Listen(const XPAddress &addr);
00106 
00111     XPSocket *Accept(void);
00112 
00118     int SetSendBuffer(const int size);
00119 
00125     int SetRecvBuffer(const int size);
00126 
00132     int GetAddress(XPAddress *const addr);
00133 
00139     int GetPeerAddress(XPAddress *const addr);
00140 
00145     static int GetMaxPacketSize(void)   {return XPSOCK_MAXPACKETSIZE;};
00146 
00152     int MutateSocket(XPSocket *socket);
00153 
00158     bool IsAlive(void);
00159 
00164     t_XPSocket *GetSocketPointer(void);
00165 
00166 private:
00167 
00168     t_XPSocket *mSocket;            
00170     enum SocketState
00171     {
00172         TypeUndefined = 0,
00173         TypeTCP = 1,
00174         TypeUDP = 2
00175     };                              
00177     SocketState mSocketState;       
00178 };
00179 
00180 /* To implement */
00181 #if 0
00182 
00183 extern char *XPSock_TranslateError(int /*errno*/);
00184 extern char *XPSock_TranslateErrorLong(int /*errno*/);
00185 
00186 extern int XPSock_GetHostName(char * /*name*/,int /*name_len*/);
00187 extern int XPSock_Resolve(t_XPAddress * /*resolve*/,char * /*input*/);
00188 
00189 extern int XPSock_UtilityGetFragment(char * /*buffer*/,int /*maxlen*/);
00190 extern int XPSock_UtilityGetInt(char * /*buffer*/,int /*offset*/);
00191 extern void XPSock_UtilitySetInt(char * /*buffer*/,int /*offset*/,int /*value*/);
00192 extern short XPSock_UtilityGetShort(char * /*buffer*/,int /*offset*/);
00193 extern void XPSock_UtilitySetShort(char * /*buffer*/,int /*offset*/,short /*value*/);
00194 #endif
00195 
00196 /* A macro to make our life easier */
00197 #define SOCKET_ASSERT_TYPE(x) \
00198     if (mSocketState == (x))    \
00199     {   \
00200         assert(0 && "XPSOCK_ILLEGALOPERATION"); \
00201         asocket_lasterror = XPSOCK_ILLEGALOPERATION;    \
00202         return XPSOCK_EERROR;   \
00203     }   \
00204     if ((x) == TypeUDP) \
00205     {   \
00206         mSocketState = TypeTCP; \
00207     }   \
00208     else    \
00209     {   \
00210         mSocketState = TypeUDP; \
00211     }
00212 
00213 #define SOCKET_ASSERT_TYPEP(x) \
00214     if (mSocketState == (x))    \
00215     {   \
00216         assert(0 && "XPSOCK_ILLEGALOPERATION"); \
00217         asocket_lasterror = XPSOCK_ILLEGALOPERATION;    \
00218         return pcXPSOCK_EERROR; \
00219     }   \
00220     if ((x) == TypeUDP) \
00221     {   \
00222         mSocketState = TypeTCP; \
00223     }   \
00224     else    \
00225     {   \
00226         mSocketState = TypeUDP; \
00227     }
00228 
00229 #define pcXPSOCK_EERROR  ((RNReplicaNet::XPSocket *) XPSOCK_EERROR) 
00231 } // namespace RNXPSockets
00232 
00233 #endif

Generated on Sat Jun 28 22:02:16 2008 for ReplicaNet and RNLobby by  doxygen 1.5.3