TCPServer.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
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 } // namespace oasys
00105                         
00106 #endif /* _OASYS_TCP_SERVER_H_ */

Generated on Thu Jun 7 16:56:52 2007 for DTN Reference Implementation by  doxygen 1.5.1