You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SocketManager.h 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* 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. // -=- SocketManager.h
  19. // Socket manager class for Win32.
  20. // Passed a network::SocketListener and a network::SocketServer when
  21. // constructed. Uses WSAAsyncSelect to get notifications of network
  22. // connection attempts. When an incoming connection is received,
  23. // the manager will call network::SocketServer::addClient(). If
  24. // addClient returns true then the manager registers interest in
  25. // network events on that socket, and calls
  26. // network::SocketServer::processSocketEvent().
  27. #ifndef __RFB_WIN32_SOCKET_MGR_H__
  28. #define __RFB_WIN32_SOCKET_MGR_H__
  29. #include <map>
  30. #include <network/Socket.h>
  31. #include <rfb_win32/EventManager.h>
  32. namespace rfb {
  33. namespace win32 {
  34. class SocketManager : public EventManager, EventHandler {
  35. public:
  36. SocketManager();
  37. virtual ~SocketManager();
  38. // AddressChangeNotifier callback interface
  39. // If an object implementing this is passed to addListener then it will be
  40. // called whenever the SocketListener's address list changes
  41. class AddressChangeNotifier {
  42. public:
  43. virtual ~AddressChangeNotifier() {}
  44. virtual void processAddressChange() = 0;
  45. };
  46. // Add a listening socket. Incoming connections will be added to the supplied
  47. // SocketServer.
  48. void addListener(network::SocketListener* sock_,
  49. network::SocketServer* srvr,
  50. AddressChangeNotifier* acn = 0);
  51. // Remove and delete a listening socket.
  52. void remListener(network::SocketListener* sock);
  53. // Add an already-connected socket. Socket events will cause the supplied
  54. // SocketServer to be called. The socket must ALREADY BE REGISTERED with
  55. // the SocketServer.
  56. void addSocket(network::Socket* sock_, network::SocketServer* srvr, bool outgoing=true);
  57. bool getDisable(network::SocketServer* srvr);
  58. void setDisable(network::SocketServer* srvr, bool disable);
  59. protected:
  60. virtual int checkTimeouts();
  61. virtual void processEvent(HANDLE event);
  62. virtual void remSocket(network::Socket* sock);
  63. struct ConnInfo {
  64. network::Socket* sock;
  65. network::SocketServer* server;
  66. };
  67. struct ListenInfo {
  68. network::SocketListener* sock;
  69. network::SocketServer* server;
  70. AddressChangeNotifier* notifier;
  71. bool disable;
  72. };
  73. std::map<HANDLE, ListenInfo> listeners;
  74. std::map<HANDLE, ConnInfo> connections;
  75. };
  76. }
  77. }
  78. #endif