00001 /* 00002 * Copyright (C) 2003-2009 Olivier Boudeville 00003 * 00004 * This file is part of the Ceylan library. 00005 * 00006 * The Ceylan library is free software: you can redistribute it and/or modify 00007 * it under the terms of either the GNU Lesser General Public License or 00008 * the GNU General Public License, as they are published by the Free Software 00009 * Foundation, either version 3 of these Licenses, or (at your option) 00010 * any later version. 00011 * 00012 * The Ceylan library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License and the GNU General Public License 00016 * for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License and the GNU General Public License along with the Ceylan library. 00020 * If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * Author: Olivier Boudeville (olivier.boudeville@esperide.com) 00023 * 00024 */ 00025 00026 00027 #ifndef CEYLAN_MULTIPLEXED_SERVER_STREAM_SOCKET_H_ 00028 #define CEYLAN_MULTIPLEXED_SERVER_STREAM_SOCKET_H_ 00029 00030 00031 00032 #include "CeylanServerStreamSocket.h" // for inheritance 00033 #include "CeylanSystem.h" // for FileDescriptor 00034 00035 #include <string> 00036 #include <set> // for _currentConnections 00037 00038 00039 00040 namespace Ceylan 00041 { 00042 00043 00044 namespace Network 00045 { 00046 00047 00048 00050 class AnonymousStreamSocket ; 00051 00052 00053 00091 class CEYLAN_DLL MultiplexedServerStreamSocket: 00092 public ServerStreamSocket 00093 { 00094 00095 00096 00097 public: 00098 00099 00100 00106 class CEYLAN_DLL MultiplexedServerStreamSocketException: 00107 public ServerStreamSocketException 00108 { 00109 public: 00110 00111 explicit MultiplexedServerStreamSocketException( 00112 const std::string & reason ) ; 00113 00114 virtual ~MultiplexedServerStreamSocketException() 00115 throw() ; 00116 00117 } ; 00118 00119 00120 00126 class NetworkServerShutdownException: 00127 public MultiplexedServerStreamSocketException 00128 { 00129 00130 public: 00131 00132 explicit NetworkServerShutdownException( 00133 const std::string & reason ) ; 00134 00135 virtual ~NetworkServerShutdownException() throw() ; 00136 00137 } ; 00138 00139 00140 00154 explicit MultiplexedServerStreamSocket( Port listeningPort, 00155 bool reuse = true ) ; 00156 00157 00158 00160 virtual ~MultiplexedServerStreamSocket() throw() ; 00161 00162 00163 00169 virtual bool isConnected() const ; 00170 00171 00172 00183 virtual void run() ; 00184 00185 00186 00206 virtual AnonymousStreamSocket * accept() ; 00207 00208 00209 00262 virtual bool handleConnection( 00263 AnonymousStreamSocket & connection ) = 0 ; 00264 00265 00266 00274 virtual void closeConnection( 00275 AnonymousStreamSocket & connection ) ; 00276 00277 00278 00291 virtual const std::string toString( 00292 Ceylan::VerbosityLevels level = Ceylan::high ) const ; 00293 00294 00295 00296 00297 protected: 00298 00299 00312 virtual bool closeAcceptedConnections() ; 00313 00314 00315 /* 00316 * Takes care of the awful issue of Windows DLL with templates. 00317 * 00318 * @see Ceylan's developer guide and README-build-for-windows.txt 00319 * to understand it, and to be aware of the associated risks. 00320 * 00321 */ 00322 #pragma warning( push ) 00323 #pragma warning( disable: 4251 ) 00324 00334 std::set<AnonymousStreamSocket *> _currentConnections ; 00335 00336 #pragma warning( pop ) 00337 00338 00339 00340 private: 00341 00342 00351 MultiplexedServerStreamSocket( 00352 const MultiplexedServerStreamSocket & source ) ; 00353 00354 00355 00364 MultiplexedServerStreamSocket & operator = ( 00365 const MultiplexedServerStreamSocket & source ) ; 00366 00367 00368 } ; 00369 00370 } 00371 00372 } 00373 00374 00375 00376 #endif // CEYLAN_MULTIPLEXED_SERVER_STREAM_SOCKET_H_ 00377