Bond's TCP Library
1.0
Bond's TCP Client/Server Library
|
|
Go to the documentation of this file.
22 #include <arpa/inet.h>
23 #include <sys/epoll.h>
36 void error(
string msg);
39 void error(
string label,
string msg);
45 void warning(
string label,
string msg);
51 void log(
string label,
string msg);
58 enum class SocketState {UNCONNECTED=0, LISTENING, CONNECTING, CONNECTED, DISCONNECTED};
82 void poll(
int timeout);
84 static const int MAX_EVENTS = 10;
85 bool add(
Socket& socket,
int events);
86 bool update(
Socket& socket,
int events);
87 bool remove(
Socket& socket);
88 void handleEvents(uint32_t events,
int fd);
90 epoll_event events[MAX_EVENTS];
91 std::map<int,tcp::Socket*> sockets;
108 Socket(
EPoll &epoll,
const int domain = AF_INET,
const int socket = 0,
const bool blocking =
false,
const int events = (EPOLLIN | EPOLLRDHUP));
121 virtual void disconnect();
128 bool setEvents(
int events);
133 virtual void handleEvents(uint32_t events) = 0;
138 virtual void disconnected();
161 DataSocket(
EPoll &epoll,
const int domain = AF_INET,
const int socket = 0,
const bool blocking =
false,
const int events = (EPOLLIN | EPOLLRDHUP)) :
162 Socket(epoll,domain,socket,blocking,events) {}
169 size_t read(
void *buffer,
size_t size);
173 size_t write(
const void *buffer,
size_t size);
178 void readToInputBuffer();
183 void sendOutputBuffer();
187 void canSend(
bool value);
192 void handleEvents(uint32_t events)
override;
196 void disconnect()
override;
201 void disconnected()
override;
206 virtual void dataAvailable() = 0;
216 size_t read_(
void *buffer,
size_t size);
217 size_t write_(
const void *buffer,
size_t size);
218 deque<uint8_t> inputBuffer;
219 deque<uint8_t> outputBuffer;
231 #endif // include guard
void setLogStream(ostream *os)
Set the output stream used by the library for log, warning and error messages.
EPoll & epoll()
Returns a reference to the epoll instance used by this socket.
void error(string msg)
Send an error message to the log stream.
recursive_mutex mtx
The mutex used to provide exclusive access to the socket.
int getDomainFromHostAndPort(const char *host, const char *port, int def_domain)
Tries to determine which address family to use from a host and port string.
SocketState
Determines the state of a socket.
void warning(string msg)
Send a warning message to the log stream.
Represents a buffered socket that can send and receive data using optional SSL encryption.
Encapsulates an SSL connection data structure.
SocketState state_
Descendant classes can manipulate the socket state directly.
size_t available()
Returns the number of bytes available in the inputBuffer.
Encapsulates an openSSL SSL_CTX record.
int socket() const
Return the linux socket handle.
Encapsulates the EPoll interface.
Provides ssl client and server functionality.
int domain() const
Return the socket domain (AF_INET or AF_INET6)
void log(string msg)
Send an log message to the log stream.
A tcp client/server library for linux that supports openSSL and EPoll.
Encapsulates a socket handle that is capable of recieving epoll events.