19typedef void (*conn_iter_func) (
sock& conn,
void* param);
24 tcpserver (
unsigned short port,
const std::string&
name = std::string (),
25 unsigned int max_conn = 0);
46 void maxconn (
unsigned int new_max);
54 bool init ()
override;
73 std::vector<conndata> contab;
79 std::function<int (
const sock& s)> connfunc;
93 return contab.size ();
105 return (idle == INFINITE) ? 0 : idle;
116 idle = msec ? msec : INFINITE;
Event objects that reset automatically after a successful wait.
Definition event.h:47
Lightweight inter-thread synchronization.
Definition critsect.h:25
void signal()
Set event to signaled state.
Definition event.h:19
sockaddr wrapper
Definition inaddr.h:23
Encapsulation of a Windows socket.
Definition wsockstream.h:27
multi-threaded TCP server.
Definition tcpserver.h:22
sock & socket()
Provides access to server listening socket.
Definition tcpserver.h:85
void run() override
Run loop.
Definition tcpserver.cpp:122
virtual void termconn(sock &conn_sock, thread *thread)
Finalizes a connection.
Definition tcpserver.cpp:293
~tcpserver()
Terminate any connection that still exists.
Definition tcpserver.cpp:83
unsigned int maxconn() const
Return maximum number of connections accepted.
Definition tcpserver.h:122
void set_connfunc(std::function< int(const sock &)> f)
Set function object that becomes the body of the thread serving a new connection.
Definition tcpserver.cpp:252
void close_connection(const sock &conn_sock)
Closes a connection.
Definition tcpserver.cpp:207
bool init() override
Binds the server socket to listening address and places it in listen mode.
Definition tcpserver.cpp:95
virtual void initconn(sock &conn_sock, thread *thread)
Initializes a connection.
Definition tcpserver.cpp:236
thread * get_connection_thread(const sock &conn_sock)
Return the thread servicing a connection.
Definition tcpserver.cpp:335
size_t numconn() const
Return number of active connections.
Definition tcpserver.h:91
virtual thread * make_thread(sock &conn_sock)
Return a servicing thread for each connection.
Definition tcpserver.cpp:269
void terminate()
Terminate the tcp server.
Definition tcpserver.cpp:349
unsigned int timeout() const
Return max interval to wait for an incoming connection (in milliseconds)
Definition tcpserver.h:103
virtual bool idle_action()
Called periodically from run loop.
Definition tcpserver.h:134
Wrapper for a Windows thread.
Definition thread.h:15
bool is_running() const
Return true if thread is running.
Definition thread.h:144
virtual const std::string & name() const
Return object's name.
Definition syncbase.h:60
criticalsection and lock classes
Definition of inaddr class.
void(* conn_iter_func)(sock &conn, void *param)
Connections iteration function.
Definition tcpserver.h:19
Definition of sock and sockstream classes.