File indexing completed on 2024-05-05 17:50:10
0001 /* 0002 Copyright (C) 2013 Andreas Hartmetz <ahartmetz@gmail.com> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LGPL. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 0019 Alternatively, this file is available under the Mozilla Public License 0020 Version 1.1. You may obtain a copy of the License at 0021 http://www.mozilla.org/MPL/ 0022 */ 0023 0024 #ifndef ISERVER_H 0025 #define ISERVER_H 0026 0027 #include "iioeventlistener.h" 0028 #include "platform.h" 0029 #include "types.h" 0030 0031 #include <deque> 0032 0033 class ConnectAddress; 0034 class EventDispatcher; 0035 class ITransport; 0036 class ICompletionListener; 0037 0038 class IServer : public IIoEventListener 0039 { 0040 public: 0041 IServer(); // TODO event dispatcher as constructor argument? 0042 ~IServer() override; 0043 0044 virtual bool isListening() const = 0; 0045 0046 void setNewConnectionListener(ICompletionListener *listener); // notified once on every new connection 0047 0048 ITransport *takeNextClient(); 0049 void close(); 0050 0051 // listenAddress may be a concrete address (in which case *concreteAddress will be set to a copy of it) 0052 // or it may be a "listen-only address", which is an underspecified or wildcard address. In the latter 0053 // case, *concreteAddress will be set to a concrete address generated according to listenAddress. 0054 static IServer *create(const ConnectAddress &listenAddress, ConnectAddress *concreteAddress); 0055 0056 protected: 0057 virtual void platformClose() = 0; 0058 0059 friend class EventDispatcher; 0060 // handleCanRead() and handleCanWrite() from IioEventListener stay pure virtual 0061 0062 std::deque<ITransport *> m_incomingConnections; 0063 ICompletionListener *m_newConnectionListener; 0064 }; 0065 0066 #endif // ISERVER_H