Base class for TCP/IP sockets. More...
Public Member Functions | |
TCPSocket () | |
Constructor. | |
virtual | ~TCPSocket () override |
Destructor. | |
bool | bind (const IPv4SocketAddress &addr, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Bind to a local address and port. More... | |
virtual bool | close (Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) override |
Close the socket. More... | |
bool | getLocalAddress (IPv4SocketAddress &addr, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Get local socket address. More... | |
SysSocketType | getSocket () const |
Get the underlying socket device handle (use with care). More... | |
bool | isOpen () const |
Check if socket is open. More... | |
virtual bool | open (Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) override |
Open the socket. More... | |
bool | reusePort (bool reuse_port, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Set the "reuse port" option. More... | |
bool | setKeepAlive (bool active, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Set the "keep alive" option. More... | |
bool | setLingerTime (int seconds, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Set the linger time option. More... | |
bool | setNoDelay (bool active, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Set the "no delay" option. More... | |
bool | setNoLinger (Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Remove the linger time option. More... | |
bool | setReceiveBufferSize (size_t size, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Set the receive buffer size. More... | |
bool | setReceiveTimeout (MilliSecond timeout, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Set the receive timeout. More... | |
bool | setSendBufferSize (size_t size, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Set the send buffer size. More... | |
bool | setTTL (int ttl, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance())))) |
Set the Time To Live (TTL) option. More... | |
Protected Member Functions | |
bool | createSocket (int domain, int type, int protocol, Report &report) |
Create the socket. More... | |
virtual void | declareOpened (SysSocketType sock, Report &report) override |
Set an open socket descriptor from a subclass. More... | |
virtual void | handleClosed (Report &report) |
This virtual method can be overriden by subclasses to be notified of close. More... | |
virtual void | handleOpened (Report &report) |
This virtual method can be overriden by subclasses to be notified of open. More... | |
Protected Attributes | |
Mutex | _mutex |
Mutex protecting this object. | |
Base class for TCP/IP sockets.
This base class is not supposed to be directly instantiated. The two concrete subclasses of TCPSocket are:
bool ts::TCPSocket::setTTL | ( | int | ttl, |
Report & | report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) |
||
) |
Set the Time To Live (TTL) option.
[in] | ttl | The TTL value, ie. the maximum number of "hops" between routers before an IP packet is dropped. |
[in,out] | report | Where to report error. |
bool ts::TCPSocket::setNoLinger | ( | Report & | report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) | ) |
Remove the linger time option.
[in,out] | report | Where to report error. |
bool ts::TCPSocket::setLingerTime | ( | int | seconds, |
Report & | report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) |
||
) |
Set the linger time option.
[in] | seconds | Number of seconds to wait after shuting down the socket. |
[in,out] | report | Where to report error. |
bool ts::TCPSocket::setKeepAlive | ( | bool | active, |
Report & | report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) |
||
) |
Set the "keep alive" option.
[in] | active | If true, the socket periodically sends "keep alive" packets when the connection is idle. |
[in,out] | report | Where to report error. |
bool ts::TCPSocket::setNoDelay | ( | bool | active, |
Report & | report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) |
||
) |
Set the "no delay" option.
[in] | active | If true, the socket immediately sends outgoing packets. By default, a TCP socket waits a small amount of time after a send() operation to get a chance to group outgoing data from successive send() operations into one single packet. |
[in,out] | report | Where to report error. |
bool ts::TCPSocket::bind | ( | const IPv4SocketAddress & | addr, |
Report & | report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) |
||
) |
Bind to a local address and port.
The IP address part of the socket address must one of:
The port number part of the socket address must be one of:
[in] | addr | Local socket address to bind to. |
[in,out] | report | Where to report error. |
|
overridevirtual |
Open the socket.
[in,out] | report | Where to report error. |
Implements ts::Socket.
|
overridevirtual |
Close the socket.
[in,out] | report | Where to report error. |
Reimplemented from ts::Socket.
Reimplemented in ts::TCPServer.
|
protectedvirtual |
This virtual method can be overriden by subclasses to be notified of open.
All subclasses should explicitly invoke their superclass' handlers.
[in,out] | report | Where to report error. |
|
protectedvirtual |
This virtual method can be overriden by subclasses to be notified of close.
All subclasses should explicitly invoke their superclass' handlers.
[in,out] | report | Where to report error. |
Reimplemented in ts::TCPConnection.
|
overrideprotectedvirtual |
Set an open socket descriptor from a subclass.
This method is used by a server to declare that a client socket has just become opened.
[in] | sock | New socket descriptor. |
[in,out] | report | Where to report error. |
Reimplemented from ts::Socket.
|
inlineinherited |
Check if socket is open.
|
inherited |
Set the send buffer size.
[in] | size | Send buffer size in bytes. |
[in,out] | report | Where to report error. |
|
inherited |
Set the receive buffer size.
[in] | size | Receive buffer size in bytes. |
[in,out] | report | Where to report error. |
|
inherited |
Set the receive timeout.
[in] | timeout | Receive timeout in milliseconds. If negative, receive timeout is not used. |
[in,out] | report | Where to report error. |
|
inherited |
Set the "reuse port" option.
[in] | reuse_port | If true, the socket is allowed to reuse a local UDP port which is already bound. |
[in,out] | report | Where to report error. |
|
inherited |
Get local socket address.
[out] | addr | Local socket address of the connection. |
[in,out] | report | Where to report error. |
|
inlineinherited |
Get the underlying socket device handle (use with care).
This method is reserved for low-level operations and should not be used by normal applications.
|
protectedinherited |