00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00050 typedef CSocketPoolSocket* (*SocketAllocator)(CSocketPool* pPool);
00051 typedef SocketAllocator LPSocketAllocator;
00052 public:
00053
00054 BOOL Connect(const std::string& rAddress,
00055 unsigned short usPort);
00056
00057
00058 BOOL Connect(const std::string& rAddress,
00059 unsigned short usPort,
00060 CSocketPoolSocket* pSocket);
00061
00062
00063 CSocketPool(int iMaxSockets,
00064 LPSocketAllocator pAllocator,
00065 int iMaxQueue=200);
00066 virtual ~CSocketPool();
00067 private:
00068
00069 typedef std::deque<CSocketPoolSocket*> SocketQueue;
00070
00071
00072 typedef std::map<CSocketPoolSocket::PoolSocketID,CSocketPoolSocket*> SocketMap;
00073 private:
00074
00075 CSocketPool(const CSocketPool& rPool);
00076
00077
00078 void SocketConnected(CSocketPoolSocket* pSocket);
00079
00080
00081 void SocketClosed(CSocketPoolSocket* pSocket);
00082
00083
00084 void CheckQueue();
00085
00086
00087 void Clear();
00088
00089
00090 int m_iMaxSocket;
00091
00092
00093 int m_iActiveSockets;
00094
00095
00096 int m_iMaxBackQueue;
00097
00098
00099 LPSocketAllocator m_pAllocator;
00100
00101
00102 SocketQueue m_aQueue;
00103
00104
00105 SocketMap m_aSocketMap;
00106
00107
00108 CGenericCriticalSection* m_pCSection;
00109
00110
00111 CGenericCriticalSection* m_pCSectionQueue;
00112
00113
00114 BOOL m_bClosing;
00115 };
00116
00117 KOMODIA_NAMESPACE_END
00118
00119 #endif // !defined(AFX_SOCKETPOOL_H__BB880692_C252_4FBC_8FD2_B89833D0F897__INCLUDED_)