UCommon
|
DCCP sockets are used for stream based connected sessions between two sockets. More...
#include <dccp.h>
Inherits ost::Socket.
Public Member Functions | |
size_t | available () const |
Return number of bytes to be read. | |
void | connect (const IPV4Host &host, tpport_t port, timeout_t timeout=0) |
Create a DCCP client connection to a DCCP socket (on a remote machine). More... | |
void | connect (const IPV6Host &host, tpport_t port, timeout_t timeout=0) |
void | connect (const char *name) |
Connect to a named client. | |
DCCPSocket (const IPV4Address &bind, tpport_t port, unsigned backlog=5) | |
A DCCP "server" is created as a DCCP socket that is bound to a hardware address and port number on the local machine and that has a backlog queue to listen for remote connection requests. More... | |
DCCPSocket (const IPV6Address &bind, tpport_t port, unsigned backlog=5) | |
DCCPSocket (const char *name, Family family=IPV4, unsigned backlog=5) | |
Create a named dccp socket by service and/or interface id. More... | |
DCCPSocket (Family family=IPV4) | |
Create an unconnected ephemeral DCCP client socket. | |
DCCPSocket (DCCPSocket &server, timeout_t timeout=0) | |
Create a server session by accepting a DCCP Socket. | |
void | disconnect (void) |
Disconnect active dccp connection (client use). | |
virtual IPV4Host | getIPV4Sender (tpport_t *port=NULL) const |
virtual IPV6Host | getIPV6Sender (tpport_t *port=NULL) const |
int | getRxCCID () const |
Get RX CCID DCCP. | |
int | getTxCCID () const |
Get TX CCID DCCP. | |
bool | isPendingConnection (timeout_t timeout=ucommon::Timer::inf) |
Used to wait for pending connection requests. More... | |
virtual bool | onAccept (const IPV4Host &ia, tpport_t port) |
A method to call in a derived DCCPSocket class that is acting as a server when a connection request is being accepted. More... | |
virtual bool | onAccept (const IPV6Host &ia, tpport_t port) |
void | reject (void) |
Used to reject the next incoming connection request. | |
bool | setCCID (uint8_t ccid) |
Set CCID DCCP. | |
virtual | ~DCCPSocket () |
Use base socket handler for ending this socket. | |
![]() | |
struct in_addr | getaddress (const IPV4Address &ia) const |
struct in6_addr | getaddress (const IPV6Address &ia) const |
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... | |
IPV4Host | getIPV4Local (in_port_t *port=NULL) const |
Get the local address and port number this socket is currently bound to. More... | |
IPV4Host | getIPV4Peer (in_port_t *port=NULL) const |
virtual IPV4Host | getIPV4Sender (in_port_t *port=NULL) const |
IPV6Host | getIPV6Local (in_port_t *port=NULL) const |
IPV6Host | getIPV6Peer (in_port_t *port=NULL) const |
virtual IPV6Host | getIPV6Sender (in_port_t *port=NULL) const |
IPV4Host | getLocal (in_port_t *port) const |
ucommon::Socket::address | getLocal () const |
ucommon::Socket::address | getPeer () const |
Get the host address and port of the socket this socket is connected to. More... | |
IPV4Host | getPeer (in_port_t *port) const |
ucommon::Socket::address | getSender () const |
May be used to examine the origin of data waiting in the socket receive queue. More... | |
IPV4Host | getSender (in_port_t *port) const |
long | getSystemError (void) const |
const char * | getSystemErrorString (void) const |
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 | isConnected (void) const |
Can test to see if this socket is "connected", and hence whether a "catch" can safely call getPeer(). More... | |
virtual bool | isPending (Pending pend, timeout_t timeout=ucommon::Timer::inf) |
Get the status of pending operations. More... | |
bool | isRouted (void) const |
Return if socket routing is enabled. More... | |
operator bool () const | |
bool | operator! () const |
Operator based testing to see if a socket is currently active. | |
Socket & | operator= (const Socket &from) |
Sockets may also be duplicated by the assignment operator. | |
void | setCompletion (bool immediate) |
Used to specify blocking mode for the socket. More... | |
Error | setKeepAlive (bool enable) |
Set the keep-alive status of this socket and if keep-alive messages will be sent. More... | |
Error | setLinger (bool linger) |
Enable lingering sockets on close. More... | |
Error | setTypeOfService (Tos service) |
Set packet scheduling on platforms which support ip quality of service conventions. More... | |
Additional Inherited Members | |
![]() | |
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 } |
typedef enum Error | Error |
enum | Family { IPV6 = 1, IPV4 = 2 } |
typedef enum Family | Family |
enum | Pending { pendingInput, pendingOutput, pendingError } |
typedef enum Pending | Pending |
enum | State { INITIAL, AVAILABLE, BOUND, CONNECTED, CONNECTING, STREAM } |
typedef enum State | State |
enum | Tos { tosLowDelay = 0, tosThroughput, tosReliability, tosMinCost, tosInvalid } |
typedef enum Tos | Tos |
![]() | |
static bool | check (Family fam) |
See if a specific protocol family is available in the current runtime environment. More... | |
![]() | |
typedef cidr | cidr_t |
typedef struct hostaddr_internet | host_t |
![]() | |
Error | bufferSize (unsigned size) |
Set the total protocol stack network kernel buffer size for both send and receive together. More... | |
Error | connectError (void) const |
Used as a common handler for connection failure processing. More... | |
Error | drop (const ucommon::Socket::address &ia, int iface=0) |
Drop membership from a multicast group. More... | |
Error | drop (const IPV4Multicast &ia) |
Error | drop (const IPV6Multicast &ia, int iface=0) |
void | endSocket (void) |
Used as the default destructor for ending a socket. More... | |
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... | |
Error | join (const ucommon::Socket::address &ia, int iface=0) |
Join a multicast group. More... | |
Error | join (const IPV4Multicast &ia) |
Error | join (const IPV6Multicast &ia, int iface=0) |
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... | |
ssize_t | readLine (char *buf, size_t len, timeout_t timeout=0) |
Process a logical input line from a socket descriptor directly. More... | |
Error | receiveBuffer (unsigned size) |
Set the protocol stack network kernel receive buffer size associated with the socket. More... | |
Error | receiveLimit (int limit=1) |
Set thr receive limit. | |
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 | sendLimit (int limit=2048) |
Set the send limit. | |
Error | sendTimeout (timeout_t timer) |
Set the send timeout for sending raw network data. More... | |
Error | setBroadcast (bool enable) |
Set the subnet broadcast flag for the socket. 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... | |
Error | setLoopbackByFamily (bool enable, Family family=IPV4) |
Set the multicast loopback 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 | setNoDelay (bool enable) |
Enable/disable delaying packets (Nagle algorithm) More... | |
Error | setRouting (bool enable) |
Set the socket routing to indicate if outgoing messages should bypass normal routing (set false). More... | |
Error | setTimeToLiveByFamily (uint8_t ttl, Family fam=IPV4) |
Set the multicast time to live for a multicast socket. 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. | |
Socket (const Socket &source) | |
A socket can also be constructed from an already existing Socket object. More... | |
virtual ssize_t | writeData (const void *buf, size_t len, timeout_t t=0) |
Write a block of len bytes to socket. More... | |
![]() | |
static socket_t | dupSocket (socket_t s, Socket::State state) |
![]() | |
struct { | |
bool broadcast: 1 | |
bool completion: 1 | |
bool keepalive: 1 | |
bool linger: 1 | |
bool loopback: 1 | |
bool multicast: 1 | |
bool route: 1 | |
bool thrown: 1 | |
unsigned ttl: 8 | |
} | flags |
State volatile | state |
DCCP sockets are used for stream based connected sessions between two sockets.
Both error recovery and flow control operate transparently for a DCCP socket connection. The DCCP socket base class is used both for client connections and to bind a DCCP "server" for accepting DCCP streams.
An implicit and unique DCCPSocket object exists in Common C++ to represent a bound DCCP socket acting as a "server" for receiving connection requests. This class is not part of DCCPStream because such objects normally perform no physical I/O (read or write operations) other than to specify a listen backlog queue and perform "accept" operations for pending connections. The Common C++ DCCPSocket offers a Peek method to examine where the next pending connection is coming from, and a Reject method to flush the next request from the queue without having to create a session.
The DCCPSocket also supports a "OnAccept" method which can be called when a DCCPStream related object is created from a DCCPSocket. By creating a DCCPStream from a DCCPSocket, an accept operation automatically occurs, and the DCCPSocket can then still reject the client connection through the return status of it's OnAccept method.
ost::DCCPSocket::DCCPSocket | ( | const IPV4Address & | bind, |
tpport_t | port, | ||
unsigned | backlog = 5 |
||
) |
A DCCP "server" is created as a DCCP socket that is bound to a hardware address and port number on the local machine and that has a backlog queue to listen for remote connection requests.
If the server cannot be created, an exception is thrown.
bind | local ip address or interface to use. |
port | number to bind socket under. |
backlog | size of connection request queue. |
ost::DCCPSocket::DCCPSocket | ( | const char * | name, |
Family | family = IPV4 , |
||
unsigned | backlog = 5 |
||
) |
Create a named dccp socket by service and/or interface id.
For IPV4 we use [host:]svc or [host/]svc for the string. If we have getaddrinfo, we use that to obtain the addr to bind for.
name | of host interface and service port to bind. |
backlog | size of connection request queue. |
void ost::DCCPSocket::connect | ( | const IPV4Host & | host, |
tpport_t | port, | ||
timeout_t | timeout = 0 |
||
) |
Create a DCCP client connection to a DCCP socket (on a remote machine).
host | address of remote DCCP server. |
port | number to connect. |
|
inline |
|
virtual |
A method to call in a derived DCCPSocket class that is acting as a server when a connection request is being accepted.
The server can implement protocol specific rules to exclude the remote socket from being accepted by returning false. The Peek method can also be used for this purpose.
ia | internet host address of the client. |
port | number of the client. |