blob: c3c8fafdd803dbdb5ee81d6c2f8952533204ed21 [file] [log] [blame]
Constantin Kaplinsky729598c2006-05-25 05:12:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software 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
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19// -=- SocketManager.h
20
21// Socket manager class for Win32.
22// Passed a network::SocketListener and a network::SocketServer when
23// constructed. Uses WSAAsyncSelect to get notifications of network
24// connection attempts. When an incoming connection is received,
25// the manager will call network::SocketServer::addClient(). If
26// addClient returns true then the manager registers interest in
27// network events on that socket, and calls
28// network::SocketServer::processSocketEvent().
29
30#ifndef __RFB_WIN32_SOCKET_MGR_H__
31#define __RFB_WIN32_SOCKET_MGR_H__
32
33#include <map>
34#include <network/Socket.h>
35#include <rfb_win32/EventManager.h>
36
37namespace rfb {
38 namespace win32 {
39
40 class SocketManager : public EventManager, EventHandler {
41 public:
42 SocketManager();
43 virtual ~SocketManager();
44
45 // AddressChangeNotifier callback interface
46 // If an object implementing this is passed to addListener then it will be
47 // called whenever the SocketListener's address list changes
48 class AddressChangeNotifier {
49 public:
50 virtual ~AddressChangeNotifier() {}
Pierre Ossman79f82f92015-03-17 13:44:00 +010051 virtual void processAddressChange() = 0;
Constantin Kaplinsky729598c2006-05-25 05:12:25 +000052 };
53
54 // Add a listening socket. Incoming connections will be added to the supplied
55 // SocketServer.
56 void addListener(network::SocketListener* sock_,
57 network::SocketServer* srvr,
58 AddressChangeNotifier* acn = 0);
59
60 // Remove and delete a listening socket.
61 void remListener(network::SocketListener* sock);
62
63 // Add an already-connected socket. Socket events will cause the supplied
64 // SocketServer to be called. The socket must ALREADY BE REGISTERED with
65 // the SocketServer.
66 void addSocket(network::Socket* sock_, network::SocketServer* srvr, bool outgoing=true);
67
68 protected:
69 virtual int checkTimeouts();
70 virtual void processEvent(HANDLE event);
71 virtual void remSocket(network::Socket* sock);
72
73 struct ConnInfo {
74 network::Socket* sock;
75 network::SocketServer* server;
76 };
77 struct ListenInfo {
78 network::SocketListener* sock;
79 network::SocketServer* server;
80 AddressChangeNotifier* notifier;
81 };
82 std::map<HANDLE, ListenInfo> listeners;
83 std::map<HANDLE, ConnInfo> connections;
84 };
85
86 }
87
88}
89
90#endif