RTP Trace System
1.0
|
#include <socket.h>
Public Types | |
enum | SocketCommunicationDomain { UndefinedSocketCommunicationDomain = -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 } |
Public Member Functions | |
Socket () | |
Socket (const SocketCommunicationDomain communicationDomain, const SocketType socketType, const SocketProtocol socketProtocol=Default) | |
virtual | ~Socket () |
bool | create (const SocketCommunicationDomain communicationDomain=IP, const SocketType socketType=TCP, const SocketProtocol socketProtocol=Default) |
void | close () |
void | shutdown (const cardinal shutdownLevel) |
card64 | getBytesSent () const |
card64 | getBytesReceived () const |
void | resetBytesSent () |
void | resetBytesReceived () |
bool | ready () const |
bool | bind (const SocketAddress &address=InternetAddress()) |
bool | listen (const cardinal backlog=5) |
Socket * | accept () |
bool | connect (const SocketAddress &address, const card8 trafficClass=0) |
integer | getLastError () |
integer | getSocketOption (const cardinal level, const cardinal optionNumber, void *optionValue, socklen_t *optionLength) const |
cardinal | getSoLinger () const |
bool | getSoReuseAddress () const |
bool | getSoBroadcast () const |
bool | getTCPNoDelay () const |
bool | getBlockingMode () |
integer | setSocketOption (const cardinal level, const cardinal optionNumber, const void *optionValue, const socklen_t optionLength) |
void | setSoLinger (const bool on, const cardinal linger) |
void | setSoReuseAddress (const bool on) |
void | setSoBroadcast (const bool on) |
void | setTCPNoDelay (const bool on) |
void | setBlockingMode (const bool on) |
card32 | getSendFlowLabel () const |
card8 | getSendTrafficClass () const |
card32 | getReceivedFlowLabel () const |
card8 | getReceivedTrafficClass () const |
virtual ssize_t | sendTo (const void *buffer, const size_t length, const cardinal flags, const SocketAddress &receiver, const card8 trafficClass=0) |
virtual ssize_t | send (const void *buffer, const size_t length, const cardinal flags=0, const card8 trafficClass=0) |
virtual ssize_t | receiveFrom (void *buffer, const size_t length, SocketAddress &sender, const cardinal flags=0) |
virtual ssize_t | receive (void *buffer, const size_t length, const cardinal flags=0) |
virtual ssize_t | read (void *buffer, const size_t length) |
virtual ssize_t | write (const void *buffer, const size_t length) |
integer | fcntl (const integer cmd, const long arg=0) |
integer | ioctl (const integer request, const void *argp) |
bool | getSocketAddress (SocketAddress &address) const |
bool | getPeerAddress (SocketAddress &address) const |
InternetFlow | allocFlow (const InternetAddress &address, const card32 flowLabel=0, const card8 shareLevel=IPV6_FL_S_PROCESS) |
void | freeFlow (InternetFlow &flow) |
bool | renewFlow (InternetFlow &flow, const cardinal expires, const cardinal linger=6) |
bool | renewFlow (const cardinal expires, const cardinal linger=6) |
virtual void | setTrafficConstraint (const card8 trafficClass, const card64 bandwidth, const double bufferDelay) |
virtual void | flush () |
int | getSystemSocketDescriptor () const |
Static Public Member Functions | |
static bool | bindInternetSocketPair (Socket &senderSocket, Socket &receiverSocket, const InternetAddress &receiver=InternetAddress()) |
Static Public Attributes | |
static const cardinal | MinAutoSelectPort = 16384 |
static const cardinal | MaxAutoSelectPort = 65535 |
Protected Member Functions | |
void | init () |
bool | setTOS (const card8 trafficClass) |
ssize_t | recvFrom (int fd, void *buf, const size_t len, const integer flags, struct sockaddr *addr, size_t *addrlen) |
Protected Attributes | |
card64 | BytesSent |
card64 | BytesReceived |
card32 | SendFlow |
card32 | ReceivedFlow |
cardinal | Backlog |
cardinal | LastError |
int | SocketDescriptor |
sockaddr * | Destination |
SocketCommunicationDomain | CommunicationDomain |
SocketType | Type |
SocketProtocol | Protocol |
Friends | |
class | TrafficShaper |
This class manages a socket. IPv6 support is automatically available, when supported by the system.
Constructor.
Coral::Socket::Socket | ( | const SocketCommunicationDomain | communicationDomain, |
const SocketType | socketType, | ||
const SocketProtocol | socketProtocol = Default |
||
) |
Constructor for a new socket. For automatic usage of IPv6 when available, set communication domain to IP. Use IPv4/IPv6 only if a special protocol version is necessary! The creation success can be checked using ready() method.
communicationDomain | Communication domain (e.g. IP). |
socketType | Socket type (e.g. TCP, UDP). |
socketProtocol | Socket protocol (e.g. Default). |
Coral::Socket::~Socket | ( | ) | [virtual] |
Destructor.
Socket * Coral::Socket::accept | ( | ) |
Accept a connection.
InternetFlow Coral::Socket::allocFlow | ( | const InternetAddress & | address, |
const card32 | flowLabel = 0 , |
||
const card8 | shareLevel = IPV6_FL_S_PROCESS |
||
) |
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 Coral::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 Coral::Socket::bindInternetSocketPair | ( | Socket & | senderSocket, |
Socket & | receiverSocket, | ||
const InternetAddress & | receiver = InternetAddress() |
||
) | [static] |
Bind a pair of internet sockets to a given address and port number x and x + 1. x will be a random number, if given port number is 0.
senderSocket | First socket. |
receiverSocket | Second socket. |
receiver | Address (e.g ipv6-localhost:0) or NULL for Any address. |
void Coral::Socket::close | ( | ) |
Close socket.
bool Coral::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 Coral::Socket::create | ( | const SocketCommunicationDomain | communicationDomain = IP , |
const SocketType | socketType = TCP , |
||
const SocketProtocol | socketProtocol = Default |
||
) |
Close existing socket and create new socket. For automatic usage of IPv6 when available, set communication domain to IP. Use IPv4/IPv6 only if a special protocol version is necessary!
communicationDomain | Communication domain (e.g. IP). |
socketType | Socket type (e.g. TCP, UDP). |
socketProtocol | Socket protocol (e.g. Default). |
integer Coral::Socket::fcntl | ( | const integer | cmd, |
const long | arg = 0 |
||
) | [inline] |
void Coral::Socket::flush | ( | ) | [virtual] |
Flush traffic shaper buffer. Note: This functionality has to be implemented by subclasses!
void Coral::Socket::freeFlow | ( | InternetFlow & | flow | ) |
Free a flow.
flow | Flow to be freed. |
bool Coral::Socket::getBlockingMode | ( | ) |
Check, if blocking mode is on.
card64 Coral::Socket::getBytesReceived | ( | ) | const [inline] |
Get number of bytes received.
card64 Coral::Socket::getBytesSent | ( | ) | const [inline] |
Get number of bytes sent.
integer Coral::Socket::getLastError | ( | ) | [inline] |
Get last error code. It will be reset to 0 after copying.
bool Coral::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. |
card32 Coral::Socket::getReceivedFlowLabel | ( | ) | const [inline] |
Get last received flow label.
card8 Coral::Socket::getReceivedTrafficClass | ( | ) | const [inline] |
Get last received traffic class.
card32 Coral::Socket::getSendFlowLabel | ( | ) | const [inline] |
Get flow label of the connection.
card8 Coral::Socket::getSendTrafficClass | ( | ) | const [inline] |
Get traffic class of the connection.
bool Coral::Socket::getSoBroadcast | ( | ) | const |
Get SO_BROADCAST option of socket.
bool Coral::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 Coral::Socket::getSocketOption | ( | const cardinal | level, |
const cardinal | optionNumber, | ||
void * | optionValue, | ||
socklen_t * | optionLength | ||
) | const [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. |
cardinal Coral::Socket::getSoLinger | ( | ) | const |
Get SO_LINGER option of socket.
bool Coral::Socket::getSoReuseAddress | ( | ) | const |
Get SO_REUSEADDR option of socket.
int Coral::Socket::getSystemSocketDescriptor | ( | ) | const [inline] |
bool Coral::Socket::getTCPNoDelay | ( | ) | const |
Get TCP_NODELAY option of socket.
void Coral::Socket::init | ( | ) | [protected] |
integer Coral::Socket::ioctl | ( | const integer | request, |
const void * | argp | ||
) | [inline] |
bool Coral::Socket::listen | ( | const cardinal | backlog = 5 | ) |
Set socket to listen mode with given backlog (queue length for sockets waiting for acception).
backlog | Backlog. |
ssize_t Coral::Socket::read | ( | void * | buffer, |
const size_t | length | ||
) | [virtual] |
Wrapper for read().
buffer | Buffer to read data to. |
length | Maximum length of data to be received. |
bool Coral::Socket::ready | ( | ) | const [inline] |
Check, if socket is ready.
ssize_t Coral::Socket::receive | ( | void * | buffer, |
const size_t | length, | ||
const cardinal | flags = 0 |
||
) | [virtual] |
Wrapper for recv().
buffer | Buffer to read data to. |
length | Maximum length of data to be received. |
flags | Flags for recv(). |
ssize_t Coral::Socket::receiveFrom | ( | void * | buffer, |
const size_t | length, | ||
SocketAddress & | sender, | ||
const cardinal | flags = 0 |
||
) | [virtual] |
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 recvfrom(). |
ssize_t Coral::Socket::recvFrom | ( | int | fd, |
void * | buf, | ||
const size_t | len, | ||
const integer | flags, | ||
struct sockaddr * | addr, | ||
size_t * | addrlen | ||
) | [protected] |
bool Coral::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 Coral::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). |
void Coral::Socket::resetBytesReceived | ( | ) | [inline] |
Reset number of bytes received.
void Coral::Socket::resetBytesSent | ( | ) | [inline] |
Reset number of bytes sent.
ssize_t Coral::Socket::send | ( | const void * | buffer, |
const size_t | length, | ||
const cardinal | flags = 0 , |
||
const card8 | trafficClass = 0 |
||
) | [virtual] |
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 Coral::Socket::sendTo | ( | const void * | buffer, |
const size_t | length, | ||
const cardinal | flags, | ||
const SocketAddress & | receiver, | ||
const card8 | trafficClass = 0 |
||
) | [virtual] |
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. |
void Coral::Socket::setBlockingMode | ( | const bool | on | ) |
Set blocking mode.
on | True to set blocking mode, false to unset. |
void Coral::Socket::setSoBroadcast | ( | const bool | on | ) |
Set SO_BROADCAST option of socket.
on | true to set SO_BROADCAST on; false otherwise. |
integer Coral::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. |
void Coral::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. |
void Coral::Socket::setSoReuseAddress | ( | const bool | on | ) |
Set SO_REUSEADDR option of socket.
on | true to set SO_REUSEADDR on; false otherwise. |
void Coral::Socket::setTCPNoDelay | ( | const bool | on | ) |
Set TCP_NODELAY option of socket.
on | true to set TCP_NODELAY on; false otherwise. |
bool Coral::Socket::setTOS | ( | const card8 | trafficClass | ) | [protected] |
void Coral::Socket::setTrafficConstraint | ( | const card8 | trafficClass, |
const card64 | bandwidth, | ||
const double | bufferDelay | ||
) | [virtual] |
Set traffic constraint to given byte rate. Packets exceeding the given constraint will be dropped. Note: This functionality has to be implemented by subclasses!
trafficClass | Traffic class. |
bandwidth | Bandwidth. |
bufferDelay | Maximum buffer delay in microseconds. |
void Coral::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 Coral::Socket::write | ( | const void * | buffer, |
const size_t | length | ||
) | [virtual] |
Wrapper for write().
buffer | Buffer with data to write |
length | Length of data to write |
friend class TrafficShaper [friend] |
cardinal Coral::Socket::Backlog [protected] |
card64 Coral::Socket::BytesReceived [protected] |
card64 Coral::Socket::BytesSent [protected] |
sockaddr* Coral::Socket::Destination [protected] |
cardinal Coral::Socket::LastError [protected] |
const cardinal Coral::Socket::MaxAutoSelectPort = 65535 [static] |
const cardinal Coral::Socket::MinAutoSelectPort = 16384 [static] |
SocketProtocol Coral::Socket::Protocol [protected] |
card32 Coral::Socket::ReceivedFlow [protected] |
card32 Coral::Socket::SendFlow [protected] |
int Coral::Socket::SocketDescriptor [protected] |
SocketType Coral::Socket::Type [protected] |