Spinning Topp Logo BlackTopp Studios
inc
platformsocket.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 
41 #ifndef _networkplatformsocket_cpp
42 #define _networkplatformsocket_cpp
43 
44 #include "Network/platformsocket.h.cpp"
45 
46 #include "stringtool.h"
47 #include "exception.h"
48 
49 namespace Mezzanine
50 {
51  namespace Network
52  {
53  ///////////////////////////////////////////////////////////////////////////////
54  // Utility Methods
55 
57  {
58  switch( Protocol )
59  {
60  case Network::NLP_IPv4: return AF_INET;
61  case Network::NLP_IPv6: return AF_INET6;
62  default: return AF_UNSPEC;
63  }
64  }
65 
66  NetworkLayerProtocol ConvertLayer3ProtocolType(const short int Protocol)
67  {
68  switch( Protocol )
69  {
70  case AF_INET: return Network::NLP_IPv4;
71  case AF_INET6: return Network::NLP_IPv6;
72  default: return Network::NLP_Invalid;
73  }
74  }
75 
77  {
78  switch( Protocol )
79  {
80  case Network::TLP_TCP: return getprotobyname("tcp")->p_proto;
81  case Network::TLP_UDP: return getprotobyname("udp")->p_proto;
82  default: return 0;
83  }
84  }
85 
87  {
88  switch( Protocol )
89  {
90  case IPPROTO_TCP: return Network::TLP_TCP;
91  case IPPROTO_UDP: return Network::TLP_UDP;
92  default: return Network::TLP_Invalid;
93  }
94  }
95 
97  {
98  switch( Protocol )
99  {
100  case Network::TLP_TCP: return SOCK_STREAM;
101  case Network::TLP_UDP: return SOCK_DGRAM;
102  default: return SOCK_STREAM;
103  }
104  }
105 
107  {
108  switch( SockType )
109  {
110  case SOCK_STREAM: return Network::TLP_TCP;
111  case SOCK_DGRAM: return Network::TLP_UDP;
112  default: return Network::TLP_Invalid;
113  }
114  }
115 
116  sockaddr_storage ConvertToSocketStorage(const SystemAddress& MezzAddr)
117  {
118  sockaddr_storage Ret;
119  Network::NetworkLayerProtocol Protocol = MezzAddr.GetAddress().GetProtocol();
120  if( Protocol == Network::NLP_IPv4 ) {
121  sockaddr_in* Casted = (sockaddr_in*)&Ret;
122  Casted->sin_family = AF_INET;
123  Casted->sin_port = MezzAddr.GetPort(true);
124  Casted->sin_addr.s_addr = MezzAddr.GetAddress().GetV4Address(true);
125  }else if( Protocol == Network::NLP_IPv6 ) {
126  sockaddr_in6* Casted = (sockaddr_in6*)&Ret;
127  Casted->sin6_family = AF_INET6;
128  Casted->sin6_port = MezzAddr.GetPort(true);
129  Casted->sin6_flowinfo = MezzAddr.GetV6Flow();
130  Casted->sin6_scope_id = MezzAddr.GetV6Scope();
131  memcpy( &Casted->sin6_addr.s6_addr[0], &MezzAddr.GetAddress().GetBinaryAddress()[0], IPAddress::IPv6BinaryLength );
132  }else{
133  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Unknown or invalid address type attempting to be converted to Berkeley socket type.");
134  }
135  return Ret;
136  }
137 
138  sockaddr_storage ConvertToSocketStorage(const SocketDescription& MezzAddr)
139  {
140  sockaddr_storage Ret;
142  if( Protocol == Network::NLP_IPv4 ) {
143  sockaddr_in* Casted = (sockaddr_in*)&Ret;
144  Casted->sin_family = AF_INET;
145  Casted->sin_port = MezzAddr.SocketPort;
146  Casted->sin_addr.s_addr = MezzAddr.SocketAddress.GetV4Address(true);
147  }else if( Protocol == Network::NLP_IPv6 ) {
148  sockaddr_in6* Casted = (sockaddr_in6*)&Ret;
149  Casted->sin6_family = AF_INET6;
150  Casted->sin6_port = MezzAddr.SocketPort;
151  Casted->sin6_flowinfo = MezzAddr.V6FlowInformation;
152  Casted->sin6_scope_id = MezzAddr.V6ScopeID;
153  memcpy( &Casted->sin6_addr.s6_addr[0], &MezzAddr.SocketAddress.GetBinaryAddress()[0], IPAddress::IPv6BinaryLength );
154  }else{
155  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Unknown or invalid address type attempting to be converted to Berkeley socket type.");
156  }
157  return Ret;
158  }
159 
160  SystemAddress ConvertToSystemAddress(const sockaddr_storage& BerkAddr)
161  {
162  SystemAddress Ret;
163  if( BerkAddr.ss_family == AF_INET ) {
164  const sockaddr_in& Casted = reinterpret_cast<const sockaddr_in&>(BerkAddr);
165 
166  Ret.GetAddress().SetV4Address(Casted.sin_addr.s_addr,true);
167  Ret.SetPort(Casted.sin_port,true);
168  }else if( BerkAddr.ss_family == AF_INET6 ) {
169  const sockaddr_in6& Casted = reinterpret_cast<const sockaddr_in6&>(BerkAddr);
170 
172  memcpy( &BinAddr[0] , &Casted.sin6_addr.s6_addr[0] , IPAddress::IPv6BinaryLength );
173  Ret.GetAddress().SetBinaryAddress(BinAddr);
174  Ret.SetPort(Casted.sin6_port,true);
175  Ret.SetV6Flow(Casted.sin6_flowinfo);
176  Ret.SetV6Scope(Casted.sin6_scope_id);
177  }else{
178  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Unknown or invalid socket address type attempting to be converted to Mezzanine address.");
179  }
180  return Ret;
181  }
182 
183  SocketDescription ConvertToSocketDescription(const sockaddr_storage& BerkAddr)
184  {
185  SocketDescription Ret;
186  if( BerkAddr.ss_family == AF_INET ) {
187  const sockaddr_in& Casted = reinterpret_cast<const sockaddr_in&>(BerkAddr);
188 
189  Ret.SocketAddress.SetV4Address(Casted.sin_addr.s_addr,true);
190  Ret.SocketPort = Casted.sin_port;
191  }else if( BerkAddr.ss_family == AF_INET6 ) {
192  const sockaddr_in6& Casted = reinterpret_cast<const sockaddr_in6&>(BerkAddr);
193 
195  memcpy( &BinAddr[0] , &Casted.sin6_addr.s6_addr[0] , IPAddress::IPv6BinaryLength );
196  Ret.SocketAddress.SetBinaryAddress(BinAddr);
197  Ret.SocketPort = Casted.sin6_port;
198  Ret.V6FlowInformation = Casted.sin6_flowinfo;
199  Ret.V6ScopeID = Casted.sin6_scope_id;
200  }else{
201  MEZZ_EXCEPTION(ExceptionBase::PARAMETERS_EXCEPTION,"Unknown or invalid socket address type attempting to be converted to Mezzanine socket description.");
202  }
203  return Ret;
204  }
205 
206  ///////////////////////////////////////////////////////////////////////////////
207  // PlatformSocket Methods
208 
209  PlatformSocket::PlatformSocket(int Domain, int Type, int Protocol) :
210  SockDomain(Domain),
211  SockType(Type),
212  Blocking(true)
213  {
214  this->InternalSocket = socket(Domain,Type,Protocol);
215  }
216 
217  PlatformSocket::PlatformSocket(int Domain, int Type, int Protocol, const UInt16 Port) :
218  SockDomain(Domain),
219  SockType(Type),
220  Blocking(true)
221  {
222  this->InternalSocket = socket(Domain,Type,Protocol);
223  this->Bind(Port);
224  }
225 
226  PlatformSocket::PlatformSocket(SocketHandle Handle, int Domain, int Type) :
227  InternalSocket(Handle),
228  SockDomain(Domain),
229  SockType(Type),
230  Blocking(true)
231  { }
232 
234  {
235  #if defined(MEZZ_WINDOWS)
236  ::closesocket(this->InternalSocket);
237  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
238  ::close(this->InternalSocket);
239  #endif
240  }
241 
242  ///////////////////////////////////////////////////////////////////////////////
243  // Core Operations
244 
246  {
247  addrinfo Hints;
248  addrinfo* Results;
249 
250  memset(&Hints,0,sizeof(addrinfo));
251  Hints.ai_family = this->SockDomain;
252  Hints.ai_socktype = this->SockType;
253  Hints.ai_flags = AI_PASSIVE;
254 
255  int Result = getaddrinfo(NULL,( Port != 0 ? StringTools::ConvertToString(Port).c_str() : NULL ),&Hints,&Results);
256  if( Result != 0 ) {
258  }
259 
260  return ( ::bind(this->InternalSocket,Results->ai_addr,Results->ai_addrlen) == 0 );
261  }
262 
264  {
265  sockaddr_storage AddressStorage = ConvertToSocketStorage(Address);
266  Network::NetworkLayerProtocol ProtoType = Address.GetAddress().GetProtocol();
267  if( ProtoType == Network::NLP_IPv4 ) {
268  return this->Bind( (sockaddr*)&AddressStorage, sizeof(sockaddr_in) );
269  }else if( ProtoType == Network::NLP_IPv6 ) {
270  return this->Bind( (sockaddr*)&AddressStorage, sizeof(sockaddr_in6) );
271  }
272  return false;
273  }
274 
275  Boole PlatformSocket::Bind(sockaddr* Address, const AddrLen Length)
276  {
277  #if defined(MEZZ_WINDOWS)
278  return ( ::bind(this->InternalSocket,Address,Length) != SOCKET_ERROR );
279  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
280  return ( ::bind(this->InternalSocket,Address,Length) == 0 );
281  #endif
282  }
283 
285  {
286  #if defined(MEZZ_WINDOWS)
287  return ( ::shutdown(this->InternalSocket,How) != SOCKET_ERROR );
288  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
289  return ( ::shutdown(this->InternalSocket,How) == 0 );
290  #endif
291  }
292 
293  ///////////////////////////////////////////////////////////////////////////////
294  // Core Operations - Stream
295 
297  {
298  sockaddr_storage AddressStorage = ConvertToSocketStorage(Address);
299  Network::NetworkLayerProtocol ProtoType = Address.GetAddress().GetProtocol();
300  if( ProtoType == Network::NLP_IPv4 ) {
301  return this->Connect( (sockaddr*)&AddressStorage, sizeof(sockaddr_in) );
302  }else if( ProtoType == Network::NLP_IPv6 ) {
303  return this->Connect( (sockaddr*)&AddressStorage, sizeof(sockaddr_in6) );
304  }
305  return false;
306  }
307 
308  Boole PlatformSocket::Connect(sockaddr* Address, const AddrLen Length)
309  {
310  #if defined(MEZZ_WINDOWS)
311  return ( ::connect(this->InternalSocket,Address,Length) != SOCKET_ERROR );
312  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
313  return ( ::connect(this->InternalSocket,Address,Length) == 0 );
314  #endif
315  }
316 
317  Boole PlatformSocket::Listen(const int Backlog)
318  {
319  #if defined(MEZZ_WINDOWS)
320  return ( ::listen(this->InternalSocket,Backlog) != SOCKET_ERROR );
321  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
322  return ( ::listen(this->InternalSocket,Backlog) == 0 );
323  #endif
324  }
325 
327  {
328  sockaddr_storage AddressStorage;
329  AddrLen AddressSize = sizeof(sockaddr_storage);
330  SocketHandle NewSock = ::accept(this->InternalSocket,(sockaddr*)&AddressStorage,&AddressSize);
331  if( NewSock != INVALID_SOCKET ) {
332  Address = ConvertToSystemAddress(AddressStorage);
333  return new PlatformSocket(NewSock,this->SockDomain,this->SockType);
334  }
335  return NULL;
336  }
337 
338  PlatformSocket* PlatformSocket::Accept(sockaddr* Address, AddrLen* Length)
339  {
340  SocketHandle NewSock = ::accept(this->InternalSocket,Address,Length);
341  if( NewSock != INVALID_SOCKET ) {
342  return new PlatformSocket(NewSock,this->SockDomain,this->SockType);
343  }
344  return NULL;
345  }
346 
347  Integer PlatformSocket::Send(const void* Buffer, const Integer BufSize, const Integer Flags)
348  {
349  #if defined(MEZZ_WINDOWS)
350  int Ret = ::send(this->InternalSocket,static_cast<const char*>(Buffer),BufSize,Flags);
351  return ( Ret != SOCKET_ERROR ? Ret : -1 );
352  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
353  return ::send(this->InternalSocket,Buffer,BufSize,Flags);
354  #endif
355  }
356 
357  Integer PlatformSocket::Receive(void* Buffer, const Integer BufSize, const Integer Flags)
358  {
359  #if defined(MEZZ_WINDOWS)
360  int Ret = ::recv(this->InternalSocket,static_cast<char*>(Buffer),BufSize,Flags);
361  return ( Ret != SOCKET_ERROR ? Ret : -1 );
362  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
363  return ::recv(this->InternalSocket,Buffer,BufSize,Flags);
364  #endif
365  }
366 
367  ///////////////////////////////////////////////////////////////////////////////
368  // Core Operations - Datagram
369 
370  Integer PlatformSocket::SendTo(const void* Buffer, const Integer BufSize, const Integer Flags, const SystemAddress& Address)
371  {
372  sockaddr_storage AddressStorage = ConvertToSocketStorage(Address);
373  Network::NetworkLayerProtocol ProtoType = Address.GetAddress().GetProtocol();
374  if( ProtoType == Network::NLP_IPv4 ) {
375  return this->SendTo( Buffer, BufSize, Flags, (sockaddr*)&AddressStorage, sizeof(sockaddr_in) );
376  }else if( ProtoType == Network::NLP_IPv6 ) {
377  return this->SendTo( Buffer, BufSize, Flags, (sockaddr*)&AddressStorage, sizeof(sockaddr_in6) );
378  }
379  return -1;
380  }
381 
382  Integer PlatformSocket::SendTo(const void* Buffer, const Integer BufSize, const Integer Flags, const sockaddr* Address, const AddrLen Length)
383  {
384  #if defined(MEZZ_WINDOWS)
385  int Ret = ::sendto(this->InternalSocket,static_cast<const char*>(Buffer),BufSize,Flags,Address,Length);
386  return ( Ret != SOCKET_ERROR ? Ret : -1 );
387  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
388  return ::sendto(this->InternalSocket,Buffer,BufSize,Flags,Address,Length);
389  #endif
390  }
391 
392  Integer PlatformSocket::ReceiveFrom(void* Buffer, const Integer BufSize, const Integer Flags, SystemAddress& Address)
393  {
394  sockaddr_storage AddressStorage;
395  AddrLen AddressSize = sizeof(sockaddr_storage);
396  int Ret = this->ReceiveFrom(Buffer,BufSize,Flags,(sockaddr*)&AddressStorage,&AddressSize);
397  Address = ConvertToSystemAddress(AddressStorage);
398  return Ret;
399  }
400 
401  Integer PlatformSocket::ReceiveFrom(void* Buffer, const Integer BufSize, const Integer Flags, sockaddr* Address, AddrLen* Length)
402  {
403  #if defined(MEZZ_WINDOWS)
404  int Ret = ::recvfrom(this->InternalSocket,static_cast<char*>(Buffer),BufSize,Flags,Address,Length);
405  return ( Ret != SOCKET_ERROR ? Ret : -1 );
406  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
407  return ::recvfrom(this->InternalSocket,Buffer,BufSize,Flags,Address,Length);
408  #endif
409  }
410 
411  ///////////////////////////////////////////////////////////////////////////////
412  // Utility
413 
415  {
416  #if defined(MEZZ_WINDOWS)
417  unsigned long Mode = ( Block ? 0 : 1 );
418  return ( ::ioctlsocket(this->InternalSocket, FIONBIO, &Mode) != SOCKET_ERROR );
419  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
420  //int Flags = fcntl(fd, F_GETFL, 0);
421  int Flags = fcntl(this->InternalSocket, F_GETFL, 0);
422  if( Flags >= 0 ) {
423  Flags = Block ? ( Flags & ~O_NONBLOCK ) : ( Flags | O_NONBLOCK );
424  return ( ::fcntl(this->InternalSocket, F_SETFL, Flags) == 0 );
425  }
426  return false;
427  #endif
428  }
429 
431  { return this->Blocking; }
432 
434  {
435  unsigned long Ret = 0;
436  #if defined(MEZZ_WINDOWS)
437  if( ::ioctlsocket(this->InternalSocket,FIONREAD,&Ret) == SOCKET_ERROR )
438  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
439  if( ::ioctl(this->InternalSocket,FIONREAD,&Ret) < 0 )
440  #endif
441  {
442  return -1;
443  }
444  return Ret;
445  }
446 
448  { return ( this->InternalSocket == INVALID_SOCKET ); }
449 
450  Boole PlatformSocket::SetSocketOption(const Integer Level, const Integer OptID, const char* Value, const AddrLen ValueLen)
451  { return ( ::setsockopt(this->InternalSocket,Level,OptID,Value,ValueLen) != SOCKET_ERROR ); }
452 
453  Boole PlatformSocket::GetSocketOption(const Integer Level, const Integer OptID, char* Value, AddrLen* ValueLen) const
454  { return ( ::getsockopt(this->InternalSocket,Level,OptID,Value,ValueLen) != SOCKET_ERROR ); }
455 
456  ///////////////////////////////////////////////////////////////////////////////
457  // Error Handling
458 
460  {
461  #if defined(MEZZ_WINDOWS)
462  return WSAGetLastError();
463  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
464  return errno;
465  #endif
466  }
467 
468  void PlatformSocket::ThrowError(const int ErrorCode)
469  {
470  #if defined(MEZZ_WINDOWS)
471  char* Str = NULL;
472  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
473  NULL, ErrorCode,
474  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
475  (LPSTR)&Str, 0, NULL);
476  String ErrorMsg( Str );
477  #elif defined(MEZZ_MACOSX) || defined(MEZZ_LINUX)
478  String ErrorMsg( strerror(ErrorCode) );
479  #endif
481  }
482 
484  {
486  }
487  }//Network
488 }//Mezzanine
489 
490 #endif
PlatformSocket * Accept(SystemAddress &Address)
Accepts an incoming connection from a remote host.
int ConvertLayer4ProtocolType(const TransportLayerProtocol Protocol)
Converts from a Mezzanine transport protocol type to it's internal counterpart.
static const UInt16 IPv6BinaryLength
The amount of space needed in a buffer to store the binary representation of an IPv6 address...
Definition: ipaddress.h:66
Thrown when an unknown internal error occurred.
Definition: exception.h:116
Boole Shutdown(const int How)
Disables some or all I/O on the socket.
UInt32 V6FlowInformation
An identifier used for routing IPv6 packets.
static void ThrowLastError()
Throws an exception containing the message from the last socket error.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
sockaddr_storage ConvertToSocketStorage(const SystemAddress &MezzAddr)
Converts a Mezzanine address to a Berkeley sockets address.
User Datagram Protocol.
Boole GetSocketOption(const Integer Level, const Integer OptID, char *Value, AddrLen *ValueLen) const
Get a low level socket parameter.
Boole IsInvalid() const
Gets whether or not this socket is invalid, indicating an error during creation.
short int ConvertLayer3ProtocolType(const NetworkLayerProtocol Protocol)
Converts from a Mezzanine address protocol type to it's internal counterpart.
Integer Send(const void *Buffer, const Integer BufSize, const Integer Flags)
Sends data to the connected remote host.
void SetPort(const UInt16 TargetPort, const Boole NBO=false)
Sets the Port portion of the target system address.
String ConvertToString(const Vector2 &ToConvert)
Converts a Vector2 into a string.
Definition: stringtool.cpp:291
const IPAddress & GetAddress() const
Gets the IP portion of the target system address.
NetworkLayerProtocol
This is an enum listing for recognized protocols on Layer 3 of the OSI model.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
Definition: exception.h:3048
static void ThrowError(const int ErrorCode)
Throws an exception containing the message for a specific error code.
int ConvertToSocketType(const TransportLayerProtocol Protocol)
Converts from a Mezzanine transport protocol type to it's internal counterpart.
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
Boole Connect(const SystemAddress &Address)
Connects this socket to a remote host connected to the network.
SocketDescription ConvertToSocketDescription(const sockaddr_storage &BerkAddr)
Converts a Berkeley sockets address to a Mezzanine socket descriptor.
UInt32 GetV6Flow() const
Gets the flow information to be used for routing packets to the target system.
Used for error conditions.
This implements the exception hiearchy for Mezzanine.
Integer GetNumBytesAvailable() const
Gets the number of bytes currently available to be read from the receive buffer.
void SetBinaryAddress(const AddressContainer &Address)
Sets the binary form of the address being stored.
Definition: ipaddress.cpp:176
UInt32 GetV4Address(const Boole NBO=false) const
Gets a version 4 IP address value.
Definition: ipaddress.cpp:194
Boole Listen(const int Backlog=5)
Prepares this socket for incoming connections.
Internet Protocol version 6.
const int SockType
Whether this is a stream or datagram socket.
Integer SendTo(const void *Buffer, const Integer BufSize, const Integer Flags, const SystemAddress &Address)
Sends data to a remote host.
void SetV6Scope(const UInt32 Scope)
Sets the scope-id for the address.
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
TransportLayerProtocol
This is an enum listing for recognized protocols on Layer 4 of the OSI model.
Boole Bind(const UInt16 Port)
Binds this socket only to a port, accepting transmissions from any interface.
Integer ReceiveFrom(void *Buffer, const Integer BufSize, const Integer Flags, SystemAddress &Address)
Receives data from a remote host.
UInt32 GetV6Scope() const
Gets the scope-id for the address.
UInt32 V6ScopeID
An identifier used to describe how accessible the address is to other hosts.
Integer Receive(void *Buffer, const Integer BufSize, const Integer Flags)
Receives data from the connected remote host.
IPAddress SocketAddress
The IP address.
This is helper class for managing platform specific data of socket implementations.
Used for error conditions.
const AddressContainer & GetBinaryAddress() const
Gets the stored binary address of this IPAddress.
Definition: ipaddress.cpp:179
UInt16 SocketPort
The port on which the socket sends and receives.
Boole SetBlocking(const Boole Block)
Sets whether or not this socket will sleep on I/O calls.
const int SockDomain
The address type used for transmissions on this socket.
PlatformSocket(int Domain, int Type, int Protocol)
Non-binding constructor.
Thrown when parameters are checked at runtime and found invalid.
Definition: exception.h:108
Transmission Control Protocol.
static int GetLastError()
Gets the last error that occured on a socket.
UInt16 GetPort(const Boole NBO=false) const
Gets the Port portion of the target system address.
Boole GetBlocking() const
Gets whether or not this socket will sleep on I/O calls.
Network::NetworkLayerProtocol GetProtocol() const
Gets the type of IP address this is.
Definition: ipaddress.cpp:162
SystemAddress ConvertToSystemAddress(const sockaddr_storage &BerkAddr)
Converts a Berkeley sockets address to a Mezzanine address.
void SetV6Flow(const UInt32 Flow)
Sets the flow information to be used.
A convenience class storing socket data that can be returned from utility methods and used to create ...
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
void SetV4Address(const UInt32 Address, const Boole NBO=false)
Sets a version 4 IP address value.
Definition: ipaddress.cpp:182
SocketHandle InternalSocket
The handle to the internal socket implementation.
std::vector< Int8 > AddressContainer
Convenience type to store the binary representation of IP addresses.
Definition: ipaddress.h:61
Boole Blocking
Whether or not this socket is currently in blocking mode.
Used to allow type inference on PlatformSocket constructors.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
A simple class that stores a complete set of information for establishing connections.
Definition: systemaddress.h:53
Internet Protocol version 4.
Boole SetSocketOption(const Integer Level, const Integer OptID, const char *Value, const AddrLen ValueLen)
Set a low level socket parameter.