00001 /*************************************************************************** 00002 * Copyright (C) 2001 by Rick L. Vinyard, Jr. * 00003 * rvinyard@cs.nmsu.edu * 00004 * * 00005 * This file is part of the conexus library. * 00006 * * 00007 * The conexus library is free software; you can redistribute it and/or * 00008 * modify it under the terms of the GNU General Public License * 00009 * version 3 as published by the Free Software Foundation. * 00010 * * 00011 * The conexus library is distributed in the hope that it will be * 00012 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * 00013 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU General Public License * 00017 * along with this software. If not see <http://www.gnu.org/licenses/>. * 00018 ***************************************************************************/ 00019 #ifndef IPV4IPV4_TCPSERVER_H 00020 #define IPV4IPV4_TCPSERVER_H 00021 00022 #include <conexus/ipv4_address.h> 00023 #include <conexus/endpointserver.h> 00024 #include <conexus/ipv4_tcp.h> 00025 00034 namespace Conexus 00035 { 00036 00037 namespace IPv4 00038 { 00039 00047 class TCPServer: public Conexus::EndpointServer 00048 { 00049 00050 protected: 00051 00052 TCPServer( uint32_t address, uint16_t port, int backlog ); 00053 00054 TCPServer( const std::string& address, uint16_t port, int backlog ); 00055 00056 public: 00057 typedef ConexusPointer<TCPServer> pointer; 00058 00059 CONEXUS_ENDPOINTSERVER_GENERIC_CREATE(); 00060 00061 static pointer create( uint16_t port = 0, int backlog = 5 ); 00062 00063 static pointer create( uint32_t address, uint16_t port, int backlog = 5 ); 00064 00065 static pointer create( const std::string& address, uint16_t port=0, int backlog = 5 ); 00066 00067 virtual ~TCPServer(); 00068 00069 virtual Address& address(); 00070 00071 virtual void set_address( Address addr ); 00072 00073 int backlog(); 00074 00075 TCP::pointer listener(); 00076 00077 const TCP::pointer listener() const; 00078 00079 void set_reuse_address( bool set=true ); 00080 00081 protected: 00082 TCP::pointer m_listener; 00083 00084 int m_backlog; 00085 00086 virtual void pre_start(); 00087 00088 virtual void post_stop(); 00089 00090 virtual void service_thread_main(); 00091 00092 virtual TCP::pointer create_accepted_endpoint( int fd ); 00093 00094 00095 }; 00096 00097 } // namespace IPv4 00098 00099 } // namespace Conexus 00100 00101 #endif