00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _OASYS_TCP_SERVER_H_
00019 #define _OASYS_TCP_SERVER_H_
00020
00021 #include "IPSocket.h"
00022 #include "../thread/Thread.h"
00023
00024 namespace oasys {
00025
00031 class TCPServer : public IPSocket {
00032 public:
00033 TCPServer(const char* logbase = "/oasys/tcpserver");
00034
00036
00037 int listen();
00038 int accept(int *fd, in_addr_t *addr, u_int16_t *port);
00040
00047 int timeout_accept(int *fd, in_addr_t *addr, u_int16_t *port,
00048 int timeout_ms);
00049 };
00050
00058 class TCPServerThread : public TCPServer, public Thread {
00059 public:
00060 TCPServerThread(const char* name, const char* logbase = "/oasys/tcpserver",
00061 int flags = 0, int accept_timeout = -1)
00062 : TCPServer(logbase), Thread(name, flags),
00063 accept_timeout_(accept_timeout)
00064 {
00065 }
00066
00071 virtual void accepted(int fd, in_addr_t addr, u_int16_t port) = 0;
00072
00082 void run();
00083
00094 int bind_listen_start(in_addr_t local_addr, u_int16_t local_port);
00095
00096 protected:
00101 int accept_timeout_;
00102 };
00103
00104 }
00105
00106 #endif