skstream
skserver.h
1 /**************************************************************************
2  FreeSockets - Portable C++ classes for IP(sockets) applications. (v0.3)
3  Copyright (C) 2000-2001 Rafael Guterres Jeffman
4  (C) 2003-2006 Alistair Riddoch
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 **************************************************************************/
21 
29 #ifndef RGJ_FREE_THREADS_SERVER_H_
30 #define RGJ_FREE_THREADS_SERVER_H_
31 
32 #include <skstream/sksocket.h> // FreeSockets are needed
33 
35 // class basic_socket_server
37 
40 public:
41  static const int SK_SRV_NONE = 0;
42  static const int SK_SRV_PURE = 1 << 0;
43  static const int SK_SRV_REUSE = 1 << 1;
44 protected:
45  SOCKET_TYPE _socket;
46  int _flags;
47 private:
49  basic_socket_server& operator=(const basic_socket_server&);
50 
51 protected:
52  explicit basic_socket_server(SOCKET_TYPE _sock = INVALID_SOCKET,
53  int flags = SK_SRV_NONE)
54  : _socket(_sock), _flags(flags) {
55  startup();
56  }
57 
58 public:
59  // Destructor
60  virtual ~basic_socket_server();
61 
62  virtual SOCKET_TYPE getSocket() const;
63 
64  void close();
65  void shutdown();
66 
68  bool can_accept();
69 
70 };
71 
73 // class ip_socket_server
75 
78 protected:
79  int bindToAddressInfo(struct addrinfo *);
80  int bindToIpService(int service, int type, int protocol);
81 
82  explicit ip_socket_server(SOCKET_TYPE _sock = INVALID_SOCKET,
83  int flags = SK_SRV_NONE) :
84  basic_socket_server(_sock, flags) {
85  }
86 public:
87  virtual ~ip_socket_server();
88 };
89 
91 // class tcp_socket_server
93 
96 public:
97  explicit tcp_socket_server(int flags = SK_SRV_PURE |
98  SK_SRV_REUSE) :
99  ip_socket_server(INVALID_SOCKET, flags) {
100  }
101 
102  // Destructor
103  virtual ~tcp_socket_server();
104 
105  SOCKET_TYPE accept();
106 
107  int open(int service);
108  int open(struct addrinfo *);
109 };
110 
112 // class udp_socket_server
114 
117 public:
118  explicit udp_socket_server(int service) {
119  open(service);
120  }
121 
122  // Destructor
123  virtual ~udp_socket_server();
124 
125  int open(int service);
126 
127 };
128 
129 #endif // RGJ_FREE_THREADS_SERVER_H_
Base class for anything that encapsulates a socket.
Definition: sksocket.h:79
Base class for anything that encapsulates a listen socket.
Definition: skserver.h:39
Base class for anything that encapsulates an IP listen socket.
Definition: skserver.h:77
Encapsulates a TCP/IP stream listen socket.
Definition: skserver.h:95
bool can_accept()
See if accept() can be called without blocking on it.
Definition: skserver.cpp:108
Encapsulates a UDP/IP datagram listen socket.
Definition: skserver.h:116