Logo
~Sockets~
~Examples~
~Contact~


ISocketHandler.h

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2004-2007  Anders Hedstrom
00007 
00008 This library is made available under the terms of the GNU GPL.
00009 
00010 If you would like to use this library in a closed-source application,
00011 a separate license agreement is available. For information about 
00012 the closed-source license agreement for the C++ sockets library,
00013 please visit http://www.alhem.net/Sockets/license.html and/or
00014 email license@alhem.net.
00015 
00016 This program is free software; you can redistribute it and/or
00017 modify it under the terms of the GNU General Public License
00018 as published by the Free Software Foundation; either version 2
00019 of the License, or (at your option) any later version.
00020 
00021 This program is distributed in the hope that it will be useful,
00022 but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public License
00027 along with this program; if not, write to the Free Software
00028 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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         // Socket stuff
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         // Connection pool
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         // Socks4
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         // DNS resolve server
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
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4