source: BAORadio/libindi/libindi/Indi_Stellarium/src/Listener.hpp @ 623

Last change on this file since 623 was 623, checked in by frichard, 13 years ago
File size: 2.4 KB
Line 
1/*
2The stellarium telescope library helps building
3telescope server programs, that can communicate with stellarium
4by means of the stellarium TCP telescope protocol.
5It also contains smaple server classes (dummy, Meade LX200).
6
7Author and Copyright of this file and of the stellarium telescope library:
8Johannes Gajdosik, 2006
9
10This library is free software; you can redistribute it and/or
11modify it under the terms of the GNU Lesser General Public
12License as published by the Free Software Foundation; either
13version 2.1 of the License, or (at your option) any later version.
14
15This library is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18Lesser General Public License for more details.
19
20You should have received a copy of the GNU Lesser General Public
21License along with this library; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23*/
24
25#ifndef _LISTENER_HPP_
26#define _LISTENER_HPP_
27
28#include "Socket.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.
36class Listener : public Socket
37{
38public:
39        //! @param port TCP/IP port number
40        Listener(Server &server, int port) : Socket(server, INVALID_SOCKET),
41                                             port(port) {}
42       
43private:
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       
56private:
57        const int port;
58};
59
60#endif
Note: See TracBrowser for help on using the repository browser.