|
NetCpp
v0.2
|
Base abstract class for protocols. More...
#include <abstract_socket.hpp>

Public Member Functions | |
| bool | close () |
| Close the socket. | |
| AbstractSystemSocket * | getSocket () |
| get the socket | |
| int | receive (__buffer buf, std::size_t size) |
| Receive operation. | |
| int | send (__buffer buf, std::size_t size) |
| Send operation. | |
Protected Member Functions | |
| AbstractSocket (const protocol &prot) | |
| Constructor. | |
Private Member Functions | |
| int | __receive (void *buffer, size_t size) |
| Low-level receive. | |
| int | __send (const void *buffer, size_t size) |
| Low-level send. | |
Private Attributes | |
| std::unique_ptr< std::thread > | receive_worker_ |
| Thread for asynchronous receive operations. | |
| std::unique_ptr< std::thread > | send_worker_ |
| Thread for asynchronous send operations. | |
| std::mutex | receive_lock_ |
| Mutex for synchronization with asynchronous receive operations. | |
| std::mutex | send_lock_ |
| Mutex for synchronization with asynchronous send operations. | |
Base abstract class for protocols.
This is the base abstract class for protocols. Any supported protocol must inherit from this class.
Definition at line 76 of file abstract_socket.hpp.
|
inlineprotected |
Constructor.
Constructor is protected because only derived classes can construct this class. The object is constructed through net::createSocket(), which creates a platform-dependent socket.
| the | protocol type |
Definition at line 118 of file abstract_socket.hpp.

|
private |
Low-level receive.
This method is private because it is meant to be used through the other receive() method. Note: it can block the caller, because it continues receiving until the given number of bytes have been received.
| buffer | Pointer to the buffer where received bytes must be stored |
| size | Number of bytes to be received |
| runtime_error | if the read() returns an error |
Definition at line 118 of file abstract_socket.cpp.

|
private |
Low-level send.
This method is private because it is meant to be used through the other send() method. Note: it can block the caller, because it continues writing until the given number of bytes have been written.
| buffer | Pointer to the buffer containing bytes to be written |
| size | Number of bytes to be written |
| runtime_error | if the write() returns 0 or an error |
Definition at line 152 of file abstract_socket.cpp.

|
inline |
Close the socket.
Method to close the socket. Currently, there is no mechanism to re-open a closed socket.
Definition at line 87 of file abstract_socket.hpp.
|
inline |
get the socket
This method is used to let derived classes of AbstractSocket invoke specific protocol-dependent functions (e.g., accept()).
Definition at line 100 of file abstract_socket.hpp.
| int receive | ( | __buffer | buf, |
| std::size_t | size | ||
| ) |
Receive operation.
This function sendsendsensendsendsendcare of synchronization with any other asynchronous operations. Note: it can block the caller, because it calls __receive() which continues receiving until the given number of bytes have been received.
| buf | Pointer where received data must be put |
| size | Size of data to be received |
| runtime_error | in case of too small buffer |
Example of usage: std::array<char, 5> buf; AbstractSocket::receive(net::buffer(b), 3);
Definition at line 51 of file abstract_socket.cpp.

| int send | ( | __buffer | buf, |
| std::size_t | size | ||
| ) |
Send operation.
This function sends data to the socket taking care of synchronization with any other asynchronous operations. Note: it can block the caller, because it calls __send() which continues writing until the given number of bytes have been written.
| buf | Pointer to data to be written |
| size | Size of data to be written |
| runtime_error | in case of too small buffer |
Example of usage: std::array<char, 5> buf; AbstractSocket::send(net::buffer(b), 3);
Definition at line 87 of file abstract_socket.cpp.

|
private |
Mutex for synchronization with asynchronous receive operations.
Definition at line 147 of file abstract_socket.hpp.
|
private |
Thread for asynchronous receive operations.
Definition at line 137 of file abstract_socket.hpp.
|
private |
Mutex for synchronization with asynchronous send operations.
Definition at line 152 of file abstract_socket.hpp.
|
private |
Thread for asynchronous send operations.
Definition at line 142 of file abstract_socket.hpp.