ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Loading...
Searching...
No Matches
ost::Socket Class Reference

#include <socket.h>

Inheritance diagram for ost::Socket:
[legend]
Collaboration diagram for ost::Socket:
[legend]

Public Types

enum  State {
  INITIAL , AVAILABLE , BOUND , CONNECTED ,
  CONNECTING , STREAM
}
 
enum  Family { IPV4 = AF_INET }
 
enum  Error {
  errSuccess = 0 , errCreateFailed , errCopyFailed , errInput ,
  errInputInterrupt , errResourceFailure , errOutput , errOutputInterrupt ,
  errNotConnected , errConnectRefused , errConnectRejected , errConnectTimeout ,
  errConnectFailed , errConnectInvalid , errConnectBusy , errConnectNoRoute ,
  errBindingFailed , errBroadcastDenied , errRoutingDenied , errKeepaliveDenied ,
  errServiceDenied , errServiceUnavailable , errMulticastDisabled , errTimeout ,
  errNoDelay , errExtended , errLookupFail , errSearchErr ,
  errInvalidValue
}
 
enum  Tos {
  tosLowDelay = 0 , tosThroughput , tosReliability , tosMinCost ,
  tosInvalid
}
 
enum  Pending { pendingInput , pendingOutput , pendingError }
 
typedef enum State State
 
typedef enum Family Family
 
typedef enum Error Error
 
typedef enum Tos Tos
 
typedef enum Pending Pending
 

Public Member Functions

 ~Socket ()
 Shutdown, close, and destroy socket. More...
 
Error getErrorNumber (void) const
 Often used by a "catch" to fetch the last error of a thrown socket. More...
 
const char * getErrorString (void) const
 Often used by a "catch" to fetch the user set error string of a thrown socket, but only if EXTENDED error codes are used. More...
 
long getSystemError (void) const
 
const char * getSystemErrorString (void) const
 
virtual bool isPending (Pending pend, timeout_t timeout=TIMEOUT_INF)
 Get the status of pending operations. More...
 
bool operator! () const
 Operator based testing to see if a socket is currently active. More...
 
 operator bool () const
 
Socketoperator= (const Socket &from)
 Sockets may also be duplicated by the assignment operator. More...
 
ucommon::Socket::address getSender () const
 May be used to examine the origin of data waiting in the socket receive queue. More...
 
virtual IPV4Host getIPV4Sender (in_port_t *port=NULL) const
 
IPV4Host getSender (in_port_t *port) const
 
ucommon::Socket::address getPeer () const
 Get the host address and port of the socket this socket is connected to. More...
 
IPV4Host getIPV4Peer (in_port_t *port=NULL) const
 
IPV4Host getPeer (in_port_t *port) const
 
IPV4Host getIPV4Local (in_port_t *port=NULL) const
 Get the local address and port number this socket is currently bound to. More...
 
IPV4Host getLocal (in_port_t *port) const
 
ucommon::Socket::address getLocal () const
 
void setCompletion (bool immediate)
 Used to specify blocking mode for the socket. More...
 
Error setLinger (bool linger)
 Enable lingering sockets on close. More...
 
Error setKeepAlive (bool enable)
 Set the keep-alive status of this socket and if keep-alive messages will be sent. More...
 
Error setTypeOfService (Tos service)
 Set packet scheduling on platforms which support ip quality of service conventions. More...
 
bool isConnected (void) const
 Can test to see if this socket is "connected", and hence whether a "catch" can safely call getPeer(). More...
 
bool isActive (void) const
 Test to see if the socket is at least operating or if it is mearly initialized. More...
 
bool isBroadcast (void) const
 Return if broadcast has been enabled for the specified socket. More...
 
bool isRouted (void) const
 Return if socket routing is enabled. More...
 
struct in_addr getaddress (const IPV4Address &ia) const
 

Static Public Member Functions

static bool check (Family fam)
 See if a specific protocol family is available in the current runtime environment. More...
 

Protected Member Functions

Error error (Error error, const char *err=NULL, long systemError=0) const
 This service is used to throw all socket errors which usually occur during the socket constructor. More...
 
void error (const char *err) const
 This service is used to throw application defined socket errors where the application specific error code is a string. More...
 
void setError (bool enable)
 This service is used to turn the error handler on or off for "throwing" exceptions by manipulating the thrown flag. More...
 
void endSocket (void)
 Used as the default destructor for ending a socket. More...
 
Error connectError (void) const
 Used as a common handler for connection failure processing. More...
 
Error sendLimit (int limit=2048)
 Set the send limit. More...
 
Error receiveLimit (int limit=1)
 Set thr receive limit. More...
 
Error sendTimeout (timeout_t timer)
 Set the send timeout for sending raw network data. More...
 
Error receiveTimeout (timeout_t timer)
 Receive timeout for receiving raw network data. More...
 
Error sendBuffer (unsigned size)
 Set the protocol stack network kernel send buffer size associated with the socket. More...
 
Error receiveBuffer (unsigned size)
 Set the protocol stack network kernel receive buffer size associated with the socket. More...
 
Error bufferSize (unsigned size)
 Set the total protocol stack network kernel buffer size for both send and receive together. More...
 
Error setBroadcast (bool enable)
 Set the subnet broadcast flag for the socket. More...
 
Error setMulticastByFamily (bool enable, Family family=IPV4)
 Setting multicast binds the multicast interface used for the socket to the interface the socket itself has been implicitly bound to. More...
 
Error setLoopbackByFamily (bool enable, Family family=IPV4)
 Set the multicast loopback flag for the socket. More...
 
Error setTimeToLiveByFamily (uint8_t ttl, Family fam=IPV4)
 Set the multicast time to live for a multicast socket. More...
 
Error join (const ucommon::Socket::address &ia, int iface=0)
 Join a multicast group. More...
 
Error join (const IPV4Multicast &ia)
 
Error drop (const ucommon::Socket::address &ia, int iface=0)
 Drop membership from a multicast group. More...
 
Error drop (const IPV4Multicast &ia)
 
