SocketPool.hGo to the documentation of this file.00001 /* 00002 * Copyright (c) 2002 Barak Weichselbaum <barak@komodia.com> 00003 * All rights reserved. 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 * 00019 * If you would like to receive a copy of this library outside the GNU GPL 00020 * license, contact us for further details. 00021 * 00022 * Contact info: 00023 * Site: http://www.komodia.com 00024 * Email: sales@komodia.com 00025 */ 00026 00027 #if !defined(AFX_SOCKETPOOL_H__BB880692_C252_4FBC_8FD2_B89833D0F897__INCLUDED_) 00028 #define AFX_SOCKETPOOL_H__BB880692_C252_4FBC_8FD2_B89833D0F897__INCLUDED_ 00029 00030 #if _MSC_VER > 1000 00031 #pragma once 00032 #endif // _MSC_VER > 1000 00033 00034 #include "ErrorHandler.h" 00035 00036 #include "SocketPoolSocket.h" 00037 00038 #include <deque> 00039 #include <map> 00040 00041 KOMODIA_NAMESPACE_START 00042 00043 class CGenericCriticalSection; 00044 00045 class CSocketPool : public CErrorHandler 00046 { 00047 friend class CSocketPoolSocket; 00048 public: 00049 //Our allocator 00050 typedef CSocketPoolSocket* (*SocketAllocator)(CSocketPool* pPool); 00051 typedef SocketAllocator LPSocketAllocator; 00052 public: 00053 //Add an address to connect to 00054 BOOL Connect(const std::string& rAddress, 00055 unsigned short usPort); 00056 00057 //Another type of connect 00058 BOOL Connect(const std::string& rAddress, 00059 unsigned short usPort, 00060 CSocketPoolSocket* pSocket); 00061 00062 //Ctor and dtor 00063 CSocketPool(int iMaxSockets, 00064 LPSocketAllocator pAllocator, 00065 int iMaxQueue=200); 00066 virtual ~CSocketPool(); 00067 private: 00068 //Our queue 00069 typedef std::deque<CSocketPoolSocket*> SocketQueue; 00070 00071 //Map of all running sockets 00072 typedef std::map<CSocketPoolSocket::PoolSocketID,CSocketPoolSocket*> SocketMap; 00073 private: 00074 //No copy ctor 00075 CSocketPool(const CSocketPool& rPool); 00076 00077 //A socket is connection 00078 void SocketConnected(CSocketPoolSocket* pSocket); 00079 00080 //A socket is closed 00081 void SocketClosed(CSocketPoolSocket* pSocket); 00082 00083 //Check if we have data in queue 00084 void CheckQueue(); 00085 00086 //Clear all the data 00087 void Clear(); 00088 00089 //Our number of sockets 00090 int m_iMaxSocket; 00091 00092 //Our number of sockets 00093 int m_iActiveSockets; 00094 00095 //Set the maximum back queue 00096 int m_iMaxBackQueue; 00097 00098 //Our allocator 00099 LPSocketAllocator m_pAllocator; 00100 00101 //Our queue 00102 SocketQueue m_aQueue; 00103 00104 //Map of the existing sockets 00105 SocketMap m_aSocketMap; 00106 00107 //Our CS 00108 CGenericCriticalSection* m_pCSection; 00109 00110 //Queue CS 00111 CGenericCriticalSection* m_pCSectionQueue; 00112 00113 //Are we closing 00114 BOOL m_bClosing; 00115 }; 00116 00117 KOMODIA_NAMESPACE_END 00118 00119 #endif // !defined(AFX_SOCKETPOOL_H__BB880692_C252_4FBC_8FD2_B89833D0F897__INCLUDED_) |