simple-socket library 1.1.5
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes

NET::SCTPSocket Class Reference

SCTP socket class. More...

#include <SCTPSocket.h>

List of all members.

Public Types

enum  abortFlag { ABORT = SCTP_ABORT, SHUTDOWN = SCTP_EOF, KEEPALIVE = 0 }
typedef SocketHandle< SCTPSocketHandle
 Handle for a new socket returned by accept.
enum  receiveFlag
enum  ShutdownDirection { STOP_SEND = SHUT_WR, STOP_RECEIVE = SHUT_RD, STOP_BOTH = SHUT_RDWR }
enum  switchAddressFlag { KEEP_PRIMARY = 0, OVERRIDE_PRIMARY = SCTP_ADDR_OVER }

Public Member Functions

Handle accept () const
int bind (const std::vector< std::string > &localAddresses, unsigned short localPort=0)
void bind (unsigned short localPort=0)
void bind (const std::string &localAddress, unsigned short localPort=0)
 bind socket to address / port
int connect (const std::vector< std::string > &foreignAddresses, unsigned short foreignPort=0)
void connect (const std::string &foreignAddress, unsigned short foreignPort)
 establish a connection with the given foreign address and port
void disconnect ()
unsigned fragmentationPoint () const
std::string getForeignAddress () const
unsigned short getForeignPort () const
std::string getLocalAddress () const
unsigned short getLocalPort () const
unsigned inStreams () const
void listen (int backlog=5)
int notAckedData () const
unsigned outStreams () const
bool peerDisconnected () const
 returns whether a peer disconnected
int pendingData () const
std::string primaryAddress () const
int receive (void *data, int maxLen, unsigned &stream, receiveFlag &flag)
int receive (void *buffer, size_t len)
 receive data from a bound socket
int receive (void *data, int maxLen, unsigned &stream)
 SCTPSocket (Handle handle)
 SCTPSocket (unsigned numOutStreams=10, unsigned maxInStreams=65535, unsigned maxAttempts=4, unsigned maxInitTimeout=0)
int send (const void *data, int length, unsigned stream, unsigned ttl=0, unsigned context=0, unsigned ppid=0, abortFlag abort=KEEPALIVE, switchAddressFlag switchAddr=KEEP_PRIMARY)
int send (const void *buffer, size_t len)
 send data through a connected socket
int sendUnordered (const void *data, int length, unsigned stream, unsigned ttl=0, unsigned context=0, unsigned ppid=0, abortFlag abort=KEEPALIVE, switchAddressFlag switchAddr=KEEP_PRIMARY)
void shutdown (ShutdownDirection type)
 shutdown the connection in the specified direction
int state () const
Handle timedAccept (unsigned timeout) const
int timedReceive (void *buffer, size_t len, int timeout)
 receive data from a bound socket, return after the given timespan
int timedReceive (void *data, int maxLen, unsigned &stream, receiveFlag &flag, unsigned timeout)
int timedReceive (void *data, int maxLen, unsigned &stream, unsigned timeout)

Protected Types

enum  SocketDomain { INTERNET = PF_INET, UNIX = PF_LOCAL }
enum  SocketType { STREAM = SOCK_STREAM, DATAGRAM = SOCK_DGRAM }

Protected Member Functions

void setInitValues (unsigned ostr, unsigned istr, unsigned att, unsigned time)

Static Protected Member Functions

static void fillAddress (const std::string &address, unsigned short port, sockaddr_in &addr)

Protected Attributes

bool m_peerDisconnected
int m_socket

Detailed Description

SCTP socket class.

Definition at line 16 of file SCTPSocket.h.


Member Typedef Documentation

Handle for a new socket returned by accept.

Definition at line 20 of file SCTPSocket.h.


Member Enumeration Documentation

Enumerator:
ABORT 
SHUTDOWN 
KEEPALIVE 

Definition at line 22 of file SCTPSocket.h.

Enumerator:
KEEP_PRIMARY 
OVERRIDE_PRIMARY 

Definition at line 29 of file SCTPSocket.h.

Definition at line 35 of file SCTPSocket.h.

Enumerator:
STOP_SEND 

disable all variants of send() on the socket, receive calls still work

STOP_RECEIVE 

disable all variants of receive() on the socket, send calls still work

STOP_BOTH 

disable all send() and receive() calls on the socket

Definition at line 49 of file SimpleSocket.h.

enum NET::SimpleSocket::SocketDomain [protected, inherited]
Enumerator:
INTERNET 
UNIX 

Definition at line 166 of file SimpleSocket.h.

enum NET::SimpleSocket::SocketType [protected, inherited]
Enumerator:
STREAM 
DATAGRAM 

Definition at line 172 of file SimpleSocket.h.


Constructor & Destructor Documentation

SCTPSocket::SCTPSocket ( unsigned  numOutStreams = 10,
unsigned  maxInStreams = 65535,
unsigned  maxAttempts = 4,
unsigned  maxInitTimeout = 0 
)

Definition at line 10 of file SCTPSocket.cpp.

SCTPSocket::SCTPSocket ( Handle  handle)

Construct a Socket from a Handle returned by accept()

Exceptions:
SocketExceptionthrown if handle is invalid

Definition at line 19 of file SCTPSocket.cpp.


Member Function Documentation

int SCTPSocket::bind ( const std::vector< std::string > &  localAddresses,
unsigned short  localPort = 0 
)

Definition at line 23 of file SCTPSocket.cpp.

int SCTPSocket::connect ( const std::vector< std::string > &  foreignAddresses,
unsigned short  foreignPort = 0 
)

Definition at line 37 of file SCTPSocket.cpp.

int SCTPSocket::state ( ) const

Definition at line 54 of file SCTPSocket.cpp.

int SCTPSocket::notAckedData ( ) const

Definition at line 63 of file SCTPSocket.cpp.

int SCTPSocket::pendingData ( ) const

Definition at line 72 of file SCTPSocket.cpp.

unsigned SCTPSocket::inStreams ( ) const

Definition at line 81 of file SCTPSocket.cpp.

unsigned SCTPSocket::outStreams ( ) const

Definition at line 90 of file SCTPSocket.cpp.

unsigned SCTPSocket::fragmentationPoint ( ) const

Definition at line 99 of file SCTPSocket.cpp.

std::string SCTPSocket::primaryAddress ( ) const

Definition at line 108 of file SCTPSocket.cpp.

int SCTPSocket::send ( const void *  data,
int  length,
unsigned  stream,
unsigned  ttl = 0,
unsigned  context = 0,
unsigned  ppid = 0,
abortFlag  abort = KEEPALIVE,
switchAddressFlag  switchAddr = KEEP_PRIMARY 
)

Definition at line 113 of file SCTPSocket.cpp.

int SCTPSocket::sendUnordered ( const void *  data,
int  length,
unsigned  stream,
unsigned  ttl = 0,
unsigned  context = 0,
unsigned  ppid = 0,
abortFlag  abort = KEEPALIVE,
switchAddressFlag  switchAddr = KEEP_PRIMARY 
)

Definition at line 124 of file SCTPSocket.cpp.

int SCTPSocket::receive ( void *  data,
int  maxLen,
unsigned &  stream 
)

Definition at line 136 of file SCTPSocket.cpp.

int SCTPSocket::receive ( void *  data,
int  maxLen,
unsigned &  stream,
receiveFlag flag 
)

Definition at line 146 of file SCTPSocket.cpp.

int SCTPSocket::timedReceive ( void *  data,
int  maxLen,
unsigned &  stream,
unsigned  timeout 
)

Definition at line 157 of file SCTPSocket.cpp.

int SCTPSocket::timedReceive ( void *  data,
int  maxLen,
unsigned &  stream,
receiveFlag flag,
unsigned  timeout 
)

Definition at line 177 of file SCTPSocket.cpp.

void SCTPSocket::listen ( int  backlog = 5)

Definition at line 197 of file SCTPSocket.cpp.

SCTPSocket::Handle SCTPSocket::accept ( ) const

Definition at line 204 of file SCTPSocket.cpp.

SCTPSocket::Handle SCTPSocket::timedAccept ( unsigned  timeout) const

Definition at line 212 of file SCTPSocket.cpp.

