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..
![]() ![]() |
UDP sockets implement the TCP SOCK_DGRAM UDP protocol. More...
#include <udp.h>
Public Member Functions | |
UDPSocket (Family family=IPV4) | |
Create an unbound UDP socket, mostly for internal use. More... | |
UDPSocket (const char *name, Family family=IPV4) | |
Create a UDP socket bound by a service name. More... | |
UDPSocket (const ucommon::Socket::address &bind) | |
Create a UDP socket and bind it to a specific interface and port address so that other UDP sockets on remote machines (or the same host) may find and send UDP messages to it. More... | |
UDPSocket (const IPV4Address &bind, tpport_t port) | |
virtual | ~UDPSocket () |
Destroy a UDP socket as a socket. More... | |
Error | setLoopback (bool enable) |
Set the loopback. More... | |
Error | setMulticast (bool enable) |
Set the multicast. More... | |
Error | setTimeToLive (char ttl) |
Set time to live. More... | |
void | setPeer (const ucommon::Socket::address &host) |
set the peer address to send message packets to. More... | |
void | connect (const ucommon::Socket::address &host) |
void | setPeer (const IPV4Host &host, tpport_t port) |
void | connect (const IPV4Host &host, tpport_t port) |
Socket::Error | getInterfaceIndex (const char *ethX, int &InterfaceIndex) |
get the interface index for a named network device More... | |
Socket::Error | join (const ucommon::Socket::address &ia, int InterfaceIndex=0) |
join a multicast group on a particular interface More... | |
Socket::Error | join (const IPV4Multicast &ia, int InterfaceIndex) |
ssize_t | send (const void *buf, size_t len) |
Send a message packet to a peer host. More... | |
ssize_t | receive (void *buf, size_t len, bool reply=false) |
Receive a message from any host. More... | |
ucommon::Socket::address | getPeer () |
Examine address of sender of next waiting packet. More... | |
IPV4Host | getIPV4Peer (tpport_t *port=NULL) |
IPV4Host | getPeer (tpport_t *port) |
ssize_t | peek (void *buf, size_t len) |
Examine contents of next waiting packet. More... | |
void | setPeer (const char *service) |
Associate socket with a named connection. More... | |
void | connect (const char *service) |
Error | disconnect (void) |
Disassociate this socket from any host connection. More... | |
![]() | |
~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 | |
Socket & | operator= (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 |
Protected Attributes | |
Socket::address | peer |
Family | family |
![]() | |
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 |
![]() | |
socket_t | so |
int | ioerr |
timeout_t | iowait |
Private Member Functions | |
Error | setKeepAlive (bool enable) |
__DELETE_COPY (UDPSocket) | |
Additional Inherited Members | |
![]() | |
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 |
![]() | |
static bool | check (Family fam) |
See if a specific protocol family is available in the current runtime environment. More... | |
![]() | |
typedef struct hostaddr_internet | host_t |
typedef cidr | cidr_t |
![]() | |
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... | |
![]() | |
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... | |
Socket & | operator= (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 socket_t | dupSocket (socket_t s, Socket::State state) |
![]() | |
static struct addrinfo * | query (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 addrinfo * | hinting (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... | |
UDP sockets implement the TCP SOCK_DGRAM UDP protocol.
They can be used to pass unverified messages between hosts, or to broadcast a specific message to an entire subnet. Please note that Streaming of realtime data commonly use UDPDuplex related classes rather than UDPSocket.
In addition to connected TCP sessions, Common C++ supports UDP sockets and these also cover a range of functionality. Like a TCPSocket, A UDPSocket can be created bound to a specific network interface and/or port address, though this is not required. UDP sockets also are usually either connected or otherwise "associated" with a specific "peer" UDP socket. Since UDP sockets operate through discreet packets, there are no streaming operators used with UDP sockets.
In addition to the UDP "socket" class, there is a "UDPBroadcast" class. The UDPBroadcast is a socket that is set to send messages to a subnet as a whole rather than to an individual peer socket that it may be associated with.
UDP sockets are often used for building "realtime" media streaming protocols and full duplex messaging services. When used in this manner, typically a pair of UDP sockets are used together; one socket is used to send and the other to receive data with an associated pair of UDP sockets on a "peer" host. This concept is represented through the Common C++ UDPDuplex object, which is a pair of sockets that communicate with another UDPDuplex pair.
Unreliable Datagram Protocol sockets.
Create an unbound UDP socket, mostly for internal use.
Definition at line 204 of file udp.cpp.
References family, peer, and ucommon::Socket::address::setAny().
Create a UDP socket bound by a service name.
Definition at line 163 of file udp.cpp.
References ucommon::addr(), ost::Socket::BOUND, ost::Socket::endSocket(), ost::Socket::errBindingFailed, ucommon::Socket::error(), family, ost::Socket::IPV4, peer, ucommon::Socket::address::setAny(), ucommon::Socket::so, and ost::Socket::state.
ost::UDPSocket::UDPSocket | ( | const ucommon::Socket::address & | bind | ) |
Create a UDP socket and bind it to a specific interface and port address so that other UDP sockets on remote machines (or the same host) may find and send UDP messages to it.
On failure to bind, an exception is thrown.
bind | address to bind this socket to. |
port | number to bind this socket to. |
Definition at line 211 of file udp.cpp.
References ost::Socket::BOUND, ost::Socket::endSocket(), ost::Socket::errBindingFailed, ucommon::Socket::error(), family, ucommon::Socket::address::family(), ucommon::Socket::address::getLength(), ost::Socket::IPV4, peer, ucommon::Socket::so, socket_errno, and ost::Socket::state.
ost::UDPSocket::UDPSocket | ( | const IPV4Address & | bind, |
tpport_t | port | ||
) |
Definition at line 228 of file udp.cpp.
References ost::Socket::BOUND, ost::Socket::endSocket(), ost::Socket::errBindingFailed, ucommon::Socket::error(), peer, ucommon::Socket::so, socket_errno, and ost::Socket::state.
|
virtual |
Destroy a UDP socket as a socket.
Definition at line 260 of file udp.cpp.
References ost::Socket::endSocket().
|
private |
void ost::UDPSocket::connect | ( | const char * | service | ) |
Definition at line 443 of file udp.cpp.
References connect(), ost::Socket::CONNECTED, ucommon::Socket::address::getLength(), INVALID_SOCKET, peer, setPeer(), ucommon::Socket::so, and ost::Socket::state.
Definition at line 406 of file udp.cpp.
References connect(), ost::Socket::CONNECTED, ucommon::Socket::address::get(), INVALID_SOCKET, peer, port, setPeer(), ucommon::Socket::so, and ost::Socket::state.
void ost::UDPSocket::connect | ( | const ucommon::Socket::address & | host | ) |
Definition at line 391 of file udp.cpp.
References connect(), ost::Socket::CONNECTED, ucommon::Socket::address::get(), ucommon::Socket::address::getLength(), INVALID_SOCKET, peer, ucommon::Socket::so, and ost::Socket::state.
Referenced by connect(), and disconnect().
Socket::Error ost::UDPSocket::disconnect | ( | void | ) |
Disassociate this socket from any host connection.
No data should be read or written until a connection is established.
Definition at line 376 of file udp.cpp.
References ost::Socket::BOUND, connect(), ost::Socket::errSuccess, ost::Socket::getLocal(), INVALID_SOCKET, ucommon::Socket::so, and ost::Socket::state.
Referenced by ost::UDPDuplex::connect(), ost::UDPDuplex::disconnect(), and ost::UDPTransmit::UDPTransmit().
Socket::Error ost::UDPSocket::getInterfaceIndex | ( | const char * | ethX, |
int & | InterfaceIndex | ||
) |
get the interface index for a named network device
ethX | is device name, like "eth0" or "eth1" |
InterfaceIndex | is the index value returned by os |
Definition at line 317 of file udp.cpp.
References ucommon::Socket::error(), ost::Socket::errServiceUnavailable, ost::Socket::errSuccess, ucommon::Socket::address::get(), peer, and ucommon::Socket::so.
Definition at line 464 of file udp.cpp.
References ucommon::addr(), getPeer(), ucommon::Socket::address::getPort(), ucommon::Socket::address::ipv4(), peer, port, and ucommon::Socket::address::setAny().
ucommon::Socket::address ost::UDPSocket::getPeer | ( | ) |
Examine address of sender of next waiting packet.
This also sets "peer" address to the sender so that the next "send" message acts as a "reply". This additional behavior overides the standard socket getSender behavior.
port | pointer to hold port number. |
Definition at line 457 of file udp.cpp.
References ucommon::addr(), ost::Socket::getPeer(), and setPeer().
Referenced by getIPV4Peer().
Socket::Error ost::UDPSocket::join | ( | const IPV4Multicast & | ia, |
int | InterfaceIndex | ||
) |
Definition at line 304 of file udp.cpp.
References ost::Socket::getaddress(), and join().
Socket::Error ost::UDPSocket::join | ( | const ucommon::Socket::address & | ia, |
int | InterfaceIndex = 0 |
||
) |
join a multicast group on a particular interface
ia | is the multicast address to use |
InterfaceIndex | is the index value returned by getInterfaceIndex |
Definition at line 311 of file udp.cpp.
References ost::Socket::join().
Referenced by join().
|
inline |
ssize_t ost::UDPSocket::receive | ( | void * | buf, |
size_t | len, | ||
bool | reply = false |
||
) |
Receive a message from any host.
buf | pointer to packet buffer to receive. |
len | of packet buffer to receive. |
reply | save sender address for reply if true. |
Definition at line 277 of file udp.cpp.
References _IOLEN64, _IORET64, ucommon::addr(), ucommon::Socket::address::getLength(), ost::Socket::isConnected(), ucommon::Socket::len(), peer, ucommon::Socket::recvfrom(), and ucommon::Socket::so.
ssize_t ost::UDPSocket::send | ( | const void * | buf, |
size_t | len | ||
) |
Send a message packet to a peer host.
buf | pointer to packet buffer to send. |
len | of packet buffer to send. |
Definition at line 265 of file udp.cpp.
References _IOLEN64, ucommon::addr(), ucommon::Socket::address::getLength(), ost::Socket::isConnected(), ucommon::Socket::len(), MSG_NOSIGNAL, peer, and ucommon::Socket::so.
|
inlineprivate |
|
inline |
|
inline |
void ost::UDPSocket::setPeer | ( | const char * | service | ) |
Associate socket with a named connection.
Definition at line 436 of file udp.cpp.
References ucommon::freeaddrinfo(), peer, and ucommon::Socket::query().
Definition at line 401 of file udp.cpp.
References ost::IPV4Address::getAddress(), peer, and port.
void ost::UDPSocket::setPeer | ( | const ucommon::Socket::address & | host | ) |
set the peer address to send message packets to.
This can be set before every send() call if nessisary.
host | address to send packets to. |
port | number to deliver packets to. |
Definition at line 386 of file udp.cpp.
References peer.
Referenced by connect(), ost::UDPReceive::connect(), and getPeer().
|
inline |
|
protected |
Definition at line 110 of file udp.h.
Referenced by UDPSocket().
|
protected |
Definition at line 108 of file udp.h.
Referenced by connect(), ost::UDPTransmit::connect(), getInterfaceIndex(), getIPV4Peer(), receive(), send(), ost::UDPBroadcast::setPeer(), setPeer(), and UDPSocket().