Error setRouting (bool enable)
 Set the socket routing to indicate if outgoing messages should bypass normal routing (set false). More...
 
Error setNoDelay (bool enable)
 Enable/disable delaying packets (Nagle algorithm) More...
 
 Socket (int domain, int type, int protocol=0)
 An unconnected socket may be created directly on the local machine. More...
 
 Socket (socket_t fd)
 A socket object may be created from a file descriptor when that descriptor was created either through a socket() or accept() call. More...
 
 Socket ()
 Create an inactive socket object for base constructors. More...
 
 Socket (const Socket &source)
 A socket can also be constructed from an already existing Socket object. More...
 
ssize_t readLine (char *buf, size_t len, timeout_t timeout=0)
 Process a logical input line from a socket descriptor directly. More...
 
virtual ssize_t readData (void *buf, size_t len, char separator=0, timeout_t t=0)
 Read in a block of len bytes with specific separator. More...
 
virtual ssize_t writeData (const void *buf, size_t len, timeout_t t=0)
 Write a block of len bytes to socket. More...
 
- Protected Member Functions inherited from ucommon::Socket
 Socket ()
 Create a socket object for use. More...
 
 Socket (const Socket &existing)
 Create socket as duped handle of existing socket. More...
 
 Socket (socket_t socket)
 Create socket from existing socket descriptor. More...
 
 Socket (const struct addrinfo *address)
 Create and connect a socket to an address from an address list. More...
 
 Socket (int family, int type, int protocol=0)
 Create an unbound socket of a specific type. More...
 
 Socket (const char *address, const char *port, int family=AF_UNSPEC, int type=0, int protocol=0)
 Create a bound socket. More...
 
virtual ~Socket ()
 Shutdown, close, and destroy socket. More...
 
void cancel (void)
 Cancel pending i/o by shutting down the socket. More...
 
void release (void)
 Shutdown and close the socket. More...
 
int err (void) const
 Get error code. More...
 
bool is_pending (unsigned value)
 See the number of bytes in the receive queue. More...
 
bool connected (void) const
 Test if socket is connected. More...
 
bool wait (timeout_t timeout=0) const
 Test for pending input data. More...
 
int nodelay (void) const
 Set nodelay option for tcp socket. More...
 
bool waitSending (timeout_t timeout=0) const
 Test for output data sent. More...
 
unsigned pending (void) const
 Get the number of bytes of data in the socket receive buffer. More...
 
int broadcast (bool enable)
 Set socket for unicast mode broadcasts. More...
 
int keepalive (bool enable)
 Set socket for keepalive packets. More...
 
int blocking (bool enable)
 Set socket blocking I/O mode. More...
 
int multicast (unsigned ttl=1)
 Set multicast mode and multicast broadcast range. More...
 
int loopback (bool enable)
 Set loopback to read multicast packets we broadcast. More...
 
int getError (void) const
 Get socket error code. More...
 
int ttl (uint8_t time)
 Set the time to live before packets expire. More...
 
int sendsize (unsigned size)
 Set the size of the socket send buffer. More...
 
int sendwait (unsigned size)
 Set the size to wait before sending. More...
 
int recvsize (unsigned size)
 Set the size of the socket receive buffer. More...
 
int type (void) const
 Get the type of a socket. More...
 
unsigned segsize (unsigned size)
 Set segment size and get mtu of a socket. More...
 
bool ccid (uint8_t id)
 Set ccid of dccp socket. More...
 
int tos (int type)
 Set the type of service field of outgoing packets. More...
 
int priority (int scheduling)
 Set packet priority, 0 to 6 unless privileged. More...
 
void shutdown (void)
 Shutdown the socket communication channel. More...
 
int connectto (struct addrinfo *list)
 Connect our socket to a remote host from an address list. More...
 
int disconnect (void)
 Disconnect a connected socket. More...
 
int join (const struct addrinfo *list, const int ifindex=0)
 Join socket to multicast group. More...
 
int drop (const struct addrinfo *list, const int ifindex=0)
 Drop socket from multicast group. More...
 
int wait (timeout_t timeout=Timer::inf)
 Socket i/o timer setting. More...
 
size_t peek (void *data, size_t number) const
 Peek at data waiting in the socket receive buffer. More...
 
size_t readfrom (void *data, size_t number, struct sockaddr_storage *address=NULL)
 Read data from the socket receive buffer. More...
 
size_t writeto (const void *data, size_t number, const struct sockaddr *address=NULL)
 Write data to the socket send buffer. More...
 
size_t readline (char *data, size_t size)
 Read a newline of text data from the socket and save in NULL terminated string. More...
 
