1 | /* |
---|
2 | The stellarium telescope library helps building |
---|
3 | telescope server programs, that can communicate with stellarium |
---|
4 | by means of the stellarium TCP telescope protocol. |
---|
5 | It also contains smaple server classes (dummy, Meade LX200). |
---|
6 | |
---|
7 | Author and Copyright of this file and of the stellarium telescope library: |
---|
8 | Johannes Gajdosik, 2006 |
---|
9 | |
---|
10 | This library is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU Lesser General Public |
---|
12 | License as published by the Free Software Foundation; either |
---|
13 | version 2.1 of the License, or (at your option) any later version. |
---|
14 | |
---|
15 | This library is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | Lesser General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU Lesser General Public |
---|
21 | License along with this library; if not, write to the Free Software |
---|
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | */ |
---|
24 | |
---|
25 | #ifndef _LISTENER_HPP_ |
---|
26 | #define _LISTENER_HPP_ |
---|
27 | |
---|
28 | #include "Socket2.hpp" |
---|
29 | |
---|
30 | //! Listens for connection attempts and adds new connections to the server. |
---|
31 | //! Every Server object contains an instance of Listener, initialized with |
---|
32 | //! a reference to that Server object and the TCP/IP port used by the server. |
---|
33 | //! Once started, the Listener object listens at the port for connection |
---|
34 | //! attempts. If a TCP/IP connection is established, the listener adds it |
---|
35 | //! to the list of connections maintained by the server. |
---|
36 | class Listener : public Socket2 |
---|
37 | { |
---|
38 | public: |
---|
39 | //! @param port TCP/IP port number |
---|
40 | Listener(Server2 &server, int port) : Socket2(server, INVALID_SOCKET), |
---|
41 | port(port) {} |
---|
42 | |
---|
43 | private: |
---|
44 | //! Checks if the connection is closed. |
---|
45 | //! @returns always false, because if Listener can't listen, |
---|
46 | //! it causes the program to exit with code 127. |
---|
47 | bool isClosed(void) const {return false;} |
---|
48 | //! Prepares TCP/IP communication and tries to start listening. |
---|
49 | //! If it can't listen, it causes the program to exit with code 127. |
---|
50 | void prepareSelectFds(fd_set &read_fds, fd_set &write_fds, int &fd_max); |
---|
51 | //! Performs TCP/IP communication and handles new connections. |
---|
52 | //! If a new connection is established, creates a new Connection object |
---|
53 | //! and passes it to the parent Server with Server::addConnection(). |
---|
54 | void handleSelectFds(const fd_set &read_fds, const fd_set &write_fds); |
---|
55 | |
---|
56 | private: |
---|
57 | const int port; |
---|
58 | }; |
---|
59 | |
---|
60 | #endif |
---|