00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _SOCKETS_ISocketHandler_H
00031 #define _SOCKETS_ISocketHandler_H
00032 #include "sockets-config.h"
00033
00034 #include <map>
00035 #include <list>
00036
00037 #include "socket_include.h"
00038 #include "StdLog.h"
00039 #include "Mutex.h"
00040 #include "Socket.h"
00041
00042 #ifdef SOCKETS_NAMESPACE
00043 namespace SOCKETS_NAMESPACE {
00044 #endif
00045
00046 typedef enum {
00047 LIST_CALLONCONNECT = 0,
00048 #ifdef ENABLE_DETACH
00049 LIST_DETACH,
00050 #endif
00051 LIST_TIMEOUT,
00052 LIST_RETRY,
00053 LIST_CLOSE
00054 } list_t;
00055
00056 class SocketAddress;
00057
00058
00061 class ISocketHandler
00062 {
00063 friend class Socket;
00064
00065 public:
00068 #ifdef ENABLE_POOL
00069 class PoolSocket : public Socket
00070 {
00071 public:
00072 PoolSocket(ISocketHandler& h,Socket *src) : Socket(h) {
00073 CopyConnection( src );
00074 SetIsClient();
00075 }
00076
00077 void OnRead() {
00078 Handler().LogError(this, "OnRead", 0, "data on hibernating socket", LOG_LEVEL_FATAL);
00079 SetCloseAndDelete();
00080 }
00081 void OnOptions(int,int,int,SOCKET) {}
00082
00083 };
00084 #endif
00085
00086 public:
00087 virtual ~ISocketHandler() {}
00088
00090 virtual Mutex& GetMutex() const = 0;
00091
00094 virtual void RegStdLog(StdLog *log) = 0;
00095
00097 virtual void LogError(Socket *p,const std::string& user_text,int err,const std::string& sys_err,loglevel_t t = LOG_LEVEL_WARNING) = 0;
00098
00099
00100
00101
00103 virtual void Add(Socket *) = 0;
00104 private:
00106 virtual void Remove(Socket *) = 0;
00107 public:
00109 virtual void Get(SOCKET s,bool& r,bool& w,bool& e) = 0;
00111 virtual void Set(SOCKET s,bool bRead,bool bWrite,bool bException = true) = 0;
00112
00114 virtual int Select(long sec,long usec) = 0;
00116 virtual int Select() = 0;
00118 virtual int Select(struct timeval *tsel) = 0;
00119
00121 virtual bool Valid(Socket *) = 0;
00123 virtual size_t GetCount() = 0;
00124
00127 virtual bool OkToAccept(Socket *p) = 0;
00128
00130 virtual void AddList(SOCKET s,list_t which_one,bool add) = 0;
00131
00132
00133
00134
00135 #ifdef ENABLE_POOL
00136
00137 virtual ISocketHandler::PoolSocket *FindConnection(int type,const std::string& protocol,SocketAddress&) = 0;
00139 virtual void EnablePool(bool = true) = 0;
00142 virtual bool PoolEnabled() = 0;
00143 #endif // ENABLE_POOL
00144
00145
00146
00147
00148 #ifdef ENABLE_SOCKS4
00149
00150 virtual void SetSocks4Host(ipaddr_t) = 0;
00152 virtual void SetSocks4Host(const std::string& ) = 0;
00154 virtual void SetSocks4Port(port_t) = 0;
00156 virtual void SetSocks4Userid(const std::string& ) = 0;
00158 virtual void SetSocks4TryDirect(bool = true) = 0;
00161 virtual ipaddr_t GetSocks4Host() = 0;
00164 virtual port_t GetSocks4Port() = 0;
00167 virtual const std::string& GetSocks4Userid() = 0;
00170 virtual bool Socks4TryDirect() = 0;
00171 #endif // ENABLE_SOCKS4
00172
00173
00174
00175
00176 #ifdef ENABLE_RESOLVER
00177
00179 virtual void EnableResolver(port_t = 16667) = 0;
00182 virtual bool ResolverEnabled() = 0;
00186 virtual int Resolve(Socket *,const std::string& host,port_t port) = 0;
00187 #ifdef ENABLE_IPV6
00188 virtual int Resolve6(Socket *,const std::string& host,port_t port) = 0;
00189 #endif
00190
00191 virtual int Resolve(Socket *,ipaddr_t a) = 0;
00192 #ifdef ENABLE_IPV6
00193 virtual int Resolve(Socket *,in6_addr& a) = 0;
00194 #endif
00195
00196 virtual port_t GetResolverPort() = 0;
00198 virtual bool ResolverReady() = 0;
00199 #endif // ENABLE_RESOLVER
00200
00201 #ifdef ENABLE_TRIGGERS
00202
00203 virtual int TriggerID(Socket *src) = 0;
00205 virtual bool Subscribe(int id, Socket *dst) = 0;
00207 virtual bool Unsubscribe(int id, Socket *dst) = 0;
00213 virtual void Trigger(int id, Socket::TriggerData& data, bool erase = true) = 0;
00214 #endif // ENABLE_TRIGGERS
00215
00216 #ifdef ENABLE_DETACH
00217
00218 virtual void SetSlave(bool x = true) = 0;
00220 virtual bool IsSlave() = 0;
00221 #endif // ENABLE_DETACH
00222
00223 };
00224
00225
00226 #ifdef SOCKETS_NAMESPACE
00227 }
00228 #endif
00229
00230 #endif // _SOCKETS_ISocketHandler_H