size_t printf (const char *format,...) __PRINTF(2
 Print formatted string to socket. More...
 
size_t size_t readline (String &buffer)
 Read a string of input from the socket and strip trailing newline. More...
 
stringref_t readline (size_t maxsize)
 
static ssize_t size_t writes (const char *string)
 Write a null terminated string to the socket. More...
 
 operator bool () const
 Test if socket is valid. More...
 
bool operator! () const
 Test if socket is invalid. More...
 
Socketoperator= (socket_t socket)
 Assign socket from a socket descriptor. More...
 
 operator socket_t () const
 Get the socket descriptor by casting. More...
 
socket_t operator* () const
 Get the socket descriptor by pointer reference. More...
 

Static Protected Member Functions

static socket_t dupSocket (socket_t s, Socket::State state)
 
- Static Protected Member Functions inherited from ucommon::Socket
static struct addrinfoquery (const char *host, const char *service, int type=SOCK_STREAM, int protocol=0)
 Get an address list directly. More...
 
static void release (struct addrinfo *list)
 Release an address list directly. More...
 
static void cancel (socket_t socket)
 Cancel pending i/o by shutting down the socket. More...
 
static bool wait (socket_t socket, timeout_t timeout=0)
 Test for pending input data. More...
 
static int type (const socket_t socket)
 Get the type of a socket. More...
 
static unsigned segsize (socket_t socket, unsigned size=0)
 Set segment size and get MTU. More...
 
static bool ccid (socket_t socket, uint8_t id)
 Set congestion control id. More...
 
static ssize_t readline (socket_t socket, char *data, size_t size, timeout_t timeout=Timer::inf)
 Read a newline of text data from the socket and save in NULL terminated string. More...
 
static ssize_t printf (socket_t socket, const char *format,...) __PRINTF(2
 Print formatted string to socket. More...
 
static unsigned pending (socket_t socket)
 Get the number of bytes pending in the receive buffer of a socket descriptor. More...
 
static int sendsize (socket_t socket, unsigned size)
 Set the send size of a socket descriptor. More...
 
static int sendwait (socket_t socket, unsigned size)
 Set the size to wait before sending. More...
 
static int recvsize (socket_t socket, unsigned size)
 Set the receive size of a socket descriptor. More...
 
static int connectto (socket_t socket, struct addrinfo *list)
 Connect socket descriptor to a remote host from an address list. More...
 
static int disconnect (socket_t socket)
 Disconnect a connected socket descriptor. More...
 
static int drop (socket_t socket, const struct addrinfo *list, const int ifindex=0)
 Drop socket descriptor from multicast group. More...
 
static int join (socket_t socket, const struct addrinfo *list, const int ifindex=0)
 Join socket descriptor to multicast group. More...
 
static int error (const socket_t socket)
 Get socket error code of socket descriptor. More...
 
static int multicast (socket_t socket, unsigned ttl=1)
 Set multicast mode and multicast broadcast range for socket descriptor. More...
 
static int loopback (socket_t socket, bool enable)
 Set loopback to read multicast packets socket descriptor broadcasts. More...
 
static int blocking (socket_t socket, bool enable)
 Set socket blocking I/O mode of socket descriptor. More...
 
static int keepalive (socket_t socket, bool enable)
 Set socket for keepalive packets for socket descriptor. More...
 
static int broadcast (socket_t socket, bool enable)
 Set socket for unicast mode broadcasts on socket descriptor. More...
 
static int nodelay (socket_t socket)
 Set tcp nodelay option on socket descriptor. More...
 
static int priority (socket_t socket, int scheduling)
 Set packet priority of socket descriptor. More...
 
static int tos (socket_t socket, int type)
 Set type of service of socket descriptor. More...
 
static int ttl (socket_t socket, uint8_t time)
 Set the time to live for the socket descriptor. More...
 
static int family (socket_t socket)
 Get the address family of the socket descriptor. More...
 
static int family (const struct sockaddr_storage &address)
 Get the address family of a socket address object. More...
 
static int family (const struct sockaddr_internet &address)
 Get the address family of an internet socket address object. More...
 
static ssize_t recvfrom (socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_storage *address=NULL)
 Get data waiting in receive queue. More...
 
static ssize_t sendto (socket_t socket, const void *buffer, size_t size, int flags=0, const struct sockaddr *address=NULL)
 Send data on socket. More...
 
static ssize_t replyto (socket_t socket, const void *buffer, size_t size, int flags, const struct sockaddr_storage *address)
 Send reply on socket. More...
 
static int bindto (socket_t socket, const char *address, const char *service, int protocol=0)
 Bind the socket descriptor to a known interface and service port. More...
 
static int listento (socket_t socket, const struct sockaddr *address, int backlog=5)
 Bind the socket descriptor to a known interface listen on service port. More...
 
static int bindto (socket_t socket, const struct sockaddr *address)
 Bind the socket descriptor to a known interface. More...
 
static socket_t acceptfrom (socket_t socket, struct sockaddr_storage *address=NULL)
 Accept a socket connection from a remote host. More...
 
static socket_t create (int family, int type, int protocol)
 Create a socket object unbound. More...
 
static socket_t create (const struct addrinfo *address, int type, int protocol)
 Create a connected socket. More...
 
static socket_t create (const char *iface, const char *service, int family=AF_UNSPEC, int type=0, int protocol=0)
 Create a bound socket for a service. More...
 
static socket_t create (const Socket::address &address)
 Create a connected socket for a service. More...
 
static void release (socket_t socket)
 Release (close) a socket. More...
 
static char * hostname (const struct sockaddr *address, char *buffer, size_t size)
 Lookup and return the host name associated with a socket address. More...
 
static struct addrinfohinting (socket_t socket, struct addrinfo *hint)
 Create an address info lookup hint based on the family and type properties of a socket descriptor. More...
 
static socklen_t query (socket_t socket, struct sockaddr_storage *address, const char *hostname, const char *service)
 Lookup a host name and service address based on the addressing family and socket type of a socket descriptor. More...
 
static socklen_t len (const struct sockaddr *address)
 Get the size of a socket address. More...
 
static bool equal (const struct sockaddr *address1, const struct sockaddr *address2)
 Compare socket addresses. More...
 
static unsigned copy (struct sockaddr *target, const struct sockaddr *origin)
 Copy a socket address. More...
 
static unsigned store (struct sockaddr_storage *storage, const struct sockaddr *address)
 Store an address into an address object. More...
 
static unsigned store (struct sockaddr_internet *storage, const struct sockaddr *address)
 Store an address into an internet address object. More...
 
static bool eq_host (const struct sockaddr *address1, const struct sockaddr *address2)
 Compare socket host addresses. More...
 
static bool eq_from (const struct sockaddr_storage *address1, const struct sockaddr_storage *address2)
 Compare socket addresses. More...
 
static bool eq_inet (const struct sockaddr_internet *address1, const struct sockaddr_internet *address2)
 Compare socket addresses. More...
 
static bool eq_subnet (const struct sockaddr *address1, const struct sockaddr *address2)
 See if both addresses are in the same subnet. More...
 
static int via (struct sockaddr *address, const struct sockaddr *target, socklen_t size=0)
 Get the socket address of the interface needed to reach a destination address. More...
 
static char * query (const struct sockaddr *address, char *buffer, socklen_t size)
 Get the hostname of a socket address. More...
 
static in_port_t port (const struct sockaddr *address)
 Get the service port of a socket. More...
 
static in_port_t port (const struct sockaddr_internet *address)
 Get the service port of an inet socket. More...
 
static unsigned keyindex (const struct sockaddr *address, unsigned size)
 Convert a socket address and service into a hash map index. More...
 
static unsigned keyhost (const struct sockaddr *address, unsigned size)
 Convert a socket host address into a hash map index. More...
 
static void init (void)
 Initialize socket subsystem. More...
 
static void query (int family)
 Set default socket family preference for query options when the socket type is otherwise not specified. More...
 
static void v4mapping (bool enable)
 Set the default socket behavior for v6-v4 mapping. More...
 
static int error (void)
 Return error code of last socket operation,. More...
 
static bool is_null (const char *string)
 Simple function to validate that a given IP address string is a "zero" address. More...
 
static bool is_numeric (const char *string)
 Simple function to validate that a given IP address string is a numeric address. More...
 
static int local (socket_t socket, struct sockaddr_storage *address)
 Get local address to which the socket is bound. More...
 
static int remote (socket_t socket, struct sockaddr_storage *address)
 Get remote address to which the socket is connected. More...
 

Protected Attributes

struct {
   bool   thrown: 1
 
   bool   broadcast: 1
 
   bool   route: 1
 
   bool   keepalive: 1
 
   bool   loopback: 1
 
   bool   multicast: 1
 
   bool   completion: 1
 
   bool   linger: 1
 
   unsigned   ttl: 8
 
flags
 
State volatile state
 
- Protected Attributes inherited from ucommon::Socket
socket_t so
 
int ioerr
 
timeout_t iowait
 

Private Member Functions

void setSocket (void)
 

Private Attributes

Error errid
 
const char * errstr
 
long syserr
 

Additional Inherited Members

- Protected Types inherited from ucommon::Socket
typedef struct hostaddr_internet host_t
 
typedef cidr cidr_t
 

Detailed Description

Definition at line 92 of file socket.h.

Member Typedef Documentation

◆ Error

typedef enum Error ost::Socket::Error

Definition at line 146 of file socket.h.

◆ Family

Definition at line 112 of file socket.h.

◆ Pending

Definition at line 162 of file socket.h.

◆ State

typedef enum State ost::Socket::State

Definition at line 103 of file socket.h.

◆ Tos

typedef enum Tos ost::Socket::Tos

Definition at line 155 of file socket.h.

Member Enumeration Documentation

◆ Error

Enumerator
errSuccess 
errCreateFailed 
errCopyFailed 
errInput 
errInputInterrupt 
errResourceFailure 
errOutput 
errOutputInterrupt 
errNotConnected 
errConnectRefused 
errConnectRejected 
errConnectTimeout 
errConnectFailed 
errConnectInvalid 
errConnectBusy 
errConnectNoRoute 
errBindingFailed 
errBroadcastDenied 
errRoutingDenied 
errKeepaliveDenied 
errServiceDenied 
errServiceUnavailable 
errMulticastDisabled 
errTimeout 
errNoDelay 
errExtended 
errLookupFail 
errSearchErr 
errInvalidValue 

Definition at line 114 of file socket.h.

◆ Family

Enumerator
IPV4 

Definition at line 105 of file socket.h.

◆ Pending

Enumerator
pendingInput 
pendingOutput 
pendingError 

Definition at line 157 of file socket.h.

◆ State

Enumerator
INITIAL 
AVAILABLE 
BOUND 
CONNECTED 
CONNECTING 
STREAM 

Definition at line 95 of file socket.h.

◆ Tos

Enumerator
tosLowDelay 
tosThroughput 
tosReliability 
tosMinCost 
tosInvalid 

Definition at line 148 of file socket.h.

Constructor & Destructor Documentation

◆ Socket() [1/4]

ost::Socket::Socket ( int  domain,
int  type,
int  protocol = 0 
)
protected

An unconnected socket may be created directly on the local machine.

Sockets can occupy both the internet domain (AF_INET) and UNIX socket domain (AF_UNIX) under unix. The socket type (SOCK_STREAM, SOCK_DGRAM) and protocol may also be specified. If the socket cannot be created, an exception is thrown.

Parameters
domainsocket domain to use.
typebase type and protocol family of the socket.
protocolspecific protocol to apply.

Definition at line 173 of file socket.cpp.

References AVAILABLE, errCreateFailed, ucommon::Socket::error(), INVALID_SOCKET, setSocket(), ucommon::Socket::so, socket_errno, state, and ucommon::Socket::type().

Here is the call graph for this function:

◆ Socket() [2/4]

ost::Socket::Socket ( socket_t  fd)
protected

A socket object may be created from a file descriptor when that descriptor was created either through a socket() or accept() call.

This constructor is mostly for internal use.

Parameters
fdfile descriptor of an already existing socket.

Definition at line 188 of file socket.cpp.

References AVAILABLE, errCreateFailed, ucommon::Socket::error(), INVALID_SOCKET, setSocket(), ucommon::Socket::so, and state.

Here is the call graph for this function:

◆ Socket() [3/4]

ost::Socket::Socket ( )
protected

Create an inactive socket object for base constructors.

Definition at line 168 of file socket.cpp.

References setSocket().

Here is the call graph for this function:

◆ Socket() [4/4]

ost::Socket::Socket ( const Socket source)
protected

A socket can also be constructed from an already existing Socket object.

On POSIX systems, the socket file descriptor is dup()'d. On Win32, DuplicateHandle() is used.

Parameters
sourceof existing socket to clone.

Definition at line 199 of file socket.cpp.

References dupSocket(), errCopyFailed, ucommon::Socket::error(), INVALID_SOCKET, setSocket(), ucommon::Socket::so, socket_errno, and state.

Here is the call graph for this function:

◆ ~Socket()

ost::Socket::~Socket ( )
virtual

Shutdown, close, and destroy socket.

Reimplemented from ucommon::Socket.

Definition at line 208 of file socket.cpp.

References endSocket().

Here is the call graph for this function:

Member Function Documentation

◆ bufferSize()

Socket::Error ost::Socket::bufferSize ( unsigned  size)
protected

Set the total protocol stack network kernel buffer size for both send and receive together.

Returns
errSuccess on success
Parameters
sizeof buffer.

Definition at line 362 of file socket.cpp.

References ucommon::Socket::err(), errSuccess, receiveBuffer(), and sendBuffer().

Referenced by ost::TCPStream::segmentBuffering().

Here is the call graph for this function:

◆ check()

bool ost::Socket::check ( Family  fam)
static

See if a specific protocol family is available in the current runtime environment.

Returns
true if family available.

Definition at line 815 of file socket.cpp.

References INVALID_SOCKET, IPV4, ucommon::Socket::release(), and ucommon::Socket::so.

Here is the call graph for this function:

◆ connectError()

Socket::Error ost::Socket::connectError ( void  ) const
protected

Used as a common handler for connection failure processing.

Returns
correct failure code to apply.

Definition at line 262 of file socket.cpp.

References errConnectBusy, errConnectFailed, errConnectInvalid, errConnectNoRoute, errConnectRefused, errConnectTimeout, ucommon::Socket::error(), socket_errno, and ucommon::str().

Referenced by ost::DCCPSocket::connect(), ost::TCPStream::connect(), ost::UDPTransmit::connect(), and ost::UDPReceive::connect().

Here is the call graph for this function:

◆ drop() [1/2]

Error ost::Socket::drop ( const IPV4Multicast ia)
inlineprotected

Definition at line 351 of file socket.h.

References ost::getaddress().

Here is the call graph for this function:

◆ drop() [2/2]

Socket::Error ost::Socket::drop ( const ucommon::Socket::address ia,
int  iface = 0 
)
protected

Drop membership from a multicast group.

Returns
0 (errSuccess) on success, else error code.
Parameters
iaaddress of multicast group to drop.

Definition at line 503 of file socket.cpp.

References ucommon::Socket::drop(), errMulticastDisabled, errNotConnected, ucommon::Socket::error(), errServiceUnavailable, and errSuccess.

Here is the call graph for this function:

◆ dupSocket()

socket_t ost::Socket::dupSocket ( socket_t  s,
Socket::State  state 
)
staticprotected

Definition at line 113 of file socket.cpp.

References ucommon::dup(), and ucommon::Socket::so.

Referenced by operator=(), and Socket().

Here is the call graph for this function:

◆ endSocket()

void ost::Socket::endSocket ( void  )
protected

Used as the default destructor for ending a socket.

This will cleanly terminate the socket connection. It is provided for use in derived virtual destructors.

Definition at line 136 of file socket.cpp.

References flags, INITIAL, INVALID_SOCKET, linger, ucommon::Socket::release(), ucommon::Socket::so, state, and STREAM.

Referenced by ost::DCCPSocket::connect(), ost::TCPStream::connect(), ost::DCCPSocket::DCCPSocket(), ost::DCCPSocket::disconnect(), ost::TCPStream::endStream(), operator=(), ost::TCPSession::TCPSession(), ost::TCPSocket::TCPSocket(), ost::TCPStream::TCPStream(), ost::UDPSocket::UDPSocket(), ost::TCPSession::waitConnection(), ost::DCCPSocket::~DCCPSocket(), ~Socket(), ost::TCPSocket::~TCPSocket(), and ost::UDPSocket::~UDPSocket().

Here is the call graph for this function:

◆ error() [1/2]

void ost::Socket::error ( const char *  err) const
inlineprotected

This service is used to throw application defined socket errors where the application specific error code is a string.

Parameters
errstring or message to pass.

Definition at line 205 of file socket.h.

References error.

◆ error() [2/2]

Socket::Error ost::Socket::error ( Error  error,
const char *  err = NULL,
long  systemError = 0 
) const
protected

This service is used to throw all socket errors which usually occur during the socket constructor.

Parameters
errordefined socket error id.
errstring or message to pass.
systemErrorthe system error# that caused the error

Definition at line 213 of file socket.cpp.

References ucommon::Socket::err(), errid, errstr, flags, ost::Thread::getException(), syserr, THROW, ost::Thread::throwException, ost::Thread::throwNothing, and ost::Thread::throwObject.

Here is the call graph for this function:

◆ getaddress()

struct in_addr ost::Socket::getaddress ( const IPV4Address ia) const
inline

Definition at line 646 of file socket.h.

References ost::getaddress().

Referenced by ost::DCCPSocket::DCCPSocket(), ost::UDPSocket::join(), and ost::TCPSocket::TCPSocket().

Here is the call graph for this function:

◆ getErrorNumber()

Error ost::Socket::getErrorNumber ( void  ) const
inline

Often used by a "catch" to fetch the last error of a thrown socket.

Returns
error number of Error error.

Definition at line 456 of file socket.h.

◆ getErrorString()

const char * ost::Socket::getErrorString ( void  ) const
inline

Often used by a "catch" to fetch the user set error string of a thrown socket, but only if EXTENDED error codes are used.

Returns
string for error message.

Definition at line 466 of file socket.h.

◆ getIPV4Local()

IPV4Host ost::Socket::getIPV4Local ( in_port_t *  port = NULL) const

Get the local address and port number this socket is currently bound to.

Parameters
portptr to port number on local host.
Returns
host address of interface this socket is bound to.

Definition at line 916 of file socket.cpp.

References getLocal(), and port.

Here is the call graph for this function:

◆ getIPV4Peer()

IPV4Host ost::Socket::getIPV4Peer ( in_port_t *  port = NULL) const

Definition at line 969 of file socket.cpp.

References getPeer(), and port.

Here is the call graph for this function:

◆ getIPV4Sender()

IPV4Host ost::Socket::getIPV4Sender ( in_port_t *  port = NULL) const
virtual

Reimplemented in ost::DCCPSocket.

Definition at line 867 of file socket.cpp.

References ucommon::addr(), getSender(), and port.

Here is the call graph for this function:

◆ getLocal() [1/2]

ucommon::Socket::address ost::Socket::getLocal ( ) const

Definition at line 902 of file socket.cpp.

References ucommon::addr(), ucommon::Socket::error(), errResourceFailure, ucommon::Socket::address::insert(), ucommon::Socket::len(), ucommon::Socket::so, and socket_errno.

Referenced by ost::UDPSocket::disconnect(), and getIPV4Local().

Here is the call graph for this function:

◆ getLocal() [2/2]

IPV4Host ost::Socket::getLocal ( in_port_t *  port) const
inline

Definition at line 559 of file socket.h.

References port.

◆ getPeer() [1/2]

ucommon::Socket::address ost::Socket::getPeer ( ) const

Get the host address and port of the socket this socket is connected to.

If the socket is currently not in a connected state, then a host address of 0.0.0.0 is returned.

Parameters
portptr to port number of remote socket.
Returns
host address of remote socket.

Definition at line 950 of file socket.cpp.

References ucommon::addr(), errNotConnected, ucommon::Socket::error(), errResourceFailure, ucommon::Socket::address::insert(), ucommon::Socket::len(), ucommon::Socket::so, and socket_errno.

Referenced by ost::TCPStream::connect(), getIPV4Peer(), ost::UDPSocket::getPeer(), and ost::TCPStream::TCPStream().

Here is the call graph for this function:

◆ getPeer() [2/2]

IPV4Host ost::Socket::getPeer ( in_port_t *  port) const
inline

Definition at line 542 of file socket.h.

References port.

◆ getSender() [1/2]

ucommon::Socket::address ost::Socket::getSender ( ) const

May be used to examine the origin of data waiting in the socket receive queue.

This can tell a TCP server where pending "connect" requests are coming from, or a UDP socket where it's next packet arrived from.

Parameters
portptr to port number of sender.
Returns
host address, test with "isInetAddress()".

Definition at line 839 of file socket.cpp.

References ucommon::addr(), errInput, ucommon::Socket::error(), ucommon::Socket::len(), ucommon::Socket::recvfrom(), ucommon::Socket::so, and socket_errno.

Referenced by getIPV4Sender().

Here is the call graph for this function:

◆ getSender() [2/2]

IPV4Host ost::Socket::getSender ( in_port_t *  port) const
inline

Definition at line 521 of file socket.h.

References port.

◆ getSystemError()

long ost::Socket::getSystemError ( void  ) const
inline

Definition at line 470 of file socket.h.

◆ getSystemErrorString()

const char * ost::Socket::getSystemErrorString ( void  ) const

Definition at line 695 of file socket.cpp.

References errid, errstr, and syserr.

◆ isActive()

bool ost::Socket::isActive ( void  ) const

Test to see if the socket is at least operating or if it is mearly initialized.

"initialized" sockets may be the result of failed constructors.

Returns
true if not in initial state.

Definition at line 1098 of file socket.cpp.

References INITIAL, and state.

◆ isBroadcast()

bool ost::Socket::isBroadcast ( void  ) const
inline

Return if broadcast has been enabled for the specified socket.

Returns
true if broadcast socket.

Definition at line 632 of file socket.h.

Referenced by ost::UDPTransmit::connect().

◆ isConnected()

bool ost::Socket::isConnected ( void  ) const

Can test to see if this socket is "connected", and hence whether a "catch" can safely call getPeer().

Of course, an unconnected socket will return a 0.0.0.0 address from getPeer() as well.

Returns
true when socket is connected to a peer.

Definition at line 1093 of file socket.cpp.

References CONNECTED, and state.

Referenced by ost::UDPSocket::receive(), and ost::UDPSocket::send().

◆ isPending()

bool ost::Socket::isPending ( Pending  pend,
timeout_t  timeout = TIMEOUT_INF 
)
virtual

Get the status of pending operations.

This can be used to examine if input or output is waiting, or if an error has occured on the descriptor.

Returns
true if ready, false on timeout.
Parameters
pendready check to perform.
timeoutin milliseconds, inf. if not specified.

Reimplemented in ost::TCPStream.

Definition at line 705 of file socket.cpp.

References INVALID_SOCKET, ucommon::Socket::pending(), pendingError, pendingInput, pendingOutput, ucommon::Socket::so, timeout, and TIMEOUT_INF.

Referenced by ost::TCPStream::isPending(), readData(), readLine(), ost::TCPStream::underflow(), ost::TCPSession::waitConnection(), and writeData().

Here is the call graph for this function:

◆ isRouted()

bool ost::Socket::isRouted ( void  ) const
inline

Return if socket routing is enabled.

Returns
true if routing enabled.

Definition at line 641 of file socket.h.

◆ join() [1/2]

Error ost::Socket::join ( const IPV4Multicast ia)
inlineprotected

Definition at line 335 of file socket.h.

References ost::getaddress().

Here is the call graph for this function:

◆ join() [2/2]

Socket::Error ost::Socket::join ( const ucommon::Socket::address ia,
int  iface = 0 
)
protected

Join a multicast group.

Returns
0 (errSuccess) on success, else error code.
Parameters
iaaddress of multicast group to join.

Definition at line 488 of file socket.cpp.

References errMulticastDisabled, errNotConnected, ucommon::Socket::error(), errServiceUnavailable, errSuccess, and ucommon::Socket::join().

Referenced by ost::UDPSocket::join().

Here is the call graph for this function:

◆ operator bool()

ost::Socket::operator bool ( ) const

Definition at line 791 of file socket.cpp.

References state.

◆ operator!()

bool ost::Socket::operator! ( ) const

Operator based testing to see if a socket is currently active.

Definition at line 786 of file socket.cpp.

References INITIAL, and state.

◆ operator=()

Socket & ost::Socket::operator= ( const Socket from)

Sockets may also be duplicated by the assignment operator.

Definition at line 796 of file socket.cpp.

References dupSocket(), endSocket(), errCopyFailed, ucommon::Socket::error(), INITIAL, INVALID_SOCKET, ucommon::Socket::so, socket_errno, and state.

Here is the call graph for this function:

◆ readData()

ssize_t ost::Socket::readData ( void *  buf,
size_t  len,
char  separator = 0,
timeout_t  t = 0 
)
protectedvirtual

Read in a block of len bytes with specific separator.

Can be zero, or any other char. If \n or \r, it's treated just like a readLine(). Otherwise it looks for the separator.

Parameters
bufpointer to byte allocation.
lenmaximum length to read.
separatorseparator for a particular ASCII character
ttimeout for pending data in milliseconds.
Returns
number of bytes actually read.

Definition at line 600 of file socket.cpp.

References _IOLEN64, errInput, ucommon::Socket::error(), errTimeout, isPending(), pendingInput, readLine(), ucommon::Socket::so, ucommon::str(), and timeout.

Referenced by ost::TCPStream::underflow().

Here is the call graph for this function:

◆ readLine()

ssize_t ost::Socket::readLine ( char *  buf,
size_t  len,
timeout_t  timeout = 0 
)
protected

Process a logical input line from a socket descriptor directly.

Parameters
bufpointer to string.
lenmaximum length to read.
timeoutfor pending data in milliseconds.
Returns
number of bytes actually read.

Definition at line 543 of file socket.cpp.

References _IOLEN64, errInput, ucommon::Socket::error(), errTimeout, isPending(), pendingInput, ucommon::Socket::so, socket_errno, ucommon::str(), and timeout.

Referenced by readData().

Here is the call graph for this function:

◆ receiveBuffer()

Socket::Error ost::Socket::receiveBuffer ( unsigned  size)
protected

Set the protocol stack network kernel receive buffer size associated with the socket.

Returns
errSuccess on success, or error.
Parameters
sizeof buffer in bytes.

Definition at line 371 of file socket.cpp.

References errInvalidValue, errServiceUnavailable, errSuccess, and ucommon::Socket::so.

Referenced by bufferSize(), and ost::UDPTransmit::UDPTransmit().

◆ receiveLimit()

Socket::Error ost::Socket::receiveLimit ( int  limit = 1)
protected

Set thr receive limit.

Definition at line 303 of file socket.cpp.

References errInvalidValue, errServiceUnavailable, errSuccess, ucommon::limit(), and ucommon::Socket::so.

Here is the call graph for this function:

◆ receiveTimeout()

Socket::Error ost::Socket::receiveTimeout ( timeout_t  timer)
protected

Receive timeout for receiving raw network data.

Returns
errSuccess if set.
Parameters
timervalue in milliseconds.

Definition at line 334 of file socket.cpp.

References errInvalidValue, errServiceUnavailable, errSuccess, and ucommon::Socket::so.

◆ sendBuffer()

Socket::Error ost::Socket::sendBuffer ( unsigned  size)
protected

Set the protocol stack network kernel send buffer size associated with the socket.

Returns
errSuccess on success, or error.
Parameters
sizeof buffer in bytes.

Definition at line 351 of file socket.cpp.

References errInvalidValue, errServiceUnavailable, errSuccess, and ucommon::Socket::so.

Referenced by bufferSize(), and ost::UDPReceive::UDPReceive().

◆ sendLimit()

Socket::Error ost::Socket::sendLimit ( int  limit = 2048)
protected

Set the send limit.

Definition at line 290 of file socket.cpp.

References errInvalidValue, errServiceUnavailable, errSuccess, ucommon::limit(), and ucommon::Socket::so.

Referenced by ost::TCPStream::segmentBuffering().

Here is the call graph for this function:

◆ sendTimeout()

Socket::Error ost::Socket::sendTimeout ( timeout_t  timer)
protected

Set the send timeout for sending raw network data.

Returns
errSuccess if set.
Parameters
timervalue in millisec.

Definition at line 316 of file socket.cpp.

References errInvalidValue, errServiceUnavailable, errSuccess, and ucommon::Socket::so.

◆ setBroadcast()

Socket::Error ost::Socket::setBroadcast ( bool  enable)
protected

Set the subnet broadcast flag for the socket.

This enables sending to a subnet and may require special image privileges depending on the operating system.

Returns
0 (errSuccess) on success, else error code.
Parameters
enablewhen set to true.

Definition at line 382 of file socket.cpp.

References errBroadcastDenied, ucommon::Socket::error(), errSuccess, flags, ucommon::Socket::so, and socket_errno.

Here is the call graph for this function:

◆ setCompletion()

void ost::Socket::setCompletion ( bool  immediate)

Used to specify blocking mode for the socket.

A socket can be made non-blocking by setting setCompletion(false) or set to block on all access with setCompletion(true). I do not believe this form of non-blocking socket I/O is supported in winsock, though it provides an alternate asynchronous set of socket services.

Parameters
immediatemode specify socket I/O call blocking mode.

Definition at line 1002 of file socket.cpp.

References flags, O_NONBLOCK, and ucommon::Socket::so.

Referenced by ost::DCCPSocket::connect(), ost::TCPStream::connect(), and ost::TCPSession::TCPSession().

◆ setError()

void ost::Socket::setError ( bool  enable)
inlineprotected

This service is used to turn the error handler on or off for "throwing" exceptions by manipulating the thrown flag.

Parameters
enabletrue to enable handler.

Definition at line 215 of file socket.h.

Referenced by ost::TCPSession::TCPSession(), and ost::TCPStream::TCPStream().

◆ setKeepAlive()

Socket::Error ost::Socket::setKeepAlive ( bool  enable)

Set the keep-alive status of this socket and if keep-alive messages will be sent.

Returns
0 on success.
Parameters
enablekeep alive messages.

Definition at line 1035 of file socket.cpp.

References errKeepaliveDenied, ucommon::Socket::error(), errSuccess, flags, ucommon::Socket::so, and socket_errno.

Here is the call graph for this function:

◆ setLinger()

Socket::Error ost::Socket::setLinger ( bool  linger)

Enable lingering sockets on close.

Parameters
lingerspecify linger enable.

Definition at line 1047 of file socket.cpp.

References ucommon::Socket::error(), errServiceUnavailable, errSuccess, flags, and linger.

Here is the call graph for this function:

◆ setLoopbackByFamily()

Socket::Error ost::Socket::setLoopbackByFamily ( bool  enable,
Family  family = IPV4 
)
protected

Set the multicast loopback flag for the socket.

Loopback enables a socket to hear what it is sending.

Returns
0 (errSuccess) on success, else error code.
Parameters
enablewhen set to true.
familyof protocol.

Definition at line 459 of file socket.cpp.

References errMulticastDisabled, ucommon::Socket::error(), errServiceUnavailable, errSuccess, ucommon::Socket::family(), flags, IPV4, and ucommon::Socket::so.

Here is the call graph for this function:

◆ setMulticastByFamily()

Socket::Error ost::Socket::setMulticastByFamily ( bool  enable,
Family  family = IPV4 
)
protected

Setting multicast binds the multicast interface used for the socket to the interface the socket itself has been implicitly bound to.

It is also used as a check flag to make sure multicast is enabled before multicast operations are used.

Returns
0 (errSuccess) on success, else error code.
Parameters
enablewhen set to true.
familyof protocol.

Definition at line 392 of file socket.cpp.

References ucommon::addr(), ucommon::Socket::error(), errServiceUnavailable, errSuccess, ucommon::Socket::family(), flags, IPV4, ucommon::Socket::len(), and ucommon::Socket::so.

Here is the call graph for this function:

◆ setNoDelay()

Socket::Error ost::Socket::setNoDelay ( bool  enable)
protected

Enable/disable delaying packets (Nagle algorithm)

Returns
0 on success.
Parameters
enabledisable Nagle algorithm when set to true.

Definition at line 531 of file socket.cpp.

References errNoDelay, ucommon::Socket::error(), errSuccess, ucommon::Socket::so, and socket_errno.

Here is the call graph for this function:

◆ setRouting()

Socket::Error ost::Socket::setRouting ( bool  enable)
protected

Set the socket routing to indicate if outgoing messages should bypass normal routing (set false).

Returns
0 on success.
Parameters
enablenormal routing when set to true.

Definition at line 518 of file socket.cpp.

References ucommon::Socket::error(), errRoutingDenied, errSuccess, flags, ucommon::Socket::so, and socket_errno.

Here is the call graph for this function:

◆ setSocket()

void ost::Socket::setSocket ( void  )
private

Definition at line 119 of file socket.cpp.

References errid, errstr, errSuccess, flags, INITIAL, INVALID_SOCKET, ucommon::Socket::so, state, and syserr.

Referenced by Socket().

◆ setTimeToLiveByFamily()

Socket::Error ost::Socket::setTimeToLiveByFamily ( uint8_t  ttl,
Family  fam = IPV4 
)
protected

Set the multicast time to live for a multicast socket.

Returns
0 (errSuccess) on success, else error code.
Parameters
ttltime to live.
famfamily of protocol.

Definition at line 436 of file socket.cpp.

References errMulticastDisabled, ucommon::Socket::error(), errServiceUnavailable, errSuccess, flags, IPV4, ucommon::Socket::so, and ttl.

Here is the call graph for this function:

◆ setTypeOfService()

Socket::Error ost::Socket::setTypeOfService ( Tos  service)

Set packet scheduling on platforms which support ip quality of service conventions.

This effects how packets in the queue are scheduled through the interface.

Returns
0 on success, error code on failure.
Parameters
servicetype of service enumerated type.

Definition at line 1057 of file socket.cpp.

References ucommon::Socket::error(), errServiceDenied, errServiceUnavailable, errSuccess, IPTOS_LOWDELAY, IPTOS_MINCOST, IPTOS_RELIABILITY, IPTOS_THROUGHPUT, ucommon::Socket::so, socket_errno, ucommon::Socket::tos(), tosLowDelay, tosMinCost, tosReliability, and tosThroughput.

Here is the call graph for this function:

◆ writeData()

ssize_t ost::Socket::writeData ( const void *  buf,
size_t  len,
timeout_t  t = 0 
)
protectedvirtual

Write a block of len bytes to socket.

Parameters
bufpointer to byte allocation.
lenmaximum length to write.
ttimeout for pending data in milliseconds.
Returns
number of bytes actually written.

Definition at line 664 of file socket.cpp.

References _IOLEN64, ucommon::Socket::error(), errOutput, isPending(), MSG_NOSIGNAL, pendingOutput, ucommon::Socket::so, and timeout.

Referenced by ost::TCPStream::overflow(), and ost::TCPStream::printf().

Here is the call graph for this function:

Member Data Documentation

◆ broadcast

bool ost::Socket::broadcast

Definition at line 177 of file socket.h.

◆ completion

bool ost::Socket::completion

Definition at line 182 of file socket.h.

◆ errid

Error ost::Socket::errid
mutableprivate

Definition at line 166 of file socket.h.

Referenced by error(), getSystemErrorString(), and setSocket().

◆ errstr

const char* ost::Socket::errstr
mutableprivate

Definition at line 167 of file socket.h.

Referenced by error(), getSystemErrorString(), and setSocket().

◆ 

◆ keepalive

bool ost::Socket::keepalive

Definition at line 179 of file socket.h.

◆ linger

bool ost::Socket::linger

Definition at line 183 of file socket.h.

Referenced by endSocket(), and setLinger().

◆ loopback

bool ost::Socket::loopback

Definition at line 180 of file socket.h.

◆ multicast

bool ost::Socket::multicast

Definition at line 181 of file socket.h.

◆ route

bool ost::Socket::route

Definition at line 178 of file socket.h.

◆ state

◆ syserr

long ost::Socket::syserr
mutableprivate

Definition at line 168 of file socket.h.

Referenced by error(), getSystemErrorString(), and setSocket().

◆ thrown

bool ost::Socket::thrown

Definition at line 176 of file socket.h.

◆ ttl

unsigned ost::Socket::ttl

Definition at line 184 of file socket.h.

Referenced by setTimeToLiveByFamily().


The documentation for this class was generated from the following files: