change log updated
[public/netxms.git] / include / socket_listener.h
CommitLineData
f0718805
VK
1/*
2** NetXMS - Network Management System
3** Copyright (C) 2003-2017 Victor Kirhenshtein
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU Lesser General Public License as published
7** by the Free Software Foundation; either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU Lesser General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: socket_listener.h
20**
21**/
22
23#ifndef _socket_listener_h_
24#define _socket_listener_h_
25
26#include <nms_util.h>
27
28/**
29 * Connection processing result
30 */
31enum ConnectionProcessingResult
32{
33 CPR_COMPLETED = 0,
34 CPR_BACKGROUND = 1
35};
36
37/**
38 * Maximum length of listener name
39 */
40#define MAX_LISTENER_NAME_LEN 64
41
42/**
43 * Socket listener
44 */
45class LIBNETXMS_EXPORTABLE SocketListener
46{
47private:
48 SOCKET m_socketV4;
49 SOCKET m_socketV6;
50 UINT16 m_port;
51 TCHAR *m_listenAddress;
52 bool m_allowV4;
53 bool m_allowV6;
54 bool m_stop;
55 TCHAR m_name[MAX_LISTENER_NAME_LEN];
56 UINT32 m_acceptErrors;
57 UINT32 m_acceptedConnections;
58 UINT32 m_rejectedConnections;
59
60protected:
61 virtual bool isConnectionAllowed(const InetAddress& peer);
62 virtual ConnectionProcessingResult processConnection(SOCKET s, const InetAddress& peer);
63 virtual bool isStopConditionReached();
64
65public:
66 SocketListener(UINT16 port, bool allowV4 = true, bool allowV6 = true);
67 virtual ~SocketListener();
68
69 void enableIPv4(bool enabled) { m_allowV4 = enabled; }
70 void enableIPv6(bool enabled) { m_allowV6 = enabled; }
71 void setName(const TCHAR *name) { _tcslcpy(m_name, name, MAX_LISTENER_NAME_LEN); }
72 void setListenAddress(const TCHAR *addr) { free(m_listenAddress); m_listenAddress = _tcsdup_ex(addr); }
73
74 UINT32 getAcceptErrors() const { return m_acceptErrors; }
75 UINT32 getAcceptedConnections() const { return m_acceptedConnections; }
76 UINT32 getRejectedConnections() const { return m_rejectedConnections; }
77
78 bool initialize();
79 void mainLoop();
80 void shutdown();
81};
82
83#endif /* _socket_listener_h_ */