void SCTPSocket::setInitValues ( unsigned  ostr,
unsigned  istr,
unsigned  att,
unsigned  time 
) [protected]

Definition at line 229 of file SCTPSocket.cpp.

void InternetSocket::connect ( const std::string &  foreignAddress,
unsigned short  foreignPort 
) [inherited]

establish a connection with the given foreign address and port

If you are using a connection oriented socket (like TCPSocket), you have to call connect() on that socket in order to send data. However, if you are using a non-connection oriented socket (like UDPSocket), calling connect on that socket will allow you to use the send() function like on a connection oriented socket.

Parameters:
foreignAddressforeign address (IP address or name)
foreignPortforeign port
Exceptions:
SocketExceptionthrown if unable to establish connection
Examples:
TCP_Client.cpp, and UDP_Multicast.cpp.

Definition at line 19 of file InternetSocket.cpp.

void InternetSocket::bind ( unsigned short  localPort = 0) [inherited]

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Instead of the richer function with more arguments, this bind() binds to any available interface / address

Examples:
TCP_Server.cpp, and UDP_Multicast.cpp.

Definition at line 30 of file InternetSocket.cpp.

void InternetSocket::bind ( const std::string &  localAddress,
unsigned short  localPort = 0 
) [inherited]

bind socket to address / port

Set the local port to the specified port and the local address to an interface.

bind() attaches the local endpoint of the socket to the specified interface and port. Typically all servers use bind() to attach to the local port specified by the used protocol. You just need to call bind if you want to restrict the connection to a specific local interface, or if you want to listen on a specific port. If you are just a client using connect() to connect to a server, calling bind is most likely unnecessary.

To bind to a port < 1023 you need eighter superuser access, or the SUID bit set on your program.

Parameters:
localAddresslocal address
localPortlocal port
Exceptions:
SocketExceptionthrown if setting local port fails

Definition at line 41 of file InternetSocket.cpp.

std::string InternetSocket::getLocalAddress ( ) const [inherited]

Get the local address (after binding the socket).

Returns:
local address of socket
Exceptions:
SocketExceptionthrown if fetch fails

Definition at line 50 of file InternetSocket.cpp.

unsigned short InternetSocket::getLocalPort ( ) const [inherited]

Get the local port (after binding the socket).

Returns:
local port of socket
Exceptions:
SocketExceptionthrown if fetch fails

Definition at line 61 of file InternetSocket.cpp.

std::string InternetSocket::getForeignAddress ( ) const [inherited]

Get the foreign address. Call connect() before using this function.

Returns:
foreign address
Exceptions:
SocketExceptionthrown if unable to fetch foreign address

Definition at line 72 of file InternetSocket.cpp.

unsigned short InternetSocket::getForeignPort ( ) const [inherited]

Get the foreign port. Call connect() before using this function.

Returns:
foreign port
Exceptions:
SocketExceptionthrown if unable to fetch foreign port

Definition at line 83 of file InternetSocket.cpp.

void InternetSocket::fillAddress ( const std::string &  address,
unsigned short  port,
sockaddr_in &  addr 
) [static, protected, inherited]

Fill an address structure with the given address and port number. If the given address is not a valid IPv4 address, it will be resolved by hostname or DNS lookup. addr will be unchanged if this resolve fails.

Parameters:
addressIPv4 domain name or address
portIP port number to fill in
addraddress structure to fill
Exceptions:
SocketExceptionthrown if unable to resolve a hostname

Definition at line 94 of file InternetSocket.cpp.

int SimpleSocket::send ( const void *  buffer,
size_t  len 
) [inherited]

send data through a connected socket

send() can only be used on a socket that called connect() before. If you try to use send() on a not connected socket, SocketException will be thrown.

If you are using a stream oriented socket (like TCPSocket), the operating system is allowed to send only a part of the packet you told it to send, so send() will return the number of bytes actually sent. It is your responsibility to resend the data not sent by send()

If you are using a datagram oriented socket (like UDPSocket or SCTPSocket) the operating system will only send and receive complete datagrams, but send() will fail if you are trying to send too much data. In that case SocketException will be thrown.

