ReplicaNet and RNLobby  1
Public Member Functions | Static Public Member Functions | Friends | List of all members
XPSocket Class Reference

#include <XPSocketClass.h>

Inheritance diagram for XPSocket:
Inheritance graph
[legend]

Public Member Functions

 XPSocket ()
 
virtual ~XPSocket ()
 
virtual int Create (void)
 
int Connect (const XPAddress &addr)
 
int Send (const char *data)
 
int Send (const char *data, const int len)
 
int Recv (char *const data, const int maxlen)
 
int Close (void)
 
int Listen (const int port=XPSOCK_PORT_ANY)
 
int Listen (const XPAddress &addr)
 
XPSocketAccept (void)
 
int SetSendBuffer (const int size)
 
int SetRecvBuffer (const int size)
 
int GetAddress (XPAddress *const addr)
 
int GetPeerAddress (XPAddress *const addr)
 
int MutateSocket (XPSocket *socket)
 
bool IsAlive (void)
 
t_XPSocketGetSocketPointer (void)
 

Static Public Member Functions

static int GetLastError (void)
 
static int GetMaxPacketSize (void)
 

Friends

class XPSocketUrgent
 

Detailed Description

This class is a socket which is a potential connection or actual connection to a machine. This uses the underlying XPSocket library which in turn uses the winsock or berkley sockets API. Most member functions return an XPSOCK_EERROR code. XPSOCK_EOK indicates no error. XPSOCK_EWOULDBLOCK is a non-fatal error and means the socket operation would have blocked the current thread at this point. If XPSOCK_EERROR is returned the user should use XPSocket::GetLastError() to find out the actual error code

Constructor & Destructor Documentation

XPSocket ( )

The ctor for an XPSocket This checks to make sure sockets are active and sets some initial states. At this point no connection is made for the socket

References XPSock_Init().

Referenced by XPSocket::Accept().

~XPSocket ( )
virtual

The dtor for an XPSocket This cleans up everything for this socket

References XPSocket::Close().

Member Function Documentation

XPSocket * Accept ( void  )

Accepts any pending connections for this socket. This should be used with the Listen() member function

Returns
returns NULL if no connection was pending or returns the pointer to the new connected XPSocket or pcXPSOCK_EERROR if an error occurred

References XPSock_Accept(), and XPSocket::XPSocket().

int Close ( void  )

Closes the socket but does not delete the memory for the XPSocket class

Returns
returns an XPSOCK_EERROR code.

References XPSock_Close().

Referenced by XPSocket::~XPSocket().

int Connect ( const XPAddress addr)

Tries to connect this socket to a network address

Parameters
addrthe address to try to connect to
Returns
returns an XPSOCK_EERROR code.

References XPSock_Connect().

int Create ( void  )
virtual

Creates a TCP style socket. This is the first stage to creating a connection

Returns
returns an XPSOCK_EERROR code.

References XPSock_Create().

int GetAddress ( XPAddress *const  addr)

Fills in the internet address and port of the socket to the address structure.

Parameters
addrthe address structure to fill in
Returns
returns XPSOCK_EOK or an XPSOCK_EERROR error code.

References XPSock_GetAddress().

int GetLastError ( void  )
static

Gets the last error reported by the XPSocket API

Returns
returns an XPSOCK_EERROR code.

References asocket_lasterror.

static int GetMaxPacketSize ( void  )
inlinestatic

Returns the maximum size for a packet

Returns
the maximum size for a data packet for this socket
int GetPeerAddress ( XPAddress *const  addr)

Fills in the internet address of the peer of the socket to the address structure.

Parameters
addrthe address structure to fill in
Returns
returns XPSOCK_EOK or an XPSOCK_EERROR error code.

References XPSock_GetPeerAddress().

t_XPSocket * GetSocketPointer ( void  )

Access for the t_XPSocket pointer

Returns
The t_XPSocket pointer associated with this class
bool IsAlive ( void  )

Tests the alive state of the socket

Returns
returns true if the socket is alive or false if the socket is dead
int Listen ( const int  port = XPSOCK_PORT_ANY)

Makes the socket listen on a certain port number

Parameters
portthe port number to listen on for incoming connections
Returns
returns an XPSOCK_EERROR code.

References XPSock_Listen().

int Listen ( const XPAddress addr)

Makes the socket listen on a certain address

Parameters
addrthe address to listen on for incoming connections
Returns
returns an XPSOCK_EERROR code.

References XPSock_Listen().

int MutateSocket ( XPSocket socket)

Mutates this socket class to use a socket

Parameters
socketthe socket to mutate to
Returns
returns XPSOCK_EOK or an XPSOCK_EERROR error code.

References XPSock_Close().

int Recv ( char *const  data,
const int  maxlen 
)

Tries to receive data that is waiting for this socket

Parameters
datathe pointer to the buffer to receive the data
maxlenthe maximum length of the data buffer
Returns
returns the length of the data received or 0 for no data pending or an XPSOCK_EERROR code.

References XPSock_Recv().

int Send ( const char *  data)

Sends a NULL terminated string to the peer (the connected machine) for this socket

Parameters
dataThe pointer to the NULL terminated string
Returns
returns an XPSOCK_EERROR code.

References XPSock_Send().

int Send ( const char *  data,
const int  len 
)

Sends data to the peer (the connected machine) for this socket

Parameters
datathe pointer to the data to send
lenthe length of the data to send
Returns
returns an XPSOCK_EERROR code.

References XPSock_Send().

int SetRecvBuffer ( const int  size)

Sets the size of the recv buffer for the socket

Parameters
sizeThe size to set the recv buffer to or -1 to only return the value
Returns
the new size of the recv buffer

References XPSock_SetRecvBuffer().

int SetSendBuffer ( const int  size)

Sets the size of the send buffer for the socket

Parameters
sizeThe size to set the send buffer to or -1 to only return the value
Returns
the new size of the send buffer

References XPSock_SetSendBuffer().