RTP Audio System
2.0.0
|
#include <tdsocket.h>
Public Types | |
enum | SocketFamily { UndefinedSocketFamily = -1, IP = 255, IPv4 = AF_INET, IPv6 = AF_INET6, Unix = AF_UNIX } |
enum | SocketType { UndefinedSocketType = -1, UDP = SOCK_DGRAM, Datagram = SOCK_DGRAM, TCP = SOCK_STREAM, Stream = SOCK_STREAM, Raw = SOCK_RAW, RDM = SOCK_RDM, SeqPacket = SOCK_SEQPACKET } |
enum | SocketProtocol { UndefinedSocketProtocol = -1, Default = 0, ICMPv4 = IPPROTO_ICMP, ICMPv6 = IPPROTO_ICMPV6, SCTP = IPPROTO_SCTP } |
enum | GetSocketAddressFlags { GLAF_HideLoopback = (1 << 0), GLAF_HideLinkLocal = (1 << 1), GLAF_HideSiteLocal = (1 << 2), GLAF_HideLocal = GLAF_HideLoopback|GLAF_HideLinkLocal|GLAF_HideSiteLocal, GLAF_HideAnycast = (1 << 3), GLAF_HideMulticast = (1 << 4), GLAF_HideBroadcast = (1 << 5), GLAF_HideReserved = (1 << 6), GLAF_Default = GLAF_HideLoopback|GLAF_HideLinkLocal|Socket::GLAF_HideSiteLocal|GLAF_HideBroadcast|GLAF_HideMulticast|GLAF_HideAnycast } |
Public Member Functions | |
Socket () | |
Socket (const integer family, const integer socketType, const integer socketProtocol=Default) | |
~Socket () | |
bool | create (const integer socketFamily=IP, const integer socketType=TCP, const integer socketProtocol=Default) |
void | close () |
void | shutdown (const cardinal shutdownLevel) |
integer | getFamily () const |
integer | getType () const |
integer | getProtocol () const |
bool | ready () const |
bool | bind (const SocketAddress &address=InternetAddress()) |
bool | bindx (const SocketAddress **addressArray=NULL, const cardinal addresses=0, const integer flags=0) |
bool | listen (const cardinal backlog=5) |
Socket * | accept (SocketAddress **address=NULL) |
bool | connect (const SocketAddress &address, const card8 trafficClass=0) |
bool | connectx (const SocketAddress **addressArray, const size_t addresses) |
integer | getLastError () |
integer | getSocketOption (const cardinal level, const cardinal optionNumber, void *optionValue, socklen_t *optionLength) |
cardinal | getSoLinger () |
bool | getSoReuseAddress () |
bool | getSoBroadcast () |
bool | getTCPNoDelay () |
bool | getBlockingMode () |
integer | setSocketOption (const cardinal level, const cardinal optionNumber, const void *optionValue, const socklen_t optionLength) |
bool | setSoLinger (const bool on, const cardinal linger) |
bool | setSoReuseAddress (const bool on) |
bool | setSoBroadcast (const bool on) |
bool | setTCPNoDelay (const bool on) |
bool | setBlockingMode (const bool on) |
card32 | getSendFlowLabel () const |
card8 | getSendTrafficClass () const |
card32 | getReceivedFlowLabel () const |
card8 | getReceivedTrafficClass () const |
ssize_t | send (const void *buffer, const size_t length, const integer flags=0, const card8 trafficClass=0x00) |
ssize_t | sendTo (const void *buffer, const size_t length, const integer flags, const SocketAddress &receiver, const card8 trafficClass=0x00) |
ssize_t | sendMsg (const struct msghdr *msg, const integer flags, const card8 trafficClass=0x00) |
ssize_t | write (const void *buffer, const size_t length) |
ssize_t | receive (void *buffer, const size_t length, integer &flags) |
ssize_t | receiveFrom (void *buffer, const size_t length, SocketAddress &sender, integer &flags) |
ssize_t | receiveMsg (struct msghdr *msg, const integer flags, const bool internalCall=false) |
ssize_t | read (void *buffer, const size_t length) |
integer | fcntl (const integer cmd, long arg) |
integer | fcntl (const integer cmd, struct flock *lock) |
integer | ioctl (const integer request, const void *argp) |
bool | getSocketAddress (SocketAddress &address) const |
bool | getPeerAddress (SocketAddress &address) const |
bool | addMulticastMembership (const SocketAddress &address, const char *interface=NULL) |
bool | dropMulticastMembership (const SocketAddress &address, const char *interface=NULL) |
bool | getMulticastLoop () |
bool | setMulticastLoop (const bool on) |
card8 | getMulticastTTL () |
bool | setMulticastTTL (const card8 ttl) |
InternetFlow | allocFlow (const InternetAddress &address, const card32 flowLabel=0, const card8 shareLevel=2) |
void | freeFlow (InternetFlow &flow) |
bool | renewFlow (InternetFlow &flow, const cardinal expires, const cardinal linger=6) |
bool | renewFlow (const cardinal expires, const cardinal linger=6) |
int | getSystemSocketDescriptor () const |
Static Public Member Functions | |
static bool | bindSocketPair (Socket &socket1, Socket &socket2, const SocketAddress &address=InternetAddress()) |
static bool | bindxSocketPair (Socket &socket1, Socket &socket2, const SocketAddress **addressArray=NULL, const cardinal addresses=0, const integer flags=0) |
static bool | getLocalAddressList (SocketAddress **&addressList, cardinal &numberOfNets, const cardinal flags=GLAF_Default) |
Static Public Attributes | |
static const cardinal | MinAutoSelectPort = 16384 |
static const cardinal | MaxAutoSelectPort = 61000 |
Private Member Functions | |
void | init () |
bool | setTypeOfService (const card8 trafficClass) |
ssize_t | recvFrom (int fd, void *buf, const size_t len, integer &flags, struct sockaddr *addr, socklen_t *addrlen) |
bool | multicastMembership (const SocketAddress &address, const char *interface, const bool add) |
void | packSocketAddressArray (const sockaddr_storage *addrArray, const size_t addrs, sockaddr *packedArray) |
Private Attributes | |
int | SocketDescriptor |
integer | Family |
integer | Type |
integer | Protocol |
card32 | SendFlow |
card32 | ReceivedFlow |
integer | LastError |
cardinal | Backlog |
sockaddr * | Destination |
Friends | |
class | TrafficShaper |
This class manages a socket. IPv6 support is automatically available, when supported by the system.
enum Socket::SocketFamily |
enum Socket::SocketType |
Socket::Socket | ( | ) |
Constructor.
Socket::Socket | ( | const integer | family, |
const integer | socketType, | ||
const integer | socketProtocol = Default |
||
) |
Constructor for a new socket. For automatic usage of IPv6 when available, set communication family to IP. Use IPv4/IPv6 only if a special protocol version is necessary! The creation success can be checked using ready() method.
family | Communication family (e.g. IP). |
socketType | Socket type (e.g. TCP, UDP). |
socketProtocol | Socket protocol (e.g. Default). |
Socket::~Socket | ( | ) |
Destructor.
Socket * Socket::accept | ( | SocketAddress ** | address = NULL | ) |
Accept a connection.
address | Reference to store SocketAddress object to with peer's address to (NULL to skip). |
bool Socket::addMulticastMembership | ( | const SocketAddress & | address, |
const char * | interface = NULL |
||
) | [inline] |
Add multicast membership.
address | Multicast address. |
interface | Interface name. |
InternetFlow Socket::allocFlow | ( | const InternetAddress & | address, |
const card32 | flowLabel = 0 , |
||
const card8 | shareLevel = 2 |
||
) |
Allocate a new flow to a given destination. A InternetFlow object is returned, the value flow.getFlowLabel() will not be 0, if the allocFlow() call was successful.
address | Address of the destination. |
flowLabel | Flowlabel; 0 for random value. |
shareLevel | Share level for flow label. |
bool Socket::bind | ( | const SocketAddress & | address = InternetAddress() | ) |
Bind socket to given address. If address is null address, then INADDR_ANY and an automatically selected port will be used.
address | Socket address. |
bool Socket::bindSocketPair | ( | Socket & | socket1, |
Socket & | socket2, | ||
const SocketAddress & | address = InternetAddress() |
||
) | [static] |
Bind a pair of sockets to a given address and port number x and x + 1. x will be a random number, if given port number is 0.
socket1 | First socket. |
socket2 | Second socket. |
address | Address (e.g ipv6-localhost:0) or NULL for Any address. |
bool Socket::bindx | ( | const SocketAddress ** | addressArray = NULL , |
const cardinal | addresses = 0 , |
||
const integer | flags = 0 |
||
) |
O * Bind socket to one or more given addresses. If no addresses are given, INADDR_ANY and an automatically selected port will be used.
addressArray | Array of socket addresses. |
addresses | Number of addresses. |
flags | Flags. |
bool Socket::bindxSocketPair | ( | Socket & | socket1, |
Socket & | socket2, | ||
const SocketAddress ** | addressArray = NULL , |
||
const cardinal | addresses = 0 , |
||
const integer | flags = 0 |
||
) | [static] |
Bind a pair of sockets to a given address and port number x and x + 1. x will be a random number, if given port number is 0. If no addresses are given, INADDR_ANY and an automatically selected port will be used.
socket1 | First socket. |
socket2 | Second socket. |
addressArray | Array of socket addresses. |
addresses | Number of addresses. |
flags | bindx() flags. |
void Socket::close | ( | ) |
Close socket.
bool Socket::connect | ( | const SocketAddress & | address, |
const card8 | trafficClass = 0 |
||
) |
Connect socket to given address. A value for traffic class is supported if the connection is an IPv6 connection; otherwise it is ignored.
address | Address. |
trafficClass | Traffic class of the connection (IPv6 only!) |
bool Socket::connectx | ( | const SocketAddress ** | addressArray, |
const size_t | addresses | ||
) |
Connect socket to destination given by list of addresses. A value for traffic class is supported if the connection is an IPv6 connection; otherwise it is ignored.
address | Address. |
trafficClass | Traffic class of the connection (IPv6 only!) |
bool Socket::create | ( | const integer | socketFamily = IP , |
const integer | socketType = TCP , |
||
const integer | socketProtocol = Default |
||
) |
Close existing socket and create new socket. For automatic usage of IPv6 when available, set communication family to IP. Use IPv4/IPv6 only if a special protocol version is necessary!
socketFamily | Communication family (e.g. IP). |
socketType | Socket type (e.g. TCP, UDP). |
socketProtocol | Socket protocol (e.g. Default). |
bool Socket::dropMulticastMembership | ( | const SocketAddress & | address, |
const char * | interface = NULL |
||
) | [inline] |
Drop multicast membership.
address | Multicast address. |
interface | Interface name. |
integer Socket::fcntl | ( | const integer | cmd, |
long | arg | ||
) | [inline] |
integer Socket::fcntl | ( | const integer | cmd, |
struct flock * | lock | ||
) | [inline] |
void Socket::freeFlow | ( | InternetFlow & | flow | ) |
Free a flow.
flow | Flow to be freed. |
bool Socket::getBlockingMode | ( | ) |
Check, if blocking mode is on.
integer Socket::getFamily | ( | ) | const [inline] |
Get socket's family.
integer Socket::getLastError | ( | ) | [inline] |
Get last error code. It will be reset to 0 after copying.
bool Socket::getLocalAddressList | ( | SocketAddress **& | addressList, |
cardinal & | numberOfNets, | ||
const cardinal | flags = GLAF_Default |
||
) | [static] |
Get list of all local addresses (IPv4 and IPv6 are currently supported). The resulting list has to be deallocated using SocketAddress::deleteAddressList().
addressList | Reference to store address list to. |
numberOfNets | Reference to store number of addresses to. |
flags | Flags. |
bool Socket::getMulticastLoop | ( | ) |
Get multicast loop mode.
Get multicast TTL.
bool Socket::getPeerAddress | ( | SocketAddress & | address | ) | const |
Get the peer's address. Note: A socket has to be connected to a peer first to get a peer address!
address | Reference to SocketAddress to write address to. |
integer Socket::getProtocol | ( | ) | const [inline] |
Get socket's protocol.
card32 Socket::getReceivedFlowLabel | ( | ) | const [inline] |
Get last received flow label.
card8 Socket::getReceivedTrafficClass | ( | ) | const [inline] |
Get last received traffic class.
card32 Socket::getSendFlowLabel | ( | ) | const [inline] |
Get flow label of the connection.
card8 Socket::getSendTrafficClass | ( | ) | const [inline] |
Get traffic class of the connection.
bool Socket::getSoBroadcast | ( | ) |
Get SO_BROADCAST option of socket.
bool Socket::getSocketAddress | ( | SocketAddress & | address | ) | const |
Get the socket's address. Note: A socket has to be bound to an address and port or connected to a peer first to let the socket have an address!
address | Reference to SocketAddress to write address to. |
integer Socket::getSocketOption | ( | const cardinal | level, |
const cardinal | optionNumber, | ||
void * | optionValue, | ||
socklen_t * | optionLength | ||
) | [inline] |
Get socket option (wrapper for getsockopt());
level | Level (e.g. SOL_SOCKET). |
optionNumber | Option (e.g. SO_REUSEADDR). |
optionValue | Memory to store option got from getsockopt(). |
optionLength | Memory with size of option memory. |
Get SO_LINGER option of socket.
bool Socket::getSoReuseAddress | ( | ) |
Get SO_REUSEADDR option of socket.
int Socket::getSystemSocketDescriptor | ( | ) | const [inline] |
bool Socket::getTCPNoDelay | ( | ) |
Get TCP_NODELAY option of socket.
integer Socket::getType | ( | ) | const [inline] |
Get socket's type.
void Socket::init | ( | ) | [private] |
integer Socket::ioctl | ( | const integer | request, |
const void * | argp | ||
) | [inline] |
bool Socket::listen | ( | const cardinal | backlog = 5 | ) |
Set socket to listen mode with given backlog (queue length for sockets waiting for acception).
backlog | Backlog. |
bool Socket::multicastMembership | ( | const SocketAddress & | address, |
const char * | interface, | ||
const bool | add | ||
) | [private] |
void Socket::packSocketAddressArray | ( | const sockaddr_storage * | addrArray, |
const size_t | addrs, | ||
sockaddr * | packedArray | ||
) | [private] |
ssize_t Socket::read | ( | void * | buffer, |
const size_t | length | ||
) | [inline] |
Wrapper for read().
buffer | Buffer to read data to. |
length | Maximum length of data to be received. |
bool Socket::ready | ( | ) | const [inline] |
Check, if socket is ready.
ssize_t Socket::receive | ( | void * | buffer, |
const size_t | length, | ||
integer & | flags | ||
) | [inline] |
Wrapper for recv().
buffer | Buffer to read data to. |
length | Maximum length of data to be received. |
flags | Flags for recvmsg(). |
ssize_t Socket::receiveFrom | ( | void * | buffer, |
const size_t | length, | ||
SocketAddress & | sender, | ||
integer & | flags | ||
) |
Wrapper for recvfrom().
buffer | Buffer to receive data to. |
length | Maximum length of data to be received. |
sender | Address to store sender's address. |
flags | Flags for recvmsg(). |
ssize_t Socket::receiveMsg | ( | struct msghdr * | msg, |
const integer | flags, | ||
const bool | internalCall = false |
||
) |
Wrapper for recvmsg().
msg | Message. |
flags | Flags for recvmsg(). |
internalCall | Internal usage only; set to false. |
ssize_t Socket::recvFrom | ( | int | fd, |
void * | buf, | ||
const size_t | len, | ||
integer & | flags, | ||
struct sockaddr * | addr, | ||
socklen_t * | addrlen | ||
) | [private] |
bool Socket::renewFlow | ( | InternetFlow & | flow, |
const cardinal | expires, | ||
const cardinal | linger = 6 |
||
) |
Renew a flow label allocation with given expires and linger (default 6) values. The expires value gives the seconds to go until the flow label expires, the linger value gives the timeout in seconds the freed flow label cannot be allocated again.
flow | Flow to be renewed. |
expires | Seconds until the flow label expires. |
linger | Linger (default 6). |
bool Socket::renewFlow | ( | const cardinal | expires, |
const cardinal | linger = 6 |
||
) |
Renew current flow's flow label allocation with given expires and linger (default 6) values.
expires | Seconds until the flow label expires. |
linger | Linger (default 6). |
ssize_t Socket::send | ( | const void * | buffer, |
const size_t | length, | ||
const integer | flags = 0 , |
||
const card8 | trafficClass = 0x00 |
||
) |
Wrapper for send(). send() will set the packet's traffic class, if trafficClass is not 0. In this case, the packet will be sent by sendto() to the destination address, the socket is connected to!
buffer | Buffer with data to send. |
length | Length of data to send. |
flags | Flags for sendto(). |
trafficClass | Traffic class for packet. |
ssize_t Socket::sendMsg | ( | const struct msghdr * | msg, |
const integer | flags, | ||
const card8 | trafficClass = 0x00 |
||
) |
Wrapper for sendmsg().
msg | Message. |
flags | Flags. |
trafficClass | Traffic class for packet. |
ssize_t Socket::sendTo | ( | const void * | buffer, |
const size_t | length, | ||
const integer | flags, | ||
const SocketAddress & | receiver, | ||
const card8 | trafficClass = 0x00 |
||
) |
Wrapper for sendto(). sendto() will set the packet's traffic class, if trafficClass is not 0.
buffer | Buffer with data to send. |
length | Length of data to send. |
flags | Flags for sendto(). |
receiver | Address of receiver. |
trafficClass | Traffic class for packet. |
bool Socket::setBlockingMode | ( | const bool | on | ) |
Set blocking mode.
on | True to set blocking mode, false to unset. |
true | for success; false otherwise. |
bool Socket::setMulticastLoop | ( | const bool | on | ) |
Set multicast loop mode.
on | true to enable, false to disable. |
bool Socket::setMulticastTTL | ( | const card8 | ttl | ) |
Set multicast TTL.
ttl | TTL. |
bool Socket::setSoBroadcast | ( | const bool | on | ) |
Set SO_BROADCAST option of socket.
on | true to set SO_BROADCAST on; false otherwise. |
integer Socket::setSocketOption | ( | const cardinal | level, |
const cardinal | optionNumber, | ||
const void * | optionValue, | ||
const socklen_t | optionLength | ||
) | [inline] |
Get socket option (wrapper for getsockopt());
level | Level (e.g. SOL_SOCKET). |
optionNumber | Option (e.g. SO_REUSEADDR). |
optionValue | Memory with option. |
optionLength | Length of option memory. |
bool Socket::setSoLinger | ( | const bool | on, |
const cardinal | linger | ||
) |
Set SO_LINGER option of socket.
on | true to set linger on; false otherwise. |
linger | SO_LINGER in seconds. |
bool Socket::setSoReuseAddress | ( | const bool | on | ) |
Set SO_REUSEADDR option of socket.
on | true to set SO_REUSEADDR on; false otherwise. |
bool Socket::setTCPNoDelay | ( | const bool | on | ) |
Set TCP_NODELAY option of socket.
on | true to set TCP_NODELAY on; false otherwise. |
bool Socket::setTypeOfService | ( | const card8 | trafficClass | ) | [private] |
void Socket::shutdown | ( | const cardinal | shutdownLevel | ) |
Shutdown full-duplex connection partial or completely. SHUT_RD - further receives will be disallowed. SHUT_WR - further sends will be disallowed. SHUT_RDWR - further sends and receives will be disallowed.
shutdownLevel | SHUT_RD, SHUT_WR, SHUT_RDWR. |
ssize_t Socket::write | ( | const void * | buffer, |
const size_t | length | ||
) | [inline] |
Wrapper for write().
buffer | Buffer with data to write |
length | Length of data to write |
friend class TrafficShaper [friend] |
cardinal Socket::Backlog [private] |
sockaddr* Socket::Destination [private] |
integer Socket::Family [private] |
integer Socket::LastError [private] |
const cardinal Socket::MaxAutoSelectPort = 61000 [static] |
const cardinal Socket::MinAutoSelectPort = 16384 [static] |
integer Socket::Protocol [private] |
card32 Socket::ReceivedFlow [private] |
card32 Socket::SendFlow [private] |
int Socket::SocketDescriptor [private] |
integer Socket::Type [private] |