Kea 2.5.8
isc::asiolink::TCPSocket< C > Class Template Reference

The TCPSocket class is a concrete derived class of IOAsioSocket that represents a TCP socket. More...

#include <tcp_socket.h>

+ Inheritance diagram for isc::asiolink::TCPSocket< C >:

Public Member Functions

 TCPSocket (boost::asio::ip::tcp::socket &socket)
 Constructor from an ASIO TCP socket.
 
 TCPSocket (const IOServicePtr &service)
 Constructor.
 
virtual ~TCPSocket ()
 Destructor.
 
virtual void asyncReceive (void *data, size_t length, size_t offset, IOEndpoint *endpoint, C &callback)
 Receive Asynchronously.
 
void asyncSend (const void *data, size_t length, C &callback)
 Send Asynchronously without count.
 
virtual void asyncSend (const void *data, size_t length, const IOEndpoint *endpoint, C &callback)
 Send Asynchronously.
 
virtual void cancel ()
 Cancel I/O On Socket.
 
virtual void close ()
 Close socket.
 
virtual boost::asio::ip::tcp::socket & getASIOSocket () const
 Returns reference to the underlying ASIO socket.
 
virtual int getNative () const
 Return file descriptor of underlying socket.
 
virtual int getProtocol () const
 Return protocol of socket.
 
virtual bool isOpenSynchronous () const
 Is "open()" synchronous?
 
bool isUsable () const
 Checks if the connection is usable.
 
virtual void open (const IOEndpoint *endpoint, C &callback)
 Open Socket.
 
virtual bool processReceivedData (const void *staging, size_t length, size_t &cumulative, size_t &offset, size_t &expected, isc::util::OutputBufferPtr &buff)
 Process received data packet.
 

Additional Inherited Members

Detailed Description

template<typename C>
class isc::asiolink::TCPSocket< C >

The TCPSocket class is a concrete derived class of IOAsioSocket that represents a TCP socket.

Parameters
CCallback type

Definition at line 48 of file tcp_socket.h.

Constructor & Destructor Documentation

◆ TCPSocket() [1/2]

template<typename C >
isc::asiolink::TCPSocket< C >::TCPSocket ( boost::asio::ip::tcp::socket &  socket)

Constructor from an ASIO TCP socket.

Parameters
socketThe ASIO representation of the TCP socket. It is assumed that the caller will open and close the socket, so these operations are a no-op for that socket.

Definition at line 258 of file tcp_socket.h.

◆ TCPSocket() [2/2]

template<typename C >
isc::asiolink::TCPSocket< C >::TCPSocket ( const IOServicePtr service)

Constructor.

Used when the TCPSocket is being asked to manage its own internal socket. In this case, the open() and close() methods are used.

Parameters
serviceI/O Service object used to manage the socket.

Definition at line 265 of file tcp_socket.h.

◆ ~TCPSocket()

template<typename C >
isc::asiolink::TCPSocket< C >::~TCPSocket
virtual

Destructor.

Definition at line 273 of file tcp_socket.h.

Member Function Documentation

◆ asyncReceive()

template<typename C >
void isc::asiolink::TCPSocket< C >::asyncReceive ( void *  data,
size_t  length,
size_t  offset,
IOEndpoint endpoint,
C &  callback 
)
virtual

Receive Asynchronously.

Calls the underlying socket's async_receive() method to read a packet of data from a remote endpoint. Arrival of the data is signalled via a call to the callback function.

Parameters
dataBuffer to receive incoming message
lengthLength of the data buffer
offsetOffset into buffer where data is to be put
endpointSource of the communication
callbackCallback object

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 378 of file tcp_socket.h.

References isc::asiolink::TCPEndpoint::getASIOEndpoint(), isc::asiolink::IOEndpoint::getProtocol(), isc_throw, and isc_throw_assert.

+ Here is the call graph for this function:

◆ asyncSend() [1/2]

template<typename C >
void isc::asiolink::TCPSocket< C >::asyncSend ( const void *  data,
size_t  length,
C &  callback 
)

Send Asynchronously without count.

This variant of the method sends data over the TCP socket without preceding the data with a data count. Eventually, we should migrate the virtual method to not insert the count but there are existing classes using the count. Once this migration is done, the existing virtual method should be replaced by this method.

