Debian Codegraph @

src/listener.h

raw
1 // Copyright © 2002-2004 Rob Kaper <[email protected]>.
2 // 2010-2015 Sylvain Rochet <[email protected]>
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // version 2 as published by the Free Software Foundation.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; see the file COPYING. If not, see
15 // <http://www.gnu.org/licenses/>.
16
17 #ifndef NETWORK_LISTENER_H
18 #define NETWORK_LISTENER_H
19
20 #include <sys/types.h>
21 #include <sys/socket.h>
22 #include <netdb.h>
23
24 #include <string>
25 #include <vector>
26
27 class ListenPort;
28 class Socket;
29 class MonopdServer;
30
31 #define LISTENQ 1024
32
33 class Listener
34 {
35 public:
36 Listener(MonopdServer *server, const int port);
37 virtual ~Listener();
38
39 Socket *findSocket(int fd);
40
41 void checkActivity();
42
43 Socket *connectSocket(struct addrinfo *addrinfo);
44
45 protected:
46 /*
47 * Add a listen port. Returns -1 on failure, 0 on success.
48 *
49 */
50 int addListenPort(const int port);
51 int addListenFd(const int fd);
52
53 private:
54 /*
55 * May return 0 in case the accept failed.
56 */
57 Socket *acceptSocket(int fd);
58
59 fd_set m_readfdset;
60 fd_set m_writefdset;
61
62 std::vector<Socket *> m_sockets;
63 std::vector<ListenPort *> m_listenPorts;
64
65 MonopdServer *m_server;
66 };
67
68 #endif // NETWORK_LISTENER_H