Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

XPSocket.cpp File Reference

#include "RNPlatform/Inc/MemoryTracking.h"
#include <assert.h>
#include <stdio.h>
#include "debug.h"
#include "RNXPSockets/Inc/XPSocket.h"
#include "RNPlatform/Inc/ThreadClass.h"
#include "RNPlatform/Inc/SysTime.h"
#include <list>

Include dependency graph for XPSocket.cpp:


Defines

#define RNmax(a, b)   (((a) > (b)) ? (a) : (b))
#define RNmin(a, b)   (((a) < (b)) ? (a) : (b))
#define closesocket   close
#define ioctlsocket   ioctl
#define SOCKET   int
#define INVALID_SOCKET   -1
#define SOCKET_ERROR   -1
#define WSAEWOULDBLOCK   EWOULDBLOCK
#define WSAECONNRESET   ECONNRESET
#define WSAENOTCONN   ENOTCONN
#define NO_NAGLE

Functions

int WSAGetLastError (void)
void XPSock_Poll (void)
int XPSock_Init (void)
int XPSock_Quit (void)
t_XPSocket * XPSock_Create (void)
int XPSock_SetSendBuffer (t_XPSocket *socket, int size)
int XPSock_SetRecvBuffer (t_XPSocket *socket, int size)
int XPSock_Connect (t_XPSocket *socket, const t_XPAddress *addr)
int XPSock_Send (t_XPSocket *socket, const char *data, const int len)
int XPSock_Recv (t_XPSocket *socket, char *data, int maxlen, int flag)
int XPSock_Close (t_XPSocket *socket)
int XPSock_Listen (t_XPSocket *socket, int port)
t_XPSocket * XPSock_Accept (t_XPSocket *socket)
int XPSock_GetAddress (t_XPSocket *socket, t_XPAddress *addr)
int XPSock_GetPeerAddress (t_XPSocket *socket, t_XPAddress *addr)
int XPSock_UrgentSetRawMode (t_XPSocket *socket, bool RawMode)
t_XPSocket * XPSock_UrgentCreate (int port)
int XPSock_UrgentMakeBroadcast (t_XPSocket *socket)
int XPSock_ProcessACKS (void)
int XPSock_UrgentSendWithACK (t_XPSocket *socket, const char *data, int len, const t_XPAddress *addr)
int XPSock_UrgentSend (t_XPSocket *socket, const char *data, int len, const t_XPAddress *addr)
int XPSock_UrgentRecv (t_XPSocket *socket, char *const data, int maxlen, int flag, t_XPAddress *const addr)
int XPSock_UrgentListen (t_XPSocket *socket)
char * XPSock_TranslateError (int error)
char * XPSock_TranslateErrorLong (int error)
int XPSock_GetHostName (char *name, int name_len)
int XPSock_GetHostAddress (XPAddress *addr)
int XPSock_Resolve (t_XPAddress *resolve, const char *input)
int XPSock_UtilityGetFragment (char *buffer, int maxlen)
int XPSock_UtilityGetInt (char *buffer, int offset)
void XPSock_UtilitySetInt (char *buffer, int offset, int value)
short XPSock_UtilityGetShort (char *buffer, int offset)
void XPSock_UtilitySetShort (char *buffer, int offset, short value)
int XPSock_UtilityChecksum (char *buffer, int length)
void XPSock_SentHistogram (unsigned int *classes, int numClasses)
void XPSock_RecvHistogram (unsigned int *classes, int numClasses)
int XPSock_GetHardwareStatus (void)

Variables

int asocket_lasterror = XPSOCK_EOK
int asocket_packets_got = 0
int asocket_packets_sent = 0
int asocket_packets_got_size = 0
int asocket_packets_sent_size = 0
MutexClass g_xpsockets_lockclass
bool gXPSock_PacketLossEmulation = false
float gXPSock_PacketLossEmulationPercent = 0.0f
bool gXPSock_PacketLatencyEmulation = false
float gXPSock_PacketLatencyEmulationBase = 0.0f
float gXPSock_PacketLatencyEmulationJitter = 0.0f

Detailed Description

Simple local host packet stuff A lot like standard sockets, but made simpler with all the error handling done internally

Handles all these protocols transparently:

Localhost sockets. TCPIP using streamed and UDP connections.

Sockets with a permanent connection and also connectionless sockets are implemented. Every urgent socket call can be thought of as mapping to equivilent UDP packet protocols.


Define Documentation

#define NO_NAGLE
 

Use this to turn off the Nagle packet compression algorithm


Function Documentation

t_XPSocket* XPSock_Accept t_XPSocket *  socket  ) 
 

Tries to accept any incoming connections and creates a connected socket if successfull.

Parameters:
socket the socket pointer
Returns:
returns the new socket conenction that got accepted or an XPSOCK error code or null for no socket