Parameters
dataData to send
lengthLength of data to send
callbackCallback object.
Exceptions
BufferTooLargeon attempt to send a buffer larger than 64kB.

Definition at line 321 of file tcp_socket.h.

References isc_throw.

◆ asyncSend() [2/2]

template<typename C >
void isc::asiolink::TCPSocket< C >::asyncSend ( const void *  data,
size_t  length,
const IOEndpoint endpoint,
C &  callback 
)
virtual

Send Asynchronously.

Calls the underlying socket's async_send() method to send a packet of data asynchronously to the remote endpoint. The callback will be called on completion.

Parameters
dataData to send
lengthLength of data to send
endpointTarget of the send. (Unused for a TCP socket because that was determined when the connection was opened.)
callbackCallback object.
Exceptions
BufferTooLargeon attempt to send a buffer larger than 64kB.

Need to copy the data into a temporary buffer and precede it with a two-byte count field.

Todo:
arrange for the buffer passed to be preceded by the count

Ensure it fits into 16 bits

Copy data into a buffer preceded by the count field.

... and send it

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 344 of file tcp_socket.h.

References isc_throw.

◆ cancel()

template<typename C >
void isc::asiolink::TCPSocket< C >::cancel
virtual

Cancel I/O On Socket.

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 480 of file tcp_socket.h.

◆ close()

template<typename C >
void isc::asiolink::TCPSocket< C >::close
virtual

Close socket.

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 490 of file tcp_socket.h.

◆ getASIOSocket()

template<typename C >
virtual boost::asio::ip::tcp::socket & isc::asiolink::TCPSocket< C >::getASIOSocket ( ) const
inlinevirtual

Returns reference to the underlying ASIO socket.

Returns
Reference to underlying ASIO socket.

Definition at line 218 of file tcp_socket.h.

◆ getNative()

template<typename C >
virtual int isc::asiolink::TCPSocket< C >::getNative ( ) const
inlinevirtual

Return file descriptor of underlying socket.

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 75 of file tcp_socket.h.

◆ getProtocol()

template<typename C >
virtual int isc::asiolink::TCPSocket< C >::getProtocol ( ) const
inlinevirtual

Return protocol of socket.

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 84 of file tcp_socket.h.

◆ isOpenSynchronous()

template<typename C >
virtual bool isc::asiolink::TCPSocket< C >::isOpenSynchronous ( ) const
inlinevirtual

Is "open()" synchronous?

Indicates that the opening of a TCP socket is asynchronous.

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 91 of file tcp_socket.h.

◆ isUsable()

template<typename C >
bool isc::asiolink::TCPSocket< C >::isUsable ( ) const
inline

Checks if the connection is usable.

The connection is usable if the socket is open and the peer has not closed its connection.

Returns
true if the connection is usable.

Definition at line 101 of file tcp_socket.h.

◆ open()

template<typename C >
void isc::asiolink::TCPSocket< C >::open ( const IOEndpoint endpoint,
C &  callback 
)
virtual

Open Socket.

Opens the TCP socket. This is an asynchronous operation, completion of which will be signalled via a call to the callback function.

Parameters
endpointEndpoint to which the socket will connect.
callbackCallback object.

the derived class and the two classes differ on return type.

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 280 of file tcp_socket.h.

References isc::asiolink::TCPEndpoint::getASIOEndpoint(), isc::asiolink::IOEndpoint::getFamily(), isc::asiolink::IOEndpoint::getProtocol(), and isc_throw_assert.

+ Here is the call graph for this function:

◆ processReceivedData()

template<typename C >
bool isc::asiolink::TCPSocket< C >::processReceivedData ( const void *  staging,
size_t  length,
size_t &  cumulative,
size_t &  offset,
size_t &  expected,
isc::util::OutputBufferPtr buff 
)
virtual

Process received data packet.

See the description of IOAsioSocket::receiveComplete for a complete description of this method.

Parameters
stagingPointer to the start of the staging buffer.
lengthAmount of data in the staging buffer.
cumulativeAmount of data received before the staging buffer is processed.
offsetUnused.
expectedunused.
buffOutput buffer. Data in the staging buffer is be copied to this output buffer in the call.
Returns
Always true

Implements isc::asiolink::IOAsioSocket< C >.

Definition at line 417 of file tcp_socket.h.

References isc::util::readUint16().

+ Here is the call graph for this function:

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