-
Notifications
You must be signed in to change notification settings - Fork 0
sockets::Connection
The Connection class represents an established network connection. Instances of the class may be moved, but are not copyable. This class takes one template argument, which is normally TCPSocket
. As such, TCPConnection
is equivalent to Connection<TCPSocket>
.
A custom Socket type may be passed as a template argument to Connection. This type must be move-constructable, move-assignable, implement the following methods:
Method Prototype | Description | Return |
---|---|---|
recv(ByteBuffer& buffer, size_t limit, size_t offset, int flags) |
Reads bytes into the given ByteBuffer beginning at the offset, up to the provided limit. The method is expected to resize the buffer to fit the data. If no data is available, the method blocks until ready. |
The number of bytes read. |
send(const ByteBuffer& buffer, size_t offset, int flags) |
Writes all the bytes beginning at the offset to the socket. | The number of bytes sent. |
invalid() |
Returns true if the Socket is invalid, false otherwise |
bool |
Normally this class is not instantiated directly, but created using the connect_to()
method.
Reads up to n bytes from the network. Returns a reference to a ByteBuffer
containing the data read. If no data is available, this method blocks until ready.
ClosedError
if the connection is marked as closed.
InvalidSocketError
if the socket is invalid.
SocketReadError
may be thrown by the internal socket class from a read()
call.
Reads exactly n bytes. Returns a reference to a ByteBuffer
containing the data read. This method blocks until exactly n
bytes are read, or an exception is thrown.
ClosedError
if the connection is marked as closed.
InvalidSocketError
if the socket is invalid.
SocketReadError
may be thrown by the internal socket class from a read()
call.
Reads data until delim
is encountered. Returns a reference to a ByteBuffer
containing all data read up to the delimiter. Any bytes read after the delimiter are discarded. This method blocks until the delimiter is encountered.
ClosedError
if the connection is marked as closed.
InvalidSocketError
if the socket is invalid.
SocketReadError
may be thrown by the internal socket class from a read()
call.
Writes all bytes from the iterator. Returns the number of bytes written.
Writes all bytes in the ByteString
. Returns the number of bytes written.
Returns a reference to the underlying Socket.
Returns a std::string
containing the ip address of the connected peer.
Returns true
if the connection has been closed. False otherwise.