Parameters:
bufferdata to be send
lenlength of the data to be sent
Returns:
number of bytes sent
Exceptions:
SocketExceptionif sending went wrong
Examples:
TCP_Server.cpp, and UDP_Multicast.cpp.

Definition at line 43 of file SimpleSocket.cpp.

int SimpleSocket::receive ( void *  buffer,
size_t  len 
) [inherited]

receive data from a bound socket

receive() can only be used on a socket that called bind() or connect() before. If you try to use receive() on a not bound socket, SocketException will be thrown.

If using a stream oriented Socket, receive can return a part of a received messge, e.g. if you send 100 bytes, it's possible you will receive 50 bytes two times in a row. However, the order of the sent data will be preserved.

If you are using a datagram oriented sockets, you will only receive whole datagrams. But beware of using a too small buffer. If the receive buffer is too small for the received datagram, the data you didn't read in the receive call will be discared.

If the remote host has closed the connection (on a connection based socket like TCP or SCTP) receive() will return 0. If you are using a connectionless protocol (like UDP) there is no way to determine wheter the connection has been closed by the remote host or not.

Parameters:
bufferthe buffer the received data will be written to
lenlength of the provided buffer, receive will not read more than that
Returns:
number of bytes received
Exceptions:
SocketExceptionin case an error occured
Examples:
UDP_Multicast.cpp.

Definition at line 61 of file SimpleSocket.cpp.

int SimpleSocket::timedReceive ( void *  buffer,
size_t  len,
int  timeout 
) [inherited]

receive data from a bound socket, return after the given timespan

timedReceive() can only be used on a socket that called bind() or connect before. If you try to use receive() on a not bound socket, SocketException will be thrown.

If using a stream oriented Socket, receive can return a part of a received messge, e.g. if you send 100 bytes, it's possible you will receive 50 bytes two times in a row. However, the order of the sent data will be preserved.

If you are using a datagram oriented sockets, you will only receive whole datagrams. But beware of using a too small buffer. If the receive buffer is too small for the received datagram, the data you didn't read in the receive call will be discared.

If the remote host has closed the connection (on a connection based socket like TCP or SCTP) receive() will return 0. If you are using a connectionless protocol (like UDP) there is no way to determine wheter the connection has been closed by the remote host or not.

Parameters:
bufferthe buffer the received data will be written to
lenlength of the provided buffer, receive will not read more than that
timeoutthe timeout in ms after which receive will give up and return
Returns:
number of bytes received, 0 on timeout
Exceptions:
SocketExceptionin case an error occured
Examples:
TCP_Client.cpp.

Definition at line 68 of file SimpleSocket.cpp.

void SimpleSocket::disconnect ( ) [inherited]

Disconnect and unset any foreign addresses

Exceptions:
SocketExceptionthrown if unable to disconnect
Examples:
TCP_Client.cpp, and TCP_Server.cpp.

Definition at line 88 of file SimpleSocket.cpp.

void SimpleSocket::shutdown ( ShutdownDirection  type) [inherited]

shutdown the connection in the specified direction

Depending on the specified ShutdownDirection, calls for that direction will stop working. Use this function if you want to have more control than just destroing the socket. It allows you to cut the connection in one direction, or both.

If you use shutdown() on an unconnected socket, the corresponding calls will simply stop working.

Parameters:
typethe ShutdownDirection that be used
Exceptions:
SocketExceptionin case an error occured

Definition at line 103 of file SimpleSocket.cpp.

bool SimpleSocket::peerDisconnected ( ) const [inherited]

returns whether a peer disconnected

Will only work if you use a connection oriented, connected socket. Returns true if the peer disconnected. Use this function after a call to receive, returned 0 received bytes.

Returns:
true if a peer disconnected
Examples:
TCP_Server.cpp.

Definition at line 109 of file SimpleSocket.cpp.


Member Data Documentation

int NET::SimpleSocket::m_socket [protected, inherited]

Definition at line 185 of file SimpleSocket.h.

bool NET::SimpleSocket::m_peerDisconnected [protected, inherited]

Definition at line 186 of file SimpleSocket.h.


The documentation for this class was generated from the following files: