41 #ifndef _networksocket_cpp
42 #define _networksocket_cpp
44 #include "Network/platformsocket.h.cpp"
46 #include "Network/socket.h"
61 #if defined(MEZZ_WINDOWS)
94 #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
95 const Integer SE_Uninitialized = -1;
96 const Integer SE_NetworkNotReady = -1;
97 const Integer SE_Interrupted = EINTR;
98 const Integer SE_AccessDenied = EACCES;
99 const Integer SE_InvalidAddr = EFAULT;
100 const Integer SE_InvalidParam = EINVAL;
101 const Integer SE_IOLimit = EMFILE;
102 const Integer SE_WouldBlock = EWOULDBLOCK;
103 const Integer SE_NowInProgress = EINPROGRESS;
104 const Integer SE_AlreadyInProgress = EALREADY;
105 const Integer SE_DestAddrReq = EDESTADDRREQ;
106 const Integer SE_MessageSize = EMSGSIZE;
107 const Integer SE_ProtoNotSupported = EPROTONOSUPPORT;
108 const Integer SE_SocketNotSupported = ESOCKTNOSUPPORT;
109 const Integer SE_PFNotSupported = EPFNOSUPPORT;
110 const Integer SE_AFNotSupported = EAFNOSUPPORT;
111 const Integer SE_AddrInUse = EADDRINUSE;
112 const Integer SE_AddrNotAvail = EADDRNOTAVAIL;
113 const Integer SE_NetworkDown = ENETDOWN;
114 const Integer SE_NetworkUnreachable = ENETUNREACH;
115 const Integer SE_ConnectionDropped = ENETRESET;
116 const Integer SE_ConnectionAborted = ECONNABORTED;
117 const Integer SE_ConnectionReset = ECONNRESET;
118 const Integer SE_NoBufferSpace = ENOBUFS;
119 const Integer SE_AlreadyConnected = EISCONN;
120 const Integer SE_NotConnected = ENOTCONN;
121 const Integer SE_SocketShutdown = ESHUTDOWN;
122 const Integer SE_ConnectionTimeout = ETIMEDOUT;
123 const Integer SE_ConnectionRefused = ECONNREFUSED;
124 const Integer SE_HostIsDown = EHOSTDOWN;
125 const Integer SE_HostUnreachable = EHOSTUNREACH;
132 #if defined(MEZZ_WINDOWS)
137 #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
138 const Integer SE_NonSocket = ENOTSOCK;
139 const Integer SE_InvalidProtoType = EPROTOTYPE;
140 const Integer SE_InvalidProtoOpt = ENOPROTOOPT;
141 const Integer SE_InvalidOperation = EOPNOTSUPP;
198 int Value = ( Reuse ? 1 : 0 );
207 return ( Value != 0 );
212 int Value = ( Route ? 1 : 0 );
221 return ( Value != 0 );
226 int Value = ( Debug ? 1 : 0 );
235 return ( Value != 0 );
240 #if defined(MEZZ_WINDOWS)
241 DWORD Value = ( Size < 0 ? 0 : Size );
243 #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
250 #if defined(MEZZ_WINDOWS)
252 #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
257 return static_cast<Integer>(Value);
262 #if defined(MEZZ_WINDOWS)
263 DWORD Value = ( Size < 0 ? 0 : Size );
265 #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
272 #if defined(MEZZ_WINDOWS)
274 #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
279 return static_cast<Integer>(Value);
299 #if defined(MEZZ_WINDOWS)
300 WORD Version = MAKEWORD(2,2);
302 return ::WSAStartup(Version,&StartupData);
303 #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
310 #if defined(MEZZ_WINDOWS)
311 return ::WSACleanup();
312 #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
const Integer SE_InvalidProtoType
The specified protocol is of the wrong type for the socket type specified. This error occurs on socke...
const Integer SE_NotConnected
The socket is not connected. Operations requiring a connection cannot be performed.
const Integer SE_AFNotSupported
The system does not have the specified address family installed or configured. This is mostly interch...
PlatformSocket * InternalSocket
A pointer to the internal system socket.
const Integer SE_Interrupted
The thread or process running a socket operation was terminated prematurely.
const Integer SE_DestAddrReq
Specifying a destination address is required for the erroring operation. This often applies to a sock...
Boole IsInvalid() const
Gets whether or not this socket is invalid, indicating an error during creation.
bool Boole
Generally acts a single bit, true or false.
Integer Receive(void *Buffer, const UInt32 BufSize) const
Reads raw data recieved on this socket from it's configured peer.
const Integer SE_AlreadyConnected
The socket is already connected. Additional connections are not supported.
static Integer GetLastError()
Gets the last error that occured on a socket.
const Integer SE_Unknown
An unknown error occured. This is for when our errors error.
virtual ~Socket()
Class destructor.
const Integer SE_ConnectionDropped
The connection was dropped. Usually occurs after keep-alive detected a failure while an operation was...
int Integer
A datatype used to represent any integer close to.
Integer GetSendBufferSize() const
Gets the size of the buffer for sending packets.
static Integer Deinitialize()
Stops the socket subsystem.
Boole GetDebugInformation() const
Gets whether or not additional debugging information should be collected during socket operations...
const Integer SE_ConnectionTimeout
The connection timed out. The connect failed because the remote host didn't respond within the timeou...
const Integer SE_Uninitialized
The OS modules for networking haven't been started.
const Integer SE_InvalidParam
An argument/parameter was provided to a socket operation.
void SetReuseAddress(const Boole Reuse)
Sets whether or not local addresses can be re-used for socket binding.
Boole GetReuseAddress() const
Gets whether or not local addresses can be re-used for socket binding.
const Integer SE_NetworkDown
The operation encountered a dead network. This could be because of a failure of the network system...
const Integer SE_HostUnreachable
No route to the specified host could be found.
const Integer SE_ProtoNotSupported
The system does not have the specified protocol installed or configured.
static Integer Initialize()
Starts the socket subsystem.
Socket()
Class constructor.
const Integer SE_MessageSize
The message to be sent through a socket is too large. The buffer provided to be sent on a datagram so...
uint16_t UInt16
An 16-bit unsigned integer.
const Integer SE_NowInProgress
The socket is non-blocking and the operation cannot be completed immediately, but is now in progress...
const Integer SE_NoBufferSpace
Either the OS lacked sufficient buffer space or the queue was full.
Integer GetNumBytesAvailable() const
Gets the number of bytes currently available to be read from the receive buffer.
static void ThrowLastError()
Throws an exception containing the message from the last socket error.
const Integer SE_NetworkNotReady
The OS modules needed for networking are unavailable.
Boole Shutdown(const Network::SocketShutdown How)
Disables some or all I/O on the socket.
uint32_t UInt32
An 32-bit unsigned integer.
Integer Send(const void *Buffer, const UInt32 BufSize) const
Sends raw data out the socket to it's configured peer.
const Integer SE_WouldBlock
A resource is temporarily unavailable. This can be returned from operations on non-blocking sockets t...
const Integer SE_InvalidOperation
The operation requested is not supported for the socket provided. For example "accept" being called o...
const Integer SE_SocketNotSupported
Either the specified socket type does not exist or support for the specified socket type with the spe...
const Integer SE_InvalidProtoOpt
An invalid option level was specified for a call setting or getting a socket option.
void SetReceiveBufferSize(const Integer Size)
Sets the size of the buffer for receiving packets.
const Integer SE_ConnectionRefused
The connection was refused. The remote host doesn't like you. Probably because you smell funny...
Integer ReceivePeek(void *Buffer, const UInt32 BufSize) const
Reads raw data recieved on this socket from it's configured peer, but doesn't remove that data from t...
const Integer SE_NonSocket
Attempting to perform a socket operation on a handle that does not belong to a valid socket...
const Integer SE_AddrNotAvail
The address specified is not valid in the current context.
const Integer SE_NetworkUnreachable
The operation could not find a valid route to the remote host specified.
void SetDontRoute(const Boole Route)
Sets whether or not packets should be sent directly to other nodes on the network if possible...
const Integer SE_InvalidAddr
The address data provided was faulty or invalid.
const Integer SE_IOLimit
Too many IO handles (Files and sockets share a pool) are open. This may be a global, process, or thread limit depending on platform.
const Integer SE_AddrInUse
The address specified for binding is already in use by another socket.
Boole SetBlocking(const Boole Block)
Sets whether or not this socket will sleep on I/O calls.
Boole GetDontRoute() const
Gets whether or not packets should be sent directly to other nodes on the network if possible...
const Integer SE_AlreadyInProgress
The socket is non-blocking and an operation is already in progress.
const Integer SE_AccessDenied
Insufficient access permissions to perform specified socket operation.
const Integer SE_HostIsDown
The operation failed because the remote host is down or doesn't exist.
The bulk of the engine components go in this namspace.
const Integer SE_ConnectionReset
The connection was reset/closed by the remote host. This can also occur if keep-alive detected a fail...
Boole GetBlocking() const
Gets whether or not this socket will sleep on I/O calls.
static void ThrowError(const Integer ErrorCode)
Throws an exception containing the message for a specific error code.
void SetDebugInformation(const Boole Debug)
Sets whether or not additional debugging information should be collected during socket operations...
void SetSendBufferSize(const Integer Size)
Sets the size of the buffer for sending packets.
SocketShutdown
This is a small enum used for socket shutdown parameters.
Integer GetReceiveBufferSize() const
Gets the size of the buffer for receiving packets.
const Integer SE_SocketShutdown
The socket has already been shut down and operations cannot be performed on it.
PlatformSocket * _GetPlatformSocket() const
Gets a pointer to the internal socket.
const Integer SE_ConnectionAborted
The connection was aborted by software on the local host.
Boole Bind(const UInt16 Port)
Binds this socket only to a port, accepting transmissions from any interface.
A simple class that stores a complete set of information for establishing connections.
Boole Connect(const SystemAddress &Address)
Connects this socket to a remote host connected to the network.
const Integer SE_PFNotSupported
The system does not have the specified protocol family installed or configured. This is mostly interc...