oasys::TCPServerThread Class Reference

#include <TCPServer.h>

Inheritance diagram for oasys::TCPServerThread:

oasys::TCPServer oasys::Thread oasys::IPSocket oasys::Logger oasys::IOHandlerBase dtn::APIServer dtn::TCPConvergenceLayer::Listener dtntunnel::TCPTunnel::Listener oasys::SMTPServer List of all members.

Detailed Description

Simple class that implements a thread of control that loops, blocking on accept(), and issuing the accepted() callback when new connections arrive.

Definition at line 58 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.


Constructor & Destructor Documentation

oasys::TCPServerThread::TCPServerThread ( const char *  name,
const char *  logbase = "/oasys/tcpserver",
int  flags = 0,
int  accept_timeout = -1 
) [inline]

Definition at line 60 of file TCPServer.h.


Member Function Documentation

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 98 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.

Returns:
-1 on error, 0 otherwise.

Definition at line 139 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().


Member Data Documentation

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 101 of file TCPServer.h.

Referenced by run().


The documentation for this class was generated from the following files:
Generated on Thu Jun 7 16:57:00 2007 for DTN Reference Implementation by  doxygen 1.5.1