28 #ifndef UR_CLIENT_LIBRARY_TCP_SERVER_H_INCLUDED 29 #define UR_CLIENT_LIBRARY_TCP_SERVER_H_INCLUDED 32 #include <sys/socket.h> 33 #include <sys/types.h> 125 bool write(
const int fd,
const uint8_t* buf,
const size_t buf_len,
size_t& written);
194 #endif // ifndef UR_CLIENT_LIBRARY_TCP_SERVER_H_INCLUDED void setDisconnectCallback(std::function< void(const int)> func)
This callback will be triggered on clients disconnecting from the server.
void setMaxClientsAllowed(const uint32_t &max_clients_allowed)
Set the maximum number of clients allowed to connect to this server.
std::thread worker_thread_
void setConnectCallback(std::function< void(const int)> func)
This callback will be triggered on clients connecting to the server.
std::vector< int > client_fds_
Wrapper class for a TCP socket server.
void spin()
Event handler. Blocks until activity on any client or connection attempt.
std::atomic< int > listen_fd_
void start()
Start event handling.
void handleDisconnect(const int fd)
void readData(const int fd)
read data from socket
void shutdown()
Shut down the event listener thread. After calling this, no events will be handled anymore...
char input_buffer_[INPUT_BUFFER_SIZE]
std::function< void(const int)> disconnect_callback_
std::atomic< bool > keep_running_
uint32_t getMaxClientsAllowed() const
Get the maximum number of clients allowed to connect to this server.
void worker()
Runs spin() as long as keep_running_ is set to true.
uint32_t max_clients_allowed_
bool write(const int fd, const uint8_t *buf, const size_t buf_len, size_t &written)
Writes to a client.
static const int INPUT_BUFFER_SIZE
void handleConnect()
Handles connection events.
void setMessageCallback(std::function< void(const int, char *)> func)
This callback will be triggered on messages received on the socket.
std::function< void(const int, char *buffer)> message_callback_
std::function< void(const int)> new_connection_callback_