#include <TCPServer.h>
Inheritance diagram for oasys::TCPServerThread:
Definition at line 79 of file TCPServer.h.
Public Member Functions | |
TCPServerThread (const char *name, const char *logbase="/oasys/tcpserver", int flags=0, int accept_timeout=-1) | |
virtual void | accepted (int fd, in_addr_t addr, u_int16_t port)=0 |
Virtual callback hook that gets called when new connections arrive. | |
void | run () |
Loop forever, issuing blocking calls to TCPServer::accept(), then calling the accepted() function when new connections arrive. | |
int | bind_listen_start (in_addr_t local_addr, u_int16_t local_port) |
Bind to an address, open the port for listening and start the thread. | |
Protected Attributes | |
int | accept_timeout_ |
If not -1, then call timeout_accept in the main loop. |
oasys::TCPServerThread::TCPServerThread | ( | const char * | name, | |
const char * | logbase = "/oasys/tcpserver" , |
|||
int | flags = 0 , |
|||
int | accept_timeout = -1 | |||
) | [inline] |
Definition at line 81 of file TCPServer.h.
virtual void oasys::TCPServerThread::accepted | ( | int | fd, | |
in_addr_t | addr, | |||
u_int16_t | port | |||
) | [pure virtual] |
Virtual callback hook that gets called when new connections arrive.
Implemented in dtn::APIServer, dtntunnel::TCPTunnel::Listener, oasys::SMTPServer, and dtn::TCPConvergenceLayer::Listener.
Referenced by run().
void oasys::TCPServerThread::run | ( | ) | [virtual] |
Loop forever, issuing blocking calls to TCPServer::accept(), then calling the accepted() function when new connections arrive.
Note that unlike in the Thread base class, this run() method is public in case we don't want to actually create a new thread for this guy, but instead just want to run the main loop.
Implements oasys::Thread.
Definition at line 119 of file TCPServer.cc.
References oasys::TCPServer::accept(), accept_timeout_, accepted(), oasys::IPSocket::close(), errno, oasys::IPSocket::fd(), intoa, oasys::IOTIMEOUT, oasys::LOG_DEBUG, oasys::LOG_ERR, oasys::Logger::logf(), oasys::Thread::should_stop(), and oasys::TCPServer::timeout_accept().
int oasys::TCPServerThread::bind_listen_start | ( | in_addr_t | local_addr, | |
u_int16_t | local_port | |||
) |
Bind to an address, open the port for listening and start the thread.
Most uses of TcpServerThread will simply call these functions in sequence, so this helper function is to merge such redundancy.
Definition at line 160 of file TCPServer.cc.
References oasys::IPSocket::bind(), oasys::TCPServer::listen(), and oasys::Thread::start().
Referenced by dtntunnel::TCPTunnel::Listener::Listener(), dtn::DTND::main(), and oasys::SMTPServer::SMTPServer().
int oasys::TCPServerThread::accept_timeout_ [protected] |
If not -1, then call timeout_accept in the main loop.
This gives a caller a (rough) way to stop the thread by calling set_should_stop() and then waiting for the accept call to timeout, at which point the bit will be checked.
Definition at line 122 of file TCPServer.h.
Referenced by run().