int XPSock_Close t_XPSocket *  socket  ) 
 

Closes a socket

Parameters:
socket the socket pointer
Returns:
returns an XPSOCK error code, XPSOCK_EOK is no error.

int XPSock_Connect t_XPSocket *  socket,
const t_XPAddress addr
 

Connect to a machine address

Parameters:
socket the socket pointer
addr the address to connect to. If addr is NULL then a local connect is tried
Returns:
returns an XPSOCK error code, XPSOCK_EOK is no error.

t_XPSocket* XPSock_Create void   ) 
 

Creates a socket

Returns:
returns the socket pointer or XPSOCK_EERROR if an error occured

int XPSock_GetAddress t_XPSocket *  socket,
t_XPAddress addr
 

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

Parameters:
socket the socket pointer
addr the address structure to fill in
Returns:
returns XPSOCK_EOK or an XPSOCK error code.

int XPSock_GetHardwareStatus void   ) 
 

Gets the status of the network hardware used by this socket interface.

Returns:

int XPSock_GetHostAddress XPAddress addr  ) 
 

Gets the host machine address

Parameters:
addr the XPAddress to fill in
Returns:
returns an XPSOCK error code.

int XPSock_GetHostName char *  name,
int  name_len
 

Gets the host machine name

Parameters:
name pointer to a buffer to receive the machines textual name
name_len the length of the buffer
Returns:
returns an XPSOCK error code.

int XPSock_GetPeerAddress t_XPSocket *  socket,
t_XPAddress addr
 

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

Parameters:
socket the socket pointer
addr the address structure to fill in
Returns:
returns XPSOCK_EOK or an XPSOCK error code.

int XPSock_Init void   ) 
 

This inits the socket interface

int XPSock_Listen t_XPSocket *  socket,
int  port
 

Sets a socket to be a listen socket for a certain port number. This should only really be used for a server not the client as it is better network programming practise.

Parameters:
socket the socket pointer
port the port number to listen from
Returns:
returns an XPSOCK error code, XPSOCK_EOK is no error.

int XPSock_ProcessACKS void   ) 
 

Propcesses the socket ACK queue. Returns the number of pending ACKs left to be received for outbound data. This should be called once a frame if urgent sockets with ACKs are used

Returns:
returns the number of pending socket ACKs.

int XPSock_Quit void   ) 
 

Quits all sockets and exits

int XPSock_Recv t_XPSocket *  socket,
char *  data,
int  maxlen,
int  flag
 

Tries to receive data from a socket

Parameters:
socket the socket pointer
data a char pointer to the data buffer
maxlen the meximum length of the data buffer to receive to
flag the flag to use for this operation. Removes the read message from the queue unless XPSOCKF_PEEK is used
Returns:
returns the number of bytes read or 0 if no data is pending or an XPSOCK_EERROR error code.

void XPSock_RecvHistogram unsigned int *  classes,
int  numClasses
 

Supplies a histogram table and the size of the table for sent packets. Each class entry corresponds to a size of packet.

Parameters:
classes The pointer to the array of classes.
numClasses The number of classes in the array.

int XPSock_Resolve t_XPAddress resolve,
const char *  input
 

Handy routine to resolve anything into an address

Parameters:
resolve the address structure to fill in with the result
input the textual name of a machine name to resolve
Returns:
returns an XPSOCK error code.

int XPSock_Send t_XPSocket *  socket,
const char *  data,
const int  len
 

Tries to send data via the socket

Parameters:
socket the socket pointer
data a char pointer to the data buffer
len the length of the data to send
Returns:
returns The number of bytes sent or an SOCKET_ERROR error code, XPSOCK_EOK is no error.

void XPSock_SentHistogram unsigned int *  classes,
int  numClasses
 

Supplies a histogram table and the size of the table for sent packets. Each class entry corresponds to a size of packet.

Parameters:
classes The pointer to the array of classes.
numClasses The number of classes in the array.

int XPSock_SetRecvBuffer t_XPSocket *  socket,
int  size
 

Sets the size of the recv buffer for a socket

Parameters:
socket the socket pointer
size The size to set the recv buffer to or -1 to only return the value
Returns:
the new size of the recv buffer

int XPSock_SetSendBuffer t_XPSocket *  socket,
int  size
 

Sets the size of the send buffer for a socket

Parameters:
socket the socket pointer
size The size to set the send buffer to or -1 to only return the value
Returns:
the new size of the send buffer

char* XPSock_TranslateError int  error  ) 
 

This translates an XP socket error to a text string

Parameters:
error the XPSOCK error number
Returns:
returns a pointer to an XPSOCK error string.

char* XPSock_TranslateErrorLong int  error  ) 
 

