Connection handles Communication between client and server, is used on both sides.
More...
|
void | init_peer_data () |
| determine peer address and port More...
|
|
bool | can_sysread () |
| Determine wether at least 1 byte can be read without blocking. More...
|
|
bool | can_syswrite () |
| Determine wether at least 1 byte can be written without blocking. More...
|
|
std::string | sysread (unsigned bytes) |
| Call the system's read function and try to read bytes. More...
|
|
std::string | syswrite (const std::string &data) |
| Call the system's write function and try to write all characters in the string data. More...
|
|
Connection handles Communication between client and server, is used on both sides.
◆ Connection()
MHA_TCP::Connection::Connection |
( |
SOCKET |
_fd | ) |
|
|
protected |
Create a connection instance from a socket filedescriptor.
- Parameters
-
_fd | The file descriptor of the TCP Socket. This file descriptor is closed again in the destructor. |
- Exceptions
-
◆ ~Connection()
Connection::~Connection |
( |
| ) |
|
|
virtual |
Destructor closes the underlying file descriptor.
◆ init_peer_data()
void MHA_TCP::Connection::init_peer_data |
( |
| ) |
|
|
private |
determine peer address and port
◆ can_sysread()
bool Connection::can_sysread |
( |
| ) |
|
|
private |
Determine wether at least 1 byte can be read without blocking.
◆ can_syswrite()
bool Connection::can_syswrite |
( |
| ) |
|
|
private |
Determine wether at least 1 byte can be written without blocking.
◆ sysread()
std::string Connection::sysread |
( |
unsigned |
bytes | ) |
|
|
private |
Call the system's read function and try to read bytes.
This will block in a situation where can_sysread returns false.
- Parameters
-
bytes | The desired number of characters. |
- Returns
- The characters read from the socket. The result may have fewer characters than specified by bytes. If the result is an empty string, then the socket has been closed by the peer.
◆ syswrite()
std::string Connection::syswrite |
( |
const std::string & |
data | ) |
|
|
private |
Call the system's write function and try to write all characters in the string data.
May write fewer characters, but will at least write one character.
- Parameters
-
data | A string of characters to write to the socket. |
- Returns
- The rest of the characters that have not yet been written.
◆ get_read_event()
◆ get_write_event()
◆ get_peer_address()
std::string Connection::get_peer_address |
( |
| ) |
|
◆ get_peer_port()
unsigned short Connection::get_peer_port |
( |
| ) |
|
◆ get_fd()
SOCKET MHA_TCP::Connection::get_fd |
( |
| ) |
const |
|
inline |
Return the (protected) file descriptor of the connection.
Will be required for SSL.
◆ eof()
Checks if the peer has closed the connection.
As a side effect, this method fills the internal "incoming" buffer if it was empty and the socket is readable and not eof.
◆ can_read_line()
bool Connection::can_read_line |
( |
char |
delim = '\n' | ) |
|
Checks if a full line of text has arrived by now.
This method reads data from the socket into the internal "incoming" buffer if it can be done without blocking.
- Parameters
-
- Returns
- true if at least one full line of text is present in the internal buffer after this method call, false otherwise.
◆ can_read_bytes()
bool Connection::can_read_bytes |
( |
unsigned |
howmany | ) |
|
Checks if the specified ammount of data can be read.
This method reads data from the socket into an internal "incoming" buffer if it can be done without blocking.
- Parameters
-
howmany | The number of bytes that the caller wants to have checked. |
- Returns
- true if at least the specified ammount of data is present in the internal buffer after this method call, false otherwise
◆ read_line()
std::string Connection::read_line |
( |
char |
delim = '\n' | ) |
|
Reads a single line of data from the socket.
Blocks if necessary.
- Parameters
-
- Returns
- The string of characters in this line, including the trailing delimiter. The delimiter may be missing if the last line before EOF does not have a delimiter.
◆ read_bytes()
std::string Connection::read_bytes |
( |
unsigned |
howmany | ) |
|
Reads the specified ammount of dat from the socket.
Blocks if necessary.
- Parameters
-
howmany | The number of bytes to read. |
- Returns
- The string of characters read. The string may be shorter if EOF is encountered.
◆ try_write()
void Connection::try_write |
( |
const std::string & |
data = "" | ) |
|
Adds data to the internal "outgoing" buffer, and then tries to write as much data from that buffer to the socket as possible without blocking.
- Parameters
-
data | data to send over the socket. |
◆ write()
void Connection::write |
( |
const std::string & |
data = "" | ) |
|
Adds data to the internal "outgoing" buffer, and then writes that that buffer to the socket, regardless of blocking.
- Parameters
-
data | data to send over the socket. |
◆ needs_write()
bool Connection::needs_write |
( |
| ) |
|
Checks if the internal "outgoing" buffer contains data.
◆ buffered_incoming_bytes()
unsigned Connection::buffered_incoming_bytes |
( |
| ) |
const |
Returns the number of bytes in the internal "incoming" buffer.
◆ buffered_outgoing_bytes()
unsigned Connection::buffered_outgoing_bytes |
( |
| ) |
const |
Returns the number of bytes in the internal "outgoing" buffer.
◆ outbuf
std::string MHA_TCP::Connection::outbuf |
|
private |
◆ inbuf
std::string MHA_TCP::Connection::inbuf |
|
private |
◆ read_event
◆ write_event
◆ closed
bool MHA_TCP::Connection::closed |
|
private |
◆ peer_addr
struct sockaddr_in MHA_TCP::Connection::peer_addr |
|
private |
◆ fd
SOCKET MHA_TCP::Connection::fd |
|
protected |
The file descriptor of the TCP Socket.
The documentation for this class was generated from the following files: