#include "RNPlatform/Inc/MemoryTracking.h"#include <assert.h>#include "RNPlatform/Inc/PlatformHeap.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 "RNPlatform/Inc/DLLExportAPI.h"#include "RNXPSockets/Ping.h"

Namespaces | |
| namespace | RNReplicaNet |
Classes | |
| class | XPSocketsHeapBlock |
| struct | ImpairedPacket |
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) |
| int | XPSock_Listen (t_XPSocket *socket, const RNReplicaNet::t_XPAddress *addr) |
| 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) |
| t_XPSocket * | XPSock_UrgentCreate (int port) |
| t_XPSocket * | XPSock_UrgentCreate (const RNReplicaNet::t_XPAddress *addr) |
| int | XPSock_UrgentMakeBroadcast (t_XPSocket *socket) |
| 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) |
| 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) |
| t_XPSocket * | XPSock_ICMPCreate (void) |
| int | XPSock_ICMPSendPing (RNReplicaNet::t_XPSocket *socket, const RNReplicaNet::t_XPAddress *addr, unsigned short *retID, unsigned short *retSeq, unsigned int *retTimeSent) |
| int | XPSock_ICMPRecvPing (RNReplicaNet::t_XPSocket *socket, RNReplicaNet::t_XPAddress *const addr, unsigned short *retID, unsigned short *retSeq, unsigned int *retTimeElapsed) |
| int | XPSock_ICMPWaitForPing (RNReplicaNet::t_XPSocket *socket, const float timeoutSeconds) |
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 |
| int | gXPSock_UDPProtoParameter = IPPROTO_UDP |
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 NO_NAGLE |
Use this to turn off the Nagle packet compression algorithm
| t_XPSocket* XPSock_Accept | ( | t_XPSocket * | socket | ) |
Tries to accept any incoming connections and creates a connected socket if successfull.
| socket | the socket pointer |
| int XPSock_Close | ( | t_XPSocket * | socket | ) |
Closes a socket
| socket | the socket pointer |
| int XPSock_Connect | ( | t_XPSocket * | socket, | |
| const t_XPAddress * | addr | |||
| ) |
Connect to a machine address
| socket | the socket pointer | |
| addr | the address to connect to. If addr is NULL then a local connect is tried |
| t_XPSocket* XPSock_Create | ( | void | ) |
Creates a socket
| int XPSock_GetAddress | ( | t_XPSocket * | socket, | |
| t_XPAddress * | addr | |||
| ) |
Fills in the internet address and port of a socket to the address structure.
| socket | the socket pointer | |
| addr | the address structure to fill in |
| int XPSock_GetHardwareStatus | ( | void | ) |
Gets the status of the network hardware used by this socket interface.
| int XPSock_GetHostAddress | ( | XPAddress * | addr | ) |
Gets the host machine address
| addr | the XPAddress to fill in |
| int XPSock_GetHostName | ( | char * | name, | |
| int | name_len | |||
| ) |
Gets the host machine name
| name | pointer to a buffer to receive the machines textual name | |
| name_len | the length of the buffer |
| int XPSock_GetPeerAddress | ( | t_XPSocket * | socket, | |
| t_XPAddress * | addr | |||
| ) |
Fills in the internet address of the peer of a socket to the address structure.
| socket | the socket pointer | |
| addr | the address structure to fill in |
| int XPSock_Init | ( | void | ) |
This inits the socket interface
| int XPSock_Listen | ( | t_XPSocket * | socket, | |
| const RNReplicaNet::t_XPAddress * | addr | |||
| ) |
Sets a socket to be a listen socket that is bound to the address supplied. This should only really be used for a server not the client as it is better network programming practise.
| socket | the socket pointer | |
| addr | the address to use. |
| 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.
| socket | the socket pointer | |
| port | the port number to listen from |
| int XPSock_Quit | ( | void | ) |
Quits all sockets and exits Calling PlatformHeap::ForceFree() will call XPSock_Quit() if XPSock_Init() was previously called.
| int XPSock_Recv | ( | t_XPSocket * | socket, | |
| char * | data, | |||
| int | maxlen, | |||
| int | flag | |||
| ) |
Tries to receive data from a socket
| socket | the socket pointer | |
| data | a char pointer to the data buffer | |
| maxlen | the maximum 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 |
| 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.
| 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
| resolve | the address structure to fill in with the result | |
| input | the textual name of a machine name to resolve |
| int XPSock_Send | ( | t_XPSocket * | socket, | |
| const char * | data, | |||
| const int | len | |||
| ) |
Tries to send data via the socket
| socket | the socket pointer | |
| data | a char pointer to the data buffer | |
| len | the length of the data to send |
| 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.
| 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
| socket | the socket pointer | |
| size | The size to set the recv buffer to or -1 to only return the value |
| int XPSock_SetSendBuffer | ( | t_XPSocket * | socket, | |
| int | size | |||
| ) |
Sets the size of the send buffer for a socket
| socket | the socket pointer | |
| size | The size to set the send buffer to or -1 to only return the value |
| char* XPSock_TranslateError | ( | int | error | ) |
This translates an XPSocket error to a text string
| error | the XPSOCK error number |
| char* XPSock_TranslateErrorLong | ( | int | error | ) |
This translates an XPSocket error to a long descriptive text string
| error | the XPSOCK error number |
| t_XPSocket* XPSock_UrgentCreate | ( | const RNReplicaNet::t_XPAddress * | addr | ) |
Creates an urgent socket that is bound to the address supplied. Returns XPSOCK_EERROR if an error occurred 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
| addr | the address to use. |
| t_XPSocket* XPSock_UrgentCreate | ( | int | port | ) |
Creates an urgent socket Returns XPSOCK_EERROR if an error occurred 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
| port | the port number to use |
| int XPSock_UrgentMakeBroadcast | ( | t_XPSocket * | socket | ) |
Makes an urgent socket broadcast capable
| socket | the socket pointer |
| int XPSock_UrgentRecv | ( | t_XPSocket * | socket, | |
| char *const | data, | |||
| int | maxlen, | |||
| int | flag, | |||
| t_XPAddress *const | addr | |||
| ) |
Receives data from an urgent socket
| 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 |
| 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
| 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 |
| int XPSock_UtilityChecksum | ( | char * | buffer, | |
| int | length | |||
| ) |
Simple function to perform a quick checksum of data
| buffer | the data buffer to checksum | |
| length | the length of the data buffer |
| 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
| buffer | pointer ot a data buffer | |
| maxlen | the length of this buffer |
| int XPSock_UtilityGetInt | ( | char * | buffer, | |
| int | offset | |||
| ) |
Extracts an int from a buffer given an offset
| buffer | the pointer to the buffer | |
| offset | the offsrt in the buffer containing the int |
| short XPSock_UtilityGetShort | ( | char * | buffer, | |
| int | offset | |||
| ) |
Extracts a short from a buffer given an offset
| buffer | the pointer to the buffer | |
| offset | the offsrt in the buffer containing the short |
| void XPSock_UtilitySetInt | ( | char * | buffer, | |
| int | offset, | |||
| int | value | |||
| ) |
Encodes an int into a buffer at a given an offset
| 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
| buffer | the pointer to the buffer | |
| offset | the offsrt in the buffer containing the short | |
| value | the value to encode in the buffer |
| 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
1.5.3