This translates an XP socket error to a long descriptive text string

Parameters:
error the XPSOCK error number
Returns:
returns a pointer to an XPSOCK long error string.

t_XPSocket* XPSock_UrgentCreate int  port  ) 
 

Creates an urgent socket Returns XPSOCK_EERROR if an error occured If port is zero (0) then the network layer will pick a port number to be bound to Using a value of zero for the port when operating a client is advised since the any chosen port might already be in use

Parameters:
port the port number to use
Returns:
returns a pointer to new socket or an XPSOCK error code.

int XPSock_UrgentListen t_XPSocket *  socket  ) 
 

Marks the urgent socket as being a server socket rather than a client socket Useless under Winsock but may be usefull for future implementation

Parameters:
socket the socket pointer
Returns:
returns an XPSOCK error code.

int XPSock_UrgentMakeBroadcast t_XPSocket *  socket  ) 
 

Makes an urgent socket broadcast capable

Parameters:
socket the socket pointer
Returns:
returns an XPSOCK error code.

int XPSock_UrgentRecv t_XPSocket *  socket,
char *const   data,
int  maxlen,
int  flag,
t_XPAddress *const   addr
 

Receives data from an urgent socket

Parameters:
socket the socket pointer
data pointer to a data buffer
maximum length of the data buffer
flag the flag to use for this operation. Removes the read message from the queue unless XPSOCK_FPEEK is used
addr the address of the sending socket for any data received
Returns:
returns thje length of the data received or 0 if no data is pending or an XPSOCK_EERROR error code

int XPSock_UrgentSend t_XPSocket *  socket,
const char *  data,
int  len,
const t_XPAddress addr
 

Send an urgent packet from the socket to the specified address. This will return XPSOCK_EUDPSENDFAILED if this method doesn't exist. If so use a non-urgent socket

Parameters:
socket the socket pointer
data the pointer to the data to send
len the length of the data to send
the addres and port number to send to
Returns:
returns an XPSOCK error code.

int XPSock_UrgentSendWithACK t_XPSocket *  socket,
const char *  data,
int  len,
const t_XPAddress addr
 

Sends data via the urgent socket to the supplied address and requests that the data is ACK'd and gaurenteed to be received This will return XPSOCK_EUDPSENDFAILED if this method doesn't exist. If so use a non-urgent socket

Parameters:
socket the socket pointer
data the pointer to the data to send
len the length of the data to send
the address and port number to send to
Returns:
returns an XPSOCK error code.

int XPSock_UrgentSetRawMode t_XPSocket *  socket,
bool  RawMode
 

Sets the raw mode for urgent sockets to be true or false. If true then the ACK layer will not add sequence data.

Parameters:
socket the socket pointer
RawMode the bool status of the raw mode send to set

int XPSock_UtilityChecksum char *  buffer,
int  length
 

Simple function to perform a quick checksum of data

Parameters:
buffer the data buffer to checksum
length the length of the data buffer
Returns:
the checksum for this data

int XPSock_UtilityGetFragment char *  buffer,
int  maxlen
 

A handy function that gets the length of the next data fragment Nice for buffers that start with two bytes that describe the length of the packet

Parameters:
buffer pointer ot a data buffer
maxlen the length of this buffer
Returns:
returns the fragment size or an XPSOCK error code if the buffer is too small

int XPSock_UtilityGetInt char *  buffer,
int  offset
 

Extracts an int from a buffer given an offset

Parameters:
buffer the pointer to the buffer
offset the offsrt in the buffer containing the int
Returns:
returns an int

short XPSock_UtilityGetShort char *  buffer,
int  offset
 

Extracts a short from a buffer given an offset

Parameters:
buffer the pointer to the buffer
offset the offsrt in the buffer containing the short
Returns:
returns a short

void XPSock_UtilitySetInt char *  buffer,
int  offset,
int  value
 

Encodes an int into a buffer at a given an offset

Parameters:
buffer the pointer to the buffer
offset the offsrt in the buffer containing the int
value the value to encode in the buffer

void XPSock_UtilitySetShort char *  buffer,
int  offset,
short  value
 

Encodes a short into a buffer at a given an offset

Parameters:
buffer the pointer to the buffer
offset the offsrt in the buffer containing the short
value the value to encode in the buffer


Variable Documentation

int asocket_lasterror = XPSOCK_EOK
 

asocket_lasterror This contains the last error value returned from any of the socket functions

int asocket_packets_got = 0
 

Total number of packets received

int asocket_packets_got_size = 0
 

Total byte size of packets received

int asocket_packets_sent = 0
 

Total number of packets sent

int asocket_packets_sent_size = 0
 

Total byte size of packets sent


Generated on Sun Oct 30 01:12:22 2005 for XPSockets by  doxygen 1.4.1