skstream
|
00001 /************************************************************************** 00002 FreeSockets - Portable C++ classes for IP(sockets) applications. (v0.3) 00003 Copyright (C) 2000-2001 Rafael Guterres Jeffman 00004 (C) 2003-2006 Alistair Riddoch 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 00020 **************************************************************************/ 00021 00029 #ifndef RGJ_FREE_THREADS_SERVER_H_ 00030 #define RGJ_FREE_THREADS_SERVER_H_ 00031 00032 #include <skstream/sksocket.h> // FreeSockets are needed 00033 00035 // class basic_socket_server 00037 00039 class basic_socket_server : public basic_socket { 00040 public: 00041 static const int SK_SRV_NONE = 0; 00042 static const int SK_SRV_PURE = 1 << 0; 00043 static const int SK_SRV_REUSE = 1 << 1; 00044 protected: 00045 SOCKET_TYPE _socket; 00046 int _flags; 00047 private: 00048 basic_socket_server(const basic_socket_server&); 00049 basic_socket_server& operator=(const basic_socket_server&); 00050 00051 protected: 00052 explicit basic_socket_server(SOCKET_TYPE _sock = INVALID_SOCKET, 00053 int flags = SK_SRV_NONE) 00054 : _socket(_sock), _flags(flags) { 00055 startup(); 00056 } 00057 00058 public: 00059 // Destructor 00060 virtual ~basic_socket_server(); 00061 00062 virtual SOCKET_TYPE getSocket() const; 00063 00064 void close(); 00065 void shutdown(); 00066 00068 bool can_accept(); 00069 00070 }; 00071 00073 // class ip_socket_server 00075 00077 class ip_socket_server : public basic_socket_server { 00078 protected: 00079 int bindToAddressInfo(struct addrinfo *); 00080 int bindToIpService(int service, int type, int protocol); 00081 00082 explicit ip_socket_server(SOCKET_TYPE _sock = INVALID_SOCKET, 00083 int flags = SK_SRV_NONE) : 00084 basic_socket_server(_sock, flags) { 00085 } 00086 public: 00087 virtual ~ip_socket_server(); 00088 }; 00089 00091 // class tcp_socket_server 00093 00095 class tcp_socket_server : public ip_socket_server { 00096 public: 00097 explicit tcp_socket_server(int flags = SK_SRV_PURE | 00098 SK_SRV_REUSE) : 00099 ip_socket_server(INVALID_SOCKET, flags) { 00100 } 00101 00102 // Destructor 00103 virtual ~tcp_socket_server(); 00104 00105 SOCKET_TYPE accept(); 00106 00107 int open(int service); 00108 int open(struct addrinfo *); 00109 }; 00110 00112 // class udp_socket_server 00114 00116 class udp_socket_server : public ip_socket_server { 00117 public: 00118 explicit udp_socket_server(int service) { 00119 open(service); 00120 } 00121 00122 // Destructor 00123 virtual ~udp_socket_server(); 00124 00125 int open(int service); 00126 00127 }; 00128 00129 #endif // RGJ_FREE_THREADS_SERVER_H_