00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
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
00181 #if 0
00182
00183 extern char *XPSock_TranslateError(int );
00184 extern char *XPSock_TranslateErrorLong(int );
00185
00186 extern int XPSock_GetHostName(char * ,int );
00187 extern int XPSock_Resolve(t_XPAddress * ,char * );
00188
00189 extern int XPSock_UtilityGetFragment(char * ,int );
00190 extern int XPSock_UtilityGetInt(char * ,int );
00191 extern void XPSock_UtilitySetInt(char * ,int ,int );
00192 extern short XPSock_UtilityGetShort(char * ,int );
00193 extern void XPSock_UtilitySetShort(char * ,int ,short );
00194 #endif
00195
00196
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