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..
![]() ![]() |
#include <socket.h>
Classes | |
class | address |
Public Types | |
typedef struct hostaddr_internet | host_t |
typedef cidr | cidr_t |
Public Member Functions | |
Socket () | |
Socket (const Socket &existing) | |
Socket (socket_t socket) | |
Socket (const struct addrinfo *address) | |
Socket (int family, int type, int protocol=0) | |
Socket (const char *address, const char *port, int family=AF_UNSPEC, int type=0, int protocol=0) | |
virtual | ~Socket () |
void | cancel (void) |
void | release (void) |
int | err (void) const |
bool | is_pending (unsigned value) |
bool | connected (void) const |
bool | wait (timeout_t timeout=0) const |
int | nodelay (void) const |
bool | waitSending (timeout_t timeout=0) const |
unsigned | pending (void) const |
int | broadcast (bool enable) |
int | keepalive (bool enable) |
int | blocking (bool enable) |
int | multicast (unsigned ttl=1) |
int | loopback (bool enable) |
int | getError (void) const |
int | ttl (uint8_t time) |
int | sendsize (unsigned size) |
int | sendwait (unsigned size) |
int | recvsize (unsigned size) |
int | type (void) const |
unsigned | segsize (unsigned size) |
bool | ccid (uint8_t id) |
int | tos (int type) |
int | priority (int scheduling) |
void | shutdown (void) |
int | connectto (struct addrinfo *list) |
int | disconnect (void) |
int | join (const struct addrinfo *list, const int ifindex=0) |
int | drop (const struct addrinfo *list, const int ifindex=0) |
int | wait (timeout_t timeout=Timer::inf) |
size_t | peek (void *data, size_t number) const |
size_t | readfrom (void *data, size_t number, struct sockaddr_storage *address=NULL) |
size_t | writeto (const void *data, size_t number, const struct sockaddr *address=NULL) |
size_t | readline (char *data, size_t size) |
size_t | printf (const char *format,...) __PRINTF(2 |
size_t size_t | readline (String &buffer) |
stringref_t | readline (size_t maxsize) |
static ssize_t size_t | writes (const char *string) |
operator bool () const | |
bool | operator! () const |
Socket & | operator= (socket_t socket) |
operator socket_t () const | |
socket_t | operator* () const |
Static Public Member Functions | |
static struct addrinfo * | query (const char *host, const char *service, int type=SOCK_STREAM, int protocol=0) |
static void | release (struct addrinfo *list) |
static void | cancel (socket_t socket) |
static bool | wait (socket_t socket, timeout_t timeout=0) |
static int | type (const socket_t socket) |
static unsigned | segsize (socket_t socket, unsigned size=0) |
static bool | ccid (socket_t socket, uint8_t id) |
static ssize_t | readline (socket_t socket, char *data, size_t size, timeout_t timeout=Timer::inf) |
static ssize_t | printf (socket_t socket, const char *format,...) __PRINTF(2 |
static unsigned | pending (socket_t socket) |
static int | sendsize (socket_t socket, unsigned size) |
static int | sendwait (socket_t socket, unsigned size) |
static int | recvsize (socket_t socket, unsigned size) |
static int | connectto (socket_t socket, struct addrinfo *list) |
static int | disconnect (socket_t socket) |
static int | drop (socket_t socket, const struct addrinfo *list, const int ifindex=0) |
static int | join (socket_t socket, const struct addrinfo *list, const int ifindex=0) |
static int | error (const socket_t socket) |
static int | multicast (socket_t socket, unsigned ttl=1) |
static int | loopback (socket_t socket, bool enable) |
static int | blocking (socket_t socket, bool enable) |
static int | keepalive (socket_t socket, bool enable) |
static int | broadcast (socket_t socket, bool enable) |
static int | nodelay (socket_t socket) |
static int | priority (socket_t socket, int scheduling) |
static int | tos (socket_t socket, int type) |
static int | ttl (socket_t socket, uint8_t time) |
static int | family (socket_t socket) |
static int | family (const struct sockaddr_storage &address) |
static int | family (const struct sockaddr_internet &address) |
static ssize_t | recvfrom (socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_storage *address=NULL) |
static ssize_t | sendto (socket_t socket, const void *buffer, size_t size, int flags=0, const struct sockaddr *address=NULL) |
static ssize_t | replyto (socket_t socket, const void *buffer, size_t size, int flags, const struct sockaddr_storage *address) |
static int | bindto (socket_t socket, const char *address, const char *service, int protocol=0) |
static int | listento (socket_t socket, const struct sockaddr *address, int backlog=5) |
static int | bindto (socket_t socket, const struct sockaddr *address) |
static socket_t | acceptfrom (socket_t socket, struct sockaddr_storage *address=NULL) |
static socket_t | create (int family, int type, int protocol) |
static socket_t | create (const struct addrinfo *address, int type, int protocol) |
static socket_t | create (const char *iface, const char *service, int family=AF_UNSPEC, int type=0, int protocol=0) |
static socket_t | create (const Socket::address &address) |
static void | release (socket_t socket) |
static char * | hostname (const struct sockaddr *address, char *buffer, size_t size) |
static struct addrinfo * | hinting (socket_t socket, struct addrinfo *hint) |
static socklen_t | query (socket_t socket, struct sockaddr_storage *address, const char *hostname, const char *service) |
static socklen_t | len (const struct sockaddr *address) |
static bool | equal (const struct sockaddr *address1, const struct sockaddr *address2) |
static unsigned | copy (struct sockaddr *target, const struct sockaddr *origin) |
static unsigned | store (struct sockaddr_storage *storage, const struct sockaddr *address) |
static unsigned | store (struct sockaddr_internet *storage, const struct sockaddr *address) |
static bool | eq_host (const struct sockaddr *address1, const struct sockaddr *address2) |
static bool | eq_from (const struct sockaddr_storage *address1, const struct sockaddr_storage *address2) |
static bool | eq_inet (const struct sockaddr_internet *address1, const struct sockaddr_internet *address2) |
static bool | eq_subnet (const struct sockaddr *address1, const struct sockaddr *address2) |
static int | via (struct sockaddr *address, const struct sockaddr *target, socklen_t size=0) |
static char * | query (const struct sockaddr *address, char *buffer, socklen_t size) |
static in_port_t | port (const struct sockaddr *address) |
static in_port_t | port (const struct sockaddr_internet *address) |
static unsigned | keyindex (const struct sockaddr *address, unsigned size) |
static unsigned | keyhost (const struct sockaddr *address, unsigned size) |
static void | init (void) |
static void | query (int family) |
static void | v4mapping (bool enable) |
static int | error (void) |
static bool | is_null (const char *string) |
static bool | is_numeric (const char *string) |
static int | local (socket_t socket, struct sockaddr_storage *address) |
static int | remote (socket_t socket, struct sockaddr_storage *address) |
Protected Attributes | |
socket_t | so |
int | ioerr |
timeout_t | iowait |
Friends | |
class | address |
A generic socket base class. This class can be used directly or as a base class for building network protocol stacks. This common base tries to handle UDP and TCP sockets, as well as support multicast, IPV4/IPV6 addressing, and additional addressing domains (such as Unix domain sockets).
typedef cidr ucommon::Socket::cidr_t |
typedef struct hostaddr_internet ucommon::Socket::host_t |
ucommon::Socket::Socket | ( | ) |
Create a socket object for use.
Definition at line 1588 of file socket.cpp.
References ucommon::Timer::inf, INVALID_SOCKET, ioerr, iowait, and so.
ucommon::Socket::Socket | ( | const Socket & | existing | ) |
Create socket as duped handle of existing socket.
existing | socket to dup. |
Definition at line 1570 of file socket.cpp.
References ucommon::dup(), init(), INVALID_SOCKET, ioerr, iowait, and so.
ucommon::Socket::Socket | ( | socket_t | socket | ) |
Create socket from existing socket descriptor.
socket | descriptor to use. |
Definition at line 1595 of file socket.cpp.
References ucommon::Timer::inf, ioerr, iowait, and so.
ucommon::Socket::Socket | ( | const struct addrinfo * | address | ) |
Create and connect a socket to an address from an address list. The type of socket created is based on the type we are connecting to.
address | list to connect with. |
Definition at line 1602 of file socket.cpp.
References ucommon::addr(), ucommon::Timer::inf, init(), INVALID_SOCKET, ioerr, iowait, so, and ucommon::socket_mapping().
ucommon::Socket::Socket | ( | int | family, |
int | type, | ||
int | protocol = 0 |
||
) |
Create an unbound socket of a specific type.
family | of our new socket. |
type | (stream, udp, etc) of our new socket. |
protocol | number of our new socket.' |
Definition at line 1623 of file socket.cpp.
References create(), family(), ucommon::Timer::inf, ioerr, iowait, so, and type().
ucommon::Socket::Socket | ( | const char * | address, |
const char * | port, | ||
int | family = AF_UNSPEC , |
||
int | type = 0 , |
||
int | protocol = 0 |
||
) |
Create a bound socket. If one wishes to listen for connections on a protocol, then ListenSocket should be used instead.
address | to bind or "*" for all. |
port | number of service to bind. |
family | to bind as. |
type | of socket to bind (stream, udp, etc). |
protocol | of socket to bind. |
Definition at line 1630 of file socket.cpp.
References create(), family(), ucommon::Timer::inf, init(), ioerr, iowait, port(), ucommon::setfamily(), so, and type().
|
virtual |
Shutdown, close, and destroy socket.
Reimplemented in ost::Socket.
Definition at line 1726 of file socket.cpp.
References release().
|
static |
Accept a socket connection from a remote host.
socket | descriptor to accept from. |
address | of socket accepting. |
Definition at line 2656 of file socket.cpp.
References ucommon::addr(), len(), and so.
|
static |
Bind the socket descriptor to a known interface and service port.
socket | descriptor to bind. |
address | to bind to or "*" for all. |
service | port to bind. |
protocol | to use or 0 if default. |
Definition at line 2997 of file socket.cpp.
References addrinfo::ai_addr, addrinfo::ai_addrlen, addrinfo::ai_family, addrinfo::ai_flags, AI_NUMERICHOST, AI_PASSIVE, addrinfo::ai_protocol, caddr_t, error(), ucommon::freeaddrinfo(), ucommon::getaddrinfo(), hinting(), INVALID_SOCKET, len(), so, and ucommon::v6only.
|
static |
Bind the socket descriptor to a known interface.
socket | descriptor to bind. |
address | of interface to bind to. |
Definition at line 2981 of file socket.cpp.
|
inline |
|
static |
Set socket blocking I/O mode of socket descriptor.
socket | descriptor. |
enable | true for blocking I/O. |
Definition at line 2308 of file socket.cpp.
References err(), error(), INVALID_SOCKET, O_NONBLOCK, and so.
|
inline |
|
static |
Set socket for unicast mode broadcasts on socket descriptor.
socket | descriptor. |
enable | broadcasting if true. |
Definition at line 2164 of file socket.cpp.
References err(), error(), INVALID_SOCKET, and so.
|
static |
Cancel pending i/o by shutting down the socket.
socket | to shutdown. |
Definition at line 1748 of file socket.cpp.
References INVALID_SOCKET, shutdown(), and so.
void ucommon::Socket::cancel | ( | void | ) |
Cancel pending i/o by shutting down the socket.
Definition at line 1742 of file socket.cpp.
References INVALID_SOCKET, shutdown(), and so.
|
static |
Set congestion control id.
socket | to modify. |
ccid | value to set. |
Definition at line 2857 of file socket.cpp.
References DCCP_SOCKOPT_AVAILABLE_CCIDS, DCCP_SOCKOPT_CCID, len(), so, and SOL_DCCP.
Referenced by ost::DCCPSocket::getRxCCID(), ost::DCCPSocket::getTxCCID(), and ost::DCCPSocket::setCCID().
|
inline |
bool ucommon::Socket::connected | ( | void | ) | const |
Test if socket is connected.
Definition at line 2607 of file socket.cpp.
References INVALID_SOCKET, MSG_DONTWAIT, so, and wait().
Referenced by ost::DCCPSocket::connect(), and ost::TCPStream::connect().
Connect socket descriptor to a remote host from an address list. For TCP (and DCCP) sockets, the entire list may be tried. For UDP, connect is only a state and the first valid entry in the list is used.
socket | descriptor. |
list | of addresses to connect to. |
Definition at line 2513 of file socket.cpp.
References addrinfo::ai_addr, addrinfo::ai_addrlen, addrinfo::ai_family, addrinfo::ai_next, error(), family(), INVALID_SOCKET, and so.
int ucommon::Socket::connectto | ( | struct addrinfo * | list | ) |
Connect our socket to a remote host from an address list. For TCP (and DCCP) sockets, the entire list may be tried. For UDP, connect is only a state and the first valid entry in the list is used.
list | of addresses to connect to. |
Definition at line 2503 of file socket.cpp.
Referenced by create(), and ucommon::tcpstream::open().
|
static |
Copy a socket address.
target | address pointer to copy into. |
origin | address pointer to copy from. |
Definition at line 3296 of file socket.cpp.
References len().
Referenced by ucommon::Socket::address::address(), ucommon::Socket::address::operator=(), store(), and ucommon::Socket::address::withPort().
|
static |
Create a bound socket for a service.
iface | to bind. |
service | port to bind. |
family | to select or AF_UNSPEC |
type | of socket to create. |
protocol | of socket to create. |
Definition at line 1662 of file socket.cpp.
References addrinfo::ai_addr, addrinfo::ai_addrlen, addrinfo::ai_family, addrinfo::ai_flags, AI_NUMERICHOST, AI_PASSIVE, addrinfo::ai_protocol, addrinfo::ai_socktype, caddr_t, create(), family(), ucommon::freeaddrinfo(), ucommon::getaddrinfo(), init(), INVALID_SOCKET, len(), port(), release(), ucommon::setfamily(), so, type(), and ucommon::v6only.
|
static |
Create a connected socket for a service.
address | of service for connect. |
Definition at line 1644 of file socket.cpp.
References address, addrinfo::ai_family, addrinfo::ai_protocol, addrinfo::ai_socktype, connectto(), create(), INVALID_SOCKET, release(), and so.
Create a connected socket.
address | list to connect to. |
type | of socket to create. |
protocol | of socket. |
Definition at line 2462 of file socket.cpp.
References AF_UNSPEC, addrinfo::ai_addr, addrinfo::ai_addrlen, addrinfo::ai_family, addrinfo::ai_next, addrinfo::ai_protocol, addrinfo::ai_socktype, create(), INVALID_SOCKET, release(), and so.
|
static |
Create a socket object unbound.
family | of socket. |
type | of socket. |
protocol | of socket. |
Definition at line 1731 of file socket.cpp.
References family(), init(), so, ucommon::socket_mapping(), and type().
Referenced by create(), ucommon::ListenSocket::create(), Socket(), and ucommon::tcpstream::tcpstream().
|
static |
Disconnect a connected socket descriptor.
socket | descriptor. |
Definition at line 2333 of file socket.cpp.
References ucommon::addr(), AF_UNSPEC, err(), error(), family(), INVALID_SOCKET, len(), and so.
int ucommon::Socket::disconnect | ( | void | ) |
Disconnect a connected socket. Depending on the implementation, this might be done by connecting to AF_UNSPEC, connecting to a 0 address, or connecting to self.
Definition at line 2508 of file socket.cpp.
Referenced by ucommon::tcpstream::close(), and ucommon::tcpstream::reset().
int ucommon::Socket::drop | ( | const struct addrinfo * | list, |
const int | ifindex = 0 |
||
) |
Drop socket from multicast group.
list | of groups to drop. |
Definition at line 2284 of file socket.cpp.
References ucommon::addr(), ioerr, and so.
Referenced by ost::Socket::drop().
|
static |
Drop socket descriptor from multicast group.
socket | descriptor. |
list | of groups to drop. |
Definition at line 2412 of file socket.cpp.
References ucommon::addr(), addrinfo::ai_addr, addrinfo::ai_family, addrinfo::ai_next, error(), family(), INVALID_SOCKET, sockaddr_internet::ipv4, len(), and so.
|
inlinestatic |
|
static |
Compare socket host addresses. Test if the host address matches or if there is no service, then just the host address values.
address1 | to compare. |
address2 | to compare. |
Definition at line 3309 of file socket.cpp.
References len().
Referenced by ucommon::eq_host().
|
inlinestatic |
|
static |
See if both addresses are in the same subnet. This is only relevant to IPV4 and class domain routing.
address1 | to test. |
address2 | to test. |
Definition at line 3244 of file socket.cpp.
Referenced by ucommon::eq_subnet().
|
static |
Compare socket addresses. Test if the address and service matches or if there is no service, then just the host address values.
address1 | to compare. |
address2 | to compare. |
Definition at line 3340 of file socket.cpp.
References len().
Referenced by ucommon::eq(), ucommon::Socket::address::find(), ucommon::Socket::address::insert(), ucommon::mapped_keyequal< struct sockaddr >(), ucommon::Type::SockAddress::operator!=(), ucommon::Type::InetAddress::operator!=(), ucommon::Socket::address::operator==(), ucommon::Type::SockAddress::operator==(), ucommon::Type::InetAddress::operator==(), and ucommon::Socket::address::remove().
|
inline |
Get error code.
Definition at line 919 of file socket.h.
Referenced by blocking(), broadcast(), ost::Socket::bufferSize(), ost::UDPTransmit::connect(), disconnect(), ost::Socket::error(), keepalive(), loopback(), nodelay(), priority(), recvsize(), sendsize(), sendwait(), tos(), and ttl().
|
static |
Get socket error code of socket descriptor.
socket | descriptor. |
Definition at line 2548 of file socket.cpp.
References caddr_t, INVALID_SOCKET, and so.
|
static |
Return error code of last socket operation,
Definition at line 1849 of file socket.cpp.
Referenced by ost::TCPStream::allocate(), ost::DCCPSocket::available(), bindto(), blocking(), broadcast(), ost::Socket::connectError(), connectto(), ost::DCCPSocket::DCCPSocket(), disconnect(), ost::Socket::drop(), drop(), ost::UDPSocket::getInterfaceIndex(), ost::Socket::getLocal(), ost::Socket::getPeer(), ost::DCCPSocket::getRxCCID(), ost::Socket::getSender(), ost::DCCPSocket::getTxCCID(), ost::Socket::join(), join(), keepalive(), listento(), loopback(), multicast(), nodelay(), ost::Socket::operator=(), ost::TCPStream::overflow(), priority(), ost::Socket::readData(), readfrom(), ost::Socket::readLine(), readline(), recvsize(), sendsize(), sendwait(), ost::Socket::setBroadcast(), ost::DCCPSocket::setCCID(), ost::Socket::setKeepAlive(), ost::Socket::setLinger(), ost::Socket::setLoopbackByFamily(), ost::Socket::setMulticastByFamily(), ost::Socket::setNoDelay(), ost::Socket::setRouting(), ost::Socket::setTimeToLiveByFamily(), ost::Socket::setTypeOfService(), ost::Socket::Socket(), ost::TCPSocket::TCPSocket(), ost::TCPStream::TCPStream(), tos(), ttl(), ost::UDPSocket::UDPSocket(), ost::TCPStream::underflow(), via(), ost::Socket::writeData(), and writeto().
|
inlinestatic |
Get the address family of an internet socket address object.
address | to examine. |
Definition at line 1472 of file socket.h.
References ucommon::Socket::address::address().
|
inlinestatic |
|
static |
Get the address family of the socket descriptor.
Definition at line 3428 of file socket.cpp.
References ucommon::addr(), AF_UNSPEC, ost::info(), INVALID_SOCKET, len(), and so.
Referenced by ucommon::Socket::address::address(), ucommon::Socket::address::any(), connectto(), create(), ucommon::ListenSocket::create(), disconnect(), drop(), ucommon::Socket::address::get(), join(), ucommon::ListenSocket::ListenSocket(), ucommon::Socket::address::loopback(), loopback(), ucommon::Socket::address::modify(), query(), ucommon::Socket::address::set(), ucommon::Socket::address::setAny(), ucommon::Socket::address::setLoopback(), ost::Socket::setLoopbackByFamily(), ost::Socket::setMulticastByFamily(), Socket(), ucommon::tcpstream::tcpstream(), and ttl().
|
inline |
Create an address info lookup hint based on the family and type properties of a socket descriptor.
socket | descriptor. |
hint | buffer. |
Definition at line 2827 of file socket.cpp.
References addrinfo::ai_family, addrinfo::ai_socktype, caddr_t, and so.
|
static |
Lookup and return the host name associated with a socket address.
address | to lookup. |
buffer | to save hostname into. |
size | of buffer to save hostname into. |
Definition at line 2911 of file socket.cpp.
References ucommon::getnameinfo(), ucommon::max(), and NI_NOFQDN.
|
static |
Initialize socket subsystem.
Definition at line 531 of file socket.cpp.
Referenced by ucommon::Socket::address::address(), create(), ucommon::secure::init(), ost::MainThread::MainThread(), and Socket().
|
static |
Simple function to validate that a given IP address string is a "zero" address. Such address strings are used for example in SIP to indicate "hold" by re-inviting peers to a null address. Supports IPV4 and IPV6 addresses.
string | address to check. |
Definition at line 3455 of file socket.cpp.
References ucommon::str().
|
static |
Simple function to validate that a given IP address string is a numeric address. This can be used to verify an address is not a "host" name. Supports IPV4 and IPV6 address strings.
string | address to check. |
Definition at line 3472 of file socket.cpp.
References ucommon::str().
Referenced by query().
bool ucommon::Socket::is_pending | ( | unsigned | value | ) |
See the number of bytes in the receive queue.
value | to test for. |
Definition at line 2623 of file socket.cpp.
References pending().
int ucommon::Socket::join | ( | const struct addrinfo * | list, |
const int | ifindex = 0 |
||
) |
Join socket to multicast group.
list | of groups to join. |
Definition at line 2276 of file socket.cpp.
References ucommon::addr(), ioerr, and so.
Referenced by ucommon::Socket::address::add(), and ost::Socket::join().
|
static |
Join socket descriptor to multicast group.
socket | descriptor. |
list | of groups to join. |
Definition at line 2364 of file socket.cpp.
References ucommon::addr(), addrinfo::ai_addr, addrinfo::ai_family, addrinfo::ai_next, error(), family(), INVALID_SOCKET, sockaddr_internet::ipv4, len(), and so.
|
inline |
|
static |
Set socket for keepalive packets for socket descriptor.
socket | descriptor. |
enable | keep-alive if true. |
Definition at line 2197 of file socket.cpp.
References err(), error(), INVALID_SOCKET, and so.
|
static |
Convert a socket host address into a hash map index.
address | to convert. |
size | of map index. |
Definition at line 3057 of file socket.cpp.
References ucommon::addr(), caddr_t, and len().
|
static |
Convert a socket address and service into a hash map index.
address | to convert. |
size | of map index. |
Definition at line 3086 of file socket.cpp.
References ucommon::addr(), caddr_t, len(), and port().
|
static |
Get the size of a socket address.
address | of socket. |
Definition at line 3410 of file socket.cpp.
Referenced by ucommon::ListenSocket::accept(), acceptfrom(), bindto(), ccid(), ost::DCCPSocket::connect(), ost::TCPStream::connect(), copy(), create(), disconnect(), drop(), ucommon::Socket::address::dup(), eq_host(), equal(), family(), ost::Socket::getLocal(), ost::Socket::getPeer(), ost::Socket::getSender(), join(), keyhost(), keyindex(), listento(), loopback(), ucommon::mapped_keypath< struct sockaddr >(), multicast(), peek(), ost::TCPStream::printf(), query(), readfrom(), ost::UDPSocket::receive(), recvfrom(), ost::UDPSocket::send(), sendto(), ucommon::Socket::address::setAny(), ost::DCCPSocket::setCCID(), ost::Socket::setMulticastByFamily(), store(), ttl(), via(), ost::TCPSession::waitConnection(), and writeto().
|
static |
Bind the socket descriptor to a known interface listen on service port.
socket | descriptor to bind. |
address | of interface to bind to. |
backlog | for service. |
Definition at line 2988 of file socket.cpp.
|
static |
Get local address to which the socket is bound. This is defined here because we may re-define the backend linkage for the socks proxy in the future.
socket | descriptor to examine. |
address | storage for local address. |
Definition at line 3493 of file socket.cpp.
References ucommon::addr().
|
inline |
|
static |
Set loopback to read multicast packets socket descriptor broadcasts.
socket | descriptor. |
enable | true to loopback, false to ignore. |
Definition at line 2060 of file socket.cpp.
References ucommon::addr(), err(), error(), family(), INVALID_SOCKET, len(), and so.
|
static |
Set multicast mode and multicast broadcast range for socket descriptor.
socket | descriptor. |
ttl | to set for multicast socket or 0 to disable multicast. |
Definition at line 2214 of file socket.cpp.
References ucommon::addr(), error(), INVALID_SOCKET, len(), so, and ttl().
|
inline |
|
static |
Set tcp nodelay option on socket descriptor.
socket | descriptor. |
Definition at line 2179 of file socket.cpp.
References err(), error(), INVALID_SOCKET, and so.
|
inline |
ucommon::Socket::operator bool | ( | ) | const |
Test if socket is valid.
Definition at line 1855 of file socket.cpp.
References INVALID_SOCKET, and so.
|
inline |
bool ucommon::Socket::operator! | ( | void | ) | const |
Test if socket is invalid.
Definition at line 1862 of file socket.cpp.
References INVALID_SOCKET, and so.
|
inline |
Assign socket from a socket descriptor. Release existing socket if one present.
socket | descriptor to assign to object. |
Definition at line 1869 of file socket.cpp.
size_t ucommon::Socket::peek | ( | void * | data, |
size_t | number | ||
) | const |
Peek at data waiting in the socket receive buffer.
data | pointer to save data in. |
number | of bytes to peek. |
Definition at line 1876 of file socket.cpp.
References caddr_t, ucommon::Timer::inf, iowait, len(), MSG_DONTWAIT, so, and wait().
|
static |
Get the number of bytes pending in the receive buffer of a socket descriptor.
socket | descriptor. |
Definition at line 2643 of file socket.cpp.
References INVALID_SOCKET, and so.
|
inline |
Get the number of bytes of data in the socket receive buffer.
Definition at line 973 of file socket.h.
Referenced by is_pending(), ost::Socket::isPending(), and ost::TCPStream::isPending().
|
static |
Get the service port of a socket.
address | of socket to examine. |
Definition at line 3117 of file socket.cpp.
References ucommon::addr().
Referenced by ucommon::Socket::address::add(), ucommon::Socket::address::address(), ost::UDPTransmit::cConnect(), ost::UDPSocket::connect(), ost::DCCPSocket::connect(), ost::UDPTransmit::connect(), ost::TCPStream::connect(), ost::UDPReceive::connect(), ost::UDPDuplex::connect(), create(), ost::DCCPSocket::DCCPSocket(), ost::Socket::getIPV4Local(), ost::UDPSocket::getIPV4Peer(), ost::Socket::getIPV4Peer(), ost::DCCPSocket::getIPV4Sender(), ost::Socket::getIPV4Sender(), ucommon::Socket::address::getPort(), ucommon::Socket::address::insert(), keyindex(), ucommon::Socket::address::set(), ost::UDPSocket::setPeer(), ost::UDPBroadcast::setPeer(), ucommon::Socket::address::setPort(), Socket(), ost::TCPSession::TCPSession(), ost::TCPSocket::TCPSocket(), ost::TCPStream::TCPStream(), and ucommon::Socket::address::withPort().
|
inlinestatic |
size_t ucommon::Socket::printf | ( | const char * | format, |
... | |||
) |
Print formatted string to socket.
format | string. |
Definition at line 3382 of file socket.cpp.
References writes().
|
static |
Print formatted string to socket.
socket | to write to. |
format | string. |
Definition at line 3396 of file socket.cpp.
|
inline |
|
static |
Set packet priority of socket descriptor.
socket | descriptor. |
scheduling | priority for packet scheduling. |
Definition at line 2130 of file socket.cpp.
References err(), error(), INVALID_SOCKET, and so.
|
static |
Get an address list directly. This is used internally by some derived socket types when generic address lists would be invalid.
host | name in the form address or "address:port" |
service | id or port to use if not specified in host string. |
type | of service to get. |
protocol | of service to get. |
Definition at line 956 of file socket.cpp.
References AF_UNSPEC, addrinfo::ai_family, addrinfo::ai_flags, AI_NUMERICHOST, AI_NUMERICSERV, AI_PASSIVE, addrinfo::ai_protocol, addrinfo::ai_socktype, DEFAULT_FAMILY, family(), ucommon::getaddrinfo(), is_numeric(), result(), ucommon::String::set(), type(), and ucommon::v6only.
Referenced by ucommon::Socket::address::add(), ucommon::Socket::address::insert(), main(), ucommon::tcpstream::open(), ucommon::Socket::address::set(), and ost::UDPSocket::setPeer().
|
static |
Get the hostname of a socket address.
address | to lookup. |
buffer | to save hostname in. |
size | of hostname buffer. |
Definition at line 3133 of file socket.cpp.
References ucommon::addr(), and ucommon::String::set().
|
static |
Set default socket family preference for query options when the socket type is otherwise not specified.
family | to select. |
Definition at line 544 of file socket.cpp.
References ucommon::query_family.
|
static |
Lookup a host name and service address based on the addressing family and socket type of a socket descriptor. Store the result in a socket address structure.
socket | descriptor. |
address | that is resolved. |
hostname | to resolve. |
service | port. |
Definition at line 2952 of file socket.cpp.
References addrinfo::ai_addr, addrinfo::ai_addrlen, ucommon::freeaddrinfo(), ucommon::getaddrinfo(), hinting(), len(), and so.
size_t ucommon::Socket::readfrom | ( | void * | data, |
size_t | number, | ||
struct sockaddr_storage * | address = NULL |
||
) |
Read data from the socket receive buffer. This will be used in abi 4.
data | pointer to save data in. |
number | of bytes to read. |
address | of peer data was received from. |
Definition at line 1899 of file socket.cpp.
References caddr_t, error(), ucommon::Timer::inf, ioerr, iowait, len(), recvfrom(), result(), so, and wait().
size_t ucommon::Socket::readline | ( | char * | data, |
size_t | size | ||
) |
Read a newline of text data from the socket and save in NULL terminated string. This uses an optimized I/O method that takes advantage of socket peeking. This presumes a connected socket on a streamble protocol. Because the trailing newline is dropped, the return size may be greater than the string length. If there was no data read because of eof of data, an error has occured, or timeout without input, then 0 will be returned.
data | to save input line. |
size | of input line buffer. |
Definition at line 1959 of file socket.cpp.
References error(), ioerr, iowait, ucommon::max(), result(), and so.
Referenced by readline(), and ucommon::str().
stringref_t ucommon::Socket::readline | ( | size_t | maxsize | ) |
Definition at line 1989 of file socket.cpp.
References ucommon::stringref< R >::create(), iowait, out, readline(), result(), and so.
|
static |
Read a newline of text data from the socket and save in NULL terminated string. This uses an optimized I/O method that takes advantage of socket peeking. As such, it has to be rewritten to be used in a ssl layer socket.
socket | to read from. |
data | to save input line. |
size | of input line buffer. |
timeout | to wait for a complete input line. |
Definition at line 2004 of file socket.cpp.
References caddr_t, ucommon::max(), so, timeout, and wait().
size_t ucommon::Socket::readline | ( | String & | buffer | ) |
Read a string of input from the socket and strip trailing newline. This uses an optimized I/O method that takes advantage of socket peeking. This presumes a connected socket on a streamble protocol. Because the trailing newline is dropped, the return size may be greater than the string length. If there was no data read because of eof of data, an error has occured, or timeout without input, then 0 will be returned.
buffer | to save input line. |
Definition at line 1974 of file socket.cpp.
References ucommon::String::clear(), ucommon::String::data(), error(), ucommon::String::fix(), ioerr, iowait, readline(), result(), ucommon::String::size(), and so.
|
static |
Get data waiting in receive queue.
socket | to get from. |
buffer | to save. |
size | of data buffer to request. |
flags | for i/o operation (MSG_OOB, MSG_PEEK, etc). |
address | of source. |
Definition at line 1890 of file socket.cpp.
References ucommon::addr(), caddr_t, len(), and so.
Referenced by ucommon::tcpstream::_read(), ost::Socket::getSender(), readfrom(), and ost::UDPSocket::receive().
|
static |
|
inline |
Set the size of the socket receive buffer.
size | of recv buffer to set. |
Definition at line 1062 of file socket.h.
Referenced by ucommon::tcpstream::allocate().
|
static |
Release (close) a socket.
socket | to close. |
Definition at line 1754 of file socket.cpp.
References shutdown(), and so.
|
static |
Release an address list directly. This is used internally by some derived socket types which do not use generic address lists.
list | of addresses. |
Definition at line 948 of file socket.cpp.
References ucommon::freeaddrinfo().
void ucommon::Socket::release | ( | void | ) |
Shutdown and close the socket.
Definition at line 1764 of file socket.cpp.
References ucommon::Timer::inf, INVALID_SOCKET, ioerr, iowait, shutdown(), and so.
Referenced by ost::Socket::check(), create(), ucommon::ListenSocket::create(), ost::Socket::endSocket(), ucommon::tcpstream::open(), operator=(), ost::TCPSocket::reject(), ucommon::tcpstream::release(), and ~Socket().
|
static |
Get remote address to which the socket is connected. This is defined here because we may re-define the backend linkage for the socks proxy in the future.
socket | descriptor to examine. |
address | storage for remote address. |
Definition at line 3500 of file socket.cpp.
References ucommon::addr().
|
inlinestatic |
Send reply on socket. Used to reply to a recvfrom message.
socket | to send to. |
buffer | to send. |
size | of data buffer to send. |
flags | for i/o operation (MSG_OOB, MSG_PEEK, etc). |
address | to reply to. |
Definition at line 1507 of file socket.h.
References buffer.
|
static |
Set segment size and get MTU.
socket | to modify. |
size | of segment or zero to not set. |
Definition at line 2883 of file socket.cpp.
References IPPROTO_DCCP, so, SOCK_DCCP, and type().
|
inline |
|
static |
Set the send size of a socket descriptor.
socket | descriptor. |
size | of send buffer to set. |
Definition at line 2577 of file socket.cpp.
References caddr_t, err(), error(), INVALID_SOCKET, and so.
|
inline |
Set the size of the socket send buffer.
size | of send buffer to set. |
Definition at line 1044 of file socket.h.
Referenced by ucommon::tcpstream::allocate().
|
static |
Send data on socket.
socket | to send to. |
buffer | to send. |
size | of data buffer to send. |
flags | for i/o operation (MSG_OOB, MSG_PEEK, etc). |
address | of destination, NULL if connected. |
Definition at line 1936 of file socket.cpp.
References caddr_t, len(), MSG_NOSIGNAL, and so.
Referenced by ucommon::tcpstream::_write(), printf(), and writeto().
|
static |
Set the size to wait before sending.
socket | descriptor. |
size | of send wait buffer to set. |
Definition at line 2561 of file socket.cpp.
References caddr_t, err(), error(), INVALID_SOCKET, and so.
|
inline |
Set the size to wait before sending.
size | of send wait buffer to set. |
Definition at line 1053 of file socket.h.
Referenced by ucommon::tcpstream::allocate().
|
inline |
Shutdown the socket communication channel.
Definition at line 1140 of file socket.h.
Referenced by cancel(), ost::TCPSocket::reject(), release(), ost::UDPReceive::UDPReceive(), ost::UDPTransmit::UDPTransmit(), and via().
|
static |
Store an address into an internet address object.
storage | for address. |
address | to store. |
Definition at line 3285 of file socket.cpp.
References len().
|
static |
Store an address into an address object.
storage | for address. |
address | to store. |
Definition at line 3276 of file socket.cpp.
References copy().
Referenced by ucommon::Type::InetAddress::InetAddress(), ucommon::Type::SockAddress::operator=(), ucommon::Type::InetAddress::operator=(), and ucommon::Type::SockAddress::SockAddress().
|
inline |
Set the type of service field of outgoing packets. Some useful values include IPTOS_LOWDELAY to minimize delay for interactive traffic, IPTOS_THROUGHPUT to optimize throughput, OPTOS_RELIABILITY to optimize for reliability, and IPTOS_MINCOST for low speed use.
type | of service value. |
Definition at line 1123 of file socket.h.
Referenced by ost::Socket::setTypeOfService().
|
static |
Set type of service of socket descriptor.
socket | descriptor. |
type | of service. |
Definition at line 2146 of file socket.cpp.
References err(), error(), INVALID_SOCKET, and so.
|
static |
Set the time to live for the socket descriptor.
socket | descriptor. |
time | to live to set. |
Definition at line 2097 of file socket.cpp.
References ucommon::addr(), err(), error(), family(), INVALID_SOCKET, len(), and so.
|
inline |
Set the time to live before packets expire.
time | to live to set. |
Definition at line 1035 of file socket.h.
Referenced by multicast().
|
static |
Get the type of a socket.
socket | descriptor. |
Definition at line 2848 of file socket.cpp.
|
inline |
Get the type of a socket.
Definition at line 1093 of file socket.h.
Referenced by ucommon::Socket::address::address(), create(), ucommon::ListenSocket::create(), ucommon::ListenSocket::ListenSocket(), query(), segsize(), ucommon::Socket::address::set(), ost::Socket::Socket(), and Socket().
|
static |
Set the default socket behavior for v6-v4 mapping. This also effects v6 address lookup as to whether v4 remapped addresses can be used if no v6 address is found.
enable | true to set mapping. This is default. |
Definition at line 536 of file socket.cpp.
References ucommon::v6only.
|
static |
Get the socket address of the interface needed to reach a destination address.
address | of interface found. |
target | address. |
size | of interface, 0 used for older code |
Definition at line 3189 of file socket.cpp.
References AF_UNSPEC, error(), INVALID_SOCKET, len(), shutdown(), so, and ucommon::socket_mapping().
Test for pending input data. This function can wait up to a specified timeout for data to appear.
socket | to test. |
timeout | or 0 if none. |
Definition at line 2670 of file socket.cpp.
References ucommon::Timer::inf, INVALID_SOCKET, so, and timeout.
bool ucommon::Socket::wait | ( | timeout_t | timeout = 0 | ) | const |
Test for pending input data. This function can wait up to a specified timeout for data to appear.
timeout | or 0 if none. |
Definition at line 2665 of file socket.cpp.
Referenced by ucommon::tcpstream::_wait(), connected(), peek(), readfrom(), readline(), and ucommon::ListenSocket::wait().
int ucommon::Socket::wait | ( | timeout_t | timeout = Timer::inf | ) |
Socket i/o timer setting.
timeout | to wait, inf for blocking, 0 pure non-blocking. |
Definition at line 2292 of file socket.cpp.
References blocking(), ucommon::Timer::inf, ioerr, iowait, so, and timeout.
bool ucommon::Socket::waitSending | ( | timeout_t | timeout = 0 | ) | const |
Test for output data sent. This function can wait up to a specified timeout for data to appear sent.
timeout | or 0 if none. |
Definition at line 2725 of file socket.cpp.
References ucommon::Timer::inf, INVALID_SOCKET, so, and timeout.
size_t ucommon::Socket::writes | ( | const char * | string | ) |
Write a null terminated string to the socket. This exists because we messed up consistency with the original puts() method. In the future there will be a single puts() that has a NULL default.
string | to write. |
Definition at line 1948 of file socket.cpp.
References ucommon::str(), and writeto().
Referenced by printf().
size_t ucommon::Socket::writeto | ( | const void * | data, |
size_t | number, | ||
const struct sockaddr * | address = NULL |
||
) |
Write data to the socket send buffer. This will be used in abi 4.
data | pointer to write data from. |
number | of bytes to write. |
address | of peer to send data to if not connected. |
Definition at line 1918 of file socket.cpp.
References caddr_t, error(), ioerr, len(), MSG_NOSIGNAL, result(), sendto(), and so.
Referenced by writes().
|
friend |
Definition at line 850 of file socket.h.
Referenced by ost::UDPSocket::connect(), create(), ost::UDPSocket::join(), ost::UDPSocket::setPeer(), ost::UDPBroadcast::setPeer(), and ost::UDPSocket::UDPSocket().
|
protected |
Definition at line 331 of file socket.h.
Referenced by connectto(), disconnect(), drop(), join(), readfrom(), readline(), release(), Socket(), wait(), and writeto().
|
protected |
Definition at line 332 of file socket.h.
Referenced by peek(), readfrom(), readline(), release(), Socket(), and wait().
|
protected |
Definition at line 330 of file socket.h.
Referenced by ucommon::ListenSocket::accept(), acceptfrom(), ost::DCCPSocket::available(), bindto(), blocking(), broadcast(), cancel(), ccid(), ost::Socket::check(), ost::UDPSocket::connect(), ost::DCCPSocket::connect(), ost::UDPTransmit::connect(), ost::TCPStream::connect(), ost::UDPReceive::connect(), connected(), connectto(), create(), ucommon::ListenSocket::create(), ost::DCCPSocket::DCCPSocket(), ost::DCCPSocket::disconnect(), ost::UDPSocket::disconnect(), ost::TCPStream::disconnect(), disconnect(), drop(), ost::Socket::dupSocket(), ost::Socket::endSocket(), error(), family(), ost::UDPSocket::getInterfaceIndex(), ost::Socket::getLocal(), ost::Socket::getPeer(), ost::DCCPSocket::getRxCCID(), ost::TCPStream::getSegmentSize(), ost::Socket::getSender(), ost::DCCPSocket::getTxCCID(), hinting(), ost::Socket::isPending(), join(), keepalive(), ucommon::ListenSocket::ListenSocket(), listento(), loopback(), multicast(), nodelay(), operator bool(), operator!(), ost::Socket::operator=(), operator=(), ost::TCPStream::overflow(), peek(), pending(), ost::TCPStream::printf(), printf(), priority(), query(), ost::Socket::readData(), readfrom(), ost::Socket::readLine(), readline(), ost::UDPSocket::receive(), ost::Socket::receiveBuffer(), ost::Socket::receiveLimit(), ost::Socket::receiveTimeout(), recvfrom(), recvsize(), ost::TCPSocket::reject(), release(), ost::TCPStream::segmentBuffering(), segsize(), ost::UDPSocket::send(), ost::Socket::sendBuffer(), ost::Socket::sendLimit(), sendsize(), ost::Socket::sendTimeout(), sendto(), sendwait(), ost::Socket::setBroadcast(), ost::DCCPSocket::setCCID(), ost::Socket::setCompletion(), ost::Socket::setKeepAlive(), ost::Socket::setLoopbackByFamily(), ost::Socket::setMulticastByFamily(), ost::Socket::setNoDelay(), ost::Socket::setRouting(), ost::TCPSocket::setSegmentSize(), ost::Socket::setSocket(), ost::Socket::setTimeToLiveByFamily(), ost::Socket::setTypeOfService(), ost::Socket::Socket(), Socket(), ost::TCPSession::TCPSession(), ost::TCPSocket::TCPSocket(), tos(), ttl(), type(), ost::UDPBroadcast::UDPBroadcast(), ost::UDPReceive::UDPReceive(), ost::UDPSocket::UDPSocket(), ost::UDPTransmit::UDPTransmit(), ost::TCPStream::underflow(), via(), wait(), ost::TCPSession::waitConnection(), waitSending(), ost::Socket::writeData(), and writeto().