2#ifndef POSIX_POSIXSOCKET_H
3#define POSIX_POSIXSOCKET_H
18#include <sys/socket.h>
19#include <netinet/tcp.h>
228 return (0 != this->
sock);
The common base class of Nebula.
Definition refcounted.h:38
Represents an IP address, consisting of a IPv4 host address and a port number.
Platform independent wrapper class for the Sockets API.
Represents an IP address, consisting of a IPv4 host address and a port number.
Definition posixipaddress.h:35
A lowlevel socket wrapper class.
Definition posixsocket.h:33
static Util::String ErrorAsString(ErrorCode err)
convert error code to human readable string
Definition posixsocket.cc:678
bool GetNoDelay()
get nodelay flag
Definition posixsocket.h:354
SizeT GetSendBufSize()
get send buffer size
Definition posixsocket.h:390
bool GetKeepAlive()
get the keepalive flag
Definition posixsocket.h:318
ErrorCode GetErrorCode() const
get the last error code
Definition posixsocket.h:264
bool Accept(Ptr< Net::Socket > &outSocket)
accept incoming connection, return a new socket (for server sockets)
Definition posixsocket.cc:322
bool IsBound() const
return true if the socket is bound to an address
Definition posixsocket.h:235
bool Bind()
bind socket to ip address
Definition posixsocket.cc:276
void SetRecvBufSize(SizeT s)
set receive buffer size
Definition posixsocket.h:363
Result Recv(void *buf, SizeT bufSize, SizeT &bytesReceived)
receive raw data from the socket
Definition posixsocket.cc:507
bool Open(Protocol p)
open the socket
Definition posixsocket.cc:65
ErrorCode error
Definition posixsocket.h:215
int GetIntOption(int optName)
get an integer socket option
Definition posixsocket.cc:220
static void InitNetwork()
static initializer method (called only once)
Definition posixsocket.cc:55
Protocol
protocol types
Definition posixsocket.h:38
@ UDP
Definition posixsocket.h:40
@ TCP
Definition posixsocket.h:39
void SetNoDelay(bool b)
set nodelay flag (TCP_NODELAY)
Definition posixsocket.h:345
void SetSendBufSize(SizeT s)
set send buffer size
Definition posixsocket.h:381
void SetKeepAlive(bool b)
set the keepalive flag (SO_KEEPALIVE)
Definition posixsocket.h:309
void SetBroadcast(bool b)
set the broadcast flag (SO_BROADCAST)
Definition posixsocket.h:273
__DeclareClass(PosixSocket)
void SetSocketError(int wsaError)
set socket error code
Definition posixsocket.cc:598
bool isBlocking
Definition posixsocket.h:218
static ErrorCode SocketErrorToErrorCode(int wsaError)
convert a socket error code to internal error code
Definition posixsocket.cc:609
static Util::String HostErrorToString(int wsaError)
convert host error code directly to string
Definition posixsocket.cc:746
Result Send(const void *buf, SizeT numBytes, SizeT &bytesSent)
send raw data into the socket
Definition posixsocket.cc:437
void SetBlocking(bool b)
set blocking mode (FIONBIO)
Definition posixsocket.cc:241
Result Connect()
connect to the sockets address (for client sockets)
Definition posixsocket.cc:359
PosixSocket()
constructor
Definition posixsocket.cc:26
void SetReUseAddr(bool b)
set reuseaddr flag (SO_REUSEADDR)
Definition posixsocket.h:327
Result SendTo(const void *buf, SizeT numBytes, uint addr, ushort port, SizeT &bytesSent)
send raw data to address for connectionless sockets
Definition posixsocket.cc:555
void SetToLastSocketError()
set error code to errno;
Definition posixsocket.cc:588
const Net::IpAddress & GetAddress() const
get internet address of socket
Definition posixsocket.h:255
bool IsOpen() const
return true if the socket is open
Definition posixsocket.h:226
static ErrorCode HostErrorToErrorCode(int wsaError)
convert a host (gethostbyname) error code to internal error code
Definition posixsocket.cc:659
void OpenWithExistingSocket(int s)
open with an existing socket (called by Accept())
Definition posixsocket.cc:107
static Util::String SocketErrorToString(int wsaError)
convert socket error code directly to string
Definition posixsocket.cc:737
SOCKET sock
Definition posixsocket.h:216
bool GetBlocking() const
get blocking mode
Definition posixsocket.h:409
bool HasRecvData()
return true if recv data is available at the socket
Definition posixsocket.cc:467
bool isBound
Definition posixsocket.h:219
void SetBoolOption(int optName, bool val)
set a bool socket option
Definition posixsocket.cc:153
bool GetBroadcast()
get the broadcast flag
Definition posixsocket.h:282
virtual ~PosixSocket()
destructor
Definition posixsocket.cc:42
void Close()
close the socket
Definition posixsocket.cc:118
void SetDontLinger(bool b)
set the don't linger flag (SO_DONTLINGER)
Definition posixsocket.h:291
ErrorCode
error codes
Definition posixsocket.h:54
@ ErrorHostUnreachable
Definition posixsocket.h:90
@ ErrorConnectionAborted
Definition posixsocket.h:81
@ ErrorUnknown
Definition posixsocket.h:56
@ ErrorNetUnreachable
Definition posixsocket.h:79
@ ErrorNetDown
Definition posixsocket.h:78
@ ErrorVersionNotSupported
Definition posixsocket.h:92
@ ErrorNotInitialized
Definition posixsocket.h:93
@ ErrorOperationNotSupported
Definition posixsocket.h:73
@ ErrorAddrFamilyNotSupported
Definition posixsocket.h:75
@ ErrorInProgress
Definition posixsocket.h:64
@ ErrorConnectionRefused
Definition posixsocket.h:88
@ ErrorProtFamilyNotSupported
Definition posixsocket.h:74
@ ErrorInterrupted
Definition posixsocket.h:57
@ ErrorIsConnected
Definition posixsocket.h:84
@ ErrorPermissionDenied
Definition posixsocket.h:59
@ ErrorNoRecovery
Definition posixsocket.h:98
@ ErrorIsShutdown
Definition posixsocket.h:86
@ ErrorHostNotFound
Definition posixsocket.h:96
@ ErrorSocketTypeNotSupported
Definition posixsocket.h:72
@ ErrorTypeNotFound
Definition posixsocket.h:95
@ ErrorInvalidArgument
Definition posixsocket.h:61
@ ErrorAddrInUse
Definition posixsocket.h:76
@ ErrorAlreadyInProgress
Definition posixsocket.h:65
@ ErrorNone
Definition posixsocket.h:55
@ ErrorNetReset
Definition posixsocket.h:80
@ ErrorWouldBlock
Definition posixsocket.h:63
@ ErrorAddrNotAvailable
Definition posixsocket.h:77
@ ErrorNotConnected
Definition posixsocket.h:85
@ ErrorIsTimedOut
Definition posixsocket.h:87
@ ErrorDestAddrRequired
Definition posixsocket.h:67
@ ErrorMsgTooLong
Definition posixsocket.h:68
@ ErrorBadAddress
Definition posixsocket.h:60
@ ErrorHostDown
Definition posixsocket.h:89
@ ErrorNotASocket
Definition posixsocket.h:66
@ ErrorNoBufferSpace
Definition posixsocket.h:83
@ ErrorTooManyOpenFiles
Definition posixsocket.h:62
@ ErrorConnectionReset
Definition posixsocket.h:82
@ ErrorBadProtocolOption
Definition posixsocket.h:70
@ ErrorSystemNotReady
Definition posixsocket.h:91
@ ErrorInvalidProtocol
Definition posixsocket.h:69
@ ErrorDisconnecting
Definition posixsocket.h:94
@ ErrorNoData
Definition posixsocket.h:99
@ ErrorTryAgain
Definition posixsocket.h:97
@ ErrorProtocolNotSupported
Definition posixsocket.h:71
@ ErrorBrokenPipe
Definition posixsocket.h:58
Result
Definition posixsocket.h:45
@ Success
Definition posixsocket.h:47
@ WouldBlock
Definition posixsocket.h:48
@ Closed
Definition posixsocket.h:49
@ Error
Definition posixsocket.h:46
Result RecvFrom(void *buf, SizeT bufSize, uint addr, ushort port, SizeT &bytesReceived)
receive raw data from address for connectionless sockets
Definition posixsocket.cc:567
bool GetBoolOption(int optName)
get a bool socket option
Definition posixsocket.cc:177
SizeT GetRecvBufSize()
get receive buffer size
Definition posixsocket.h:372
bool GetReUseAddr()
get reuseaddr flag
Definition posixsocket.h:336
void SetIntOption(int optName, int val)
set an integer socket option
Definition posixsocket.cc:203
bool IsConnected()
test if the socket is currently connected
Definition posixsocket.cc:403
void ClearError()
clear the last error code
Definition posixsocket.cc:578
Util::String GetErrorString() const
get the last error string
Definition posixsocket.cc:755
void SetAddress(const Net::IpAddress &a)
set internet address of socket
Definition posixsocket.h:245
static bool NetworkInitialized
Definition posixsocket.h:214
bool GetDontLinger()
get the don't linger flag
Definition posixsocket.h:300
SizeT GetMaxMsgSize()
get the maximum message size that can be sent atomically
Definition posixsocket.h:399
Net::IpAddress addr
Definition posixsocket.h:217
bool Listen()
listen for incoming connections (for server sockets)
Definition posixsocket.cc:299
Provides Posix specific helper functions.
Definition posixsysfunc.h:25
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Definition debugmessage.h:20
Posix implemention of a read-many write-few lock.
Definition posixsysfunc.cc:21
int SOCKET
Definition posixsocket.h:30
Nebula's universal string class.
Definition string.h:50
int SizeT
Definition types.h:49
unsigned int uint
Definition types.h:31
unsigned short ushort
Definition types.h:32