Logo
~Sockets~
~Examples~
~Contact~


ISocketHandler Class Reference
[Basic sockets]

Socket container class, event generator. More...

#include <ISocketHandler.h>

Inheritance diagram for ISocketHandler:

Inheritance graph
[legend]
Collaboration diagram for ISocketHandler:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ISocketHandler (StdLog *log)
 ISocketHandler constructor.
 ISocketHandler (Mutex &mutex, StdLog *log)
 ISocketHandler threadsafe constructor.
virtual ~ISocketHandler ()
MutexGetMutex () const
 Get mutex reference for threadsafe operations.
void SetSlave (bool x=true)
 Indicates that the handler runs under SocketThread.
bool IsSlave ()
 Indicates that the handler runs under SocketThread.
void RegStdLog (StdLog *log)
 Register StdLog object for error callback.
void LogError (Socket *p, const std::string &user_text, int err, const std::string &sys_err, loglevel_t t=LOG_LEVEL_WARNING)
 Log error to log class for print out / storage.
virtual void Add (Socket *)=0
 Add socket instance to socket map.
virtual void Get (SOCKET s, bool &r, bool &w, bool &e)=0
 Get status of read/write/exception file descriptor set for a socket.
virtual void Set (SOCKET s, bool bRead, bool bWrite, bool bException=true)=0
 Set read/write/exception file descriptor sets (fd_set).
virtual int Select (long sec, long usec)=0
 Wait for events, generate callbacks.
virtual int Select ()=0
 This method will not return until an event has been detected.
virtual int Select (struct timeval *tsel)=0
 Wait for events, generate callbacks.
virtual bool Valid (Socket *)=0
 Check that a socket really is handled by this socket handler.
virtual size_t GetCount ()=0
 Return number of sockets handled by this handler.
virtual bool OkToAccept (Socket *p)=0
 Override and return false to deny all incoming connections.
virtual void AddList (SOCKET s, list_t which_one, bool add)=0
 Called by Socket when a socket changes state.
virtual ISocketHandler::PoolSocketFindConnection (int type, const std::string &protocol, SocketAddress &)
 Find available open connection (used by connection pool).
virtual void EnablePool (bool=true)
 Enable connection pool (by default disabled).
virtual bool PoolEnabled ()
 Check pool status.
virtual void SetSocks4Host (ipaddr_t)
 Set socks4 server ip that all new tcp sockets should use.
virtual void SetSocks4Host (const std::string &)
 Set socks4 server hostname that all new tcp sockets should use.
virtual void SetSocks4Port (port_t)
 Set socks4 server port number that all new tcp sockets should use.
virtual void SetSocks4Userid (const std::string &)
 Set optional socks4 userid.
virtual void SetSocks4TryDirect (bool=true)
 If connection to socks4 server fails, immediately try direct connection to final host.
virtual ipaddr_t GetSocks4Host ()
 Get socks4 server ip.
virtual port_t GetSocks4Port ()
 Get socks4 port number.
virtual const std::string & GetSocks4Userid ()=0
 Get socks4 userid (optional).
virtual bool Socks4TryDirect ()
 Check status of socks4 try direct flag.
virtual void EnableResolver (port_t=16667)
 Enable asynchronous DNS.
virtual bool ResolverEnabled ()
 Check resolver status.
virtual int Resolve (Socket *, const std::string &host, port_t port)
 Queue a dns request.
virtual int Resolve (Socket *, ipaddr_t a)
 Do a reverse dns lookup.
virtual port_t GetResolverPort ()
 Get listen port of asynchronous dns server.
virtual bool ResolverReady ()
 Resolver thread ready for queries.

Protected Attributes

StdLogm_stdlog
 Registered log class, or NULL.
bool m_slave
 Indicates that this is a ISocketHandler run in SocketThread.
Mutexm_mutex
 Thread safety mutex.
bool m_b_use_mutex
 Mutex correctly initialized.

Private Member Functions

virtual void Remove (Socket *)=0
 Remove socket from socket map, used by Socket class.

Friends

class Socket

Classes

class  PoolSocket
 Connection pool class for internal use by the ISocketHandler. More...

Detailed Description

Socket container class, event generator.

Definition at line 61 of file ISocketHandler.h.


Constructor & Destructor Documentation

ISocketHandler::ISocketHandler ( StdLog log  ) 

ISocketHandler constructor.

Parameters:
log Optional log class pointer

Definition at line 45 of file ISocketHandler.cpp.

00046 : m_stdlog(log)
00047 #ifdef ENABLE_DETACH
00048 , m_slave(false)
00049 #endif
00050 , m_mutex(m_mutex)
00051 , m_b_use_mutex(false)
00052 {
00053 }

ISocketHandler::ISocketHandler ( Mutex mutex,
StdLog log 
)

ISocketHandler threadsafe constructor.

Parameters:
mutex Externally declared mutex variable
log Optional log class pointer

Definition at line 56 of file ISocketHandler.cpp.

00057 : m_stdlog(log)
00058 #ifdef ENABLE_DETACH
00059 , m_slave(false)
00060 #endif
00061 , m_mutex(mutex)
00062 , m_b_use_mutex(true)
00063 {
00064 }

ISocketHandler::~ISocketHandler (  )  [virtual]

Definition at line 67 of file ISocketHandler.cpp.

00068 {
00069 }


Member Function Documentation

Mutex & ISocketHandler::GetMutex (  )  const

Get mutex reference for threadsafe operations.

Definition at line 72 of file ISocketHandler.cpp.

References m_mutex.

00073 {
00074         return m_mutex; 
00075 }

void ISocketHandler::SetSlave ( bool  x = true  ) 

Indicates that the handler runs under SocketThread.

Definition at line 79 of file ISocketHandler.cpp.

References m_slave.

Referenced by Socket::SocketThread::Run().

00080 {
00081         m_slave = x;
00082 }

bool ISocketHandler::IsSlave (  ) 

Indicates that the handler runs under SocketThread.

Definition at line 85 of file ISocketHandler.cpp.

References m_slave.

00086 {
00087         return m_slave;
00088 }

void ISocketHandler::RegStdLog ( StdLog log  ) 

Register StdLog object for error callback.

Parameters:
log Pointer to log class

Definition at line 92 of file ISocketHandler.cpp.

References m_stdlog.

00093 {
00094         m_stdlog = log;
00095 }

void ISocketHandler::LogError ( Socket p,
const std::string &  user_text,
int  err,
const std::string &  sys_err,
loglevel_t  t = LOG_LEVEL_WARNING 
)

Log error to log class for print out / storage.

Definition at line 98 of file ISocketHandler.cpp.

References m_stdlog.

Referenced by SocketHandler::Add(), SctpSocket::AddAddress(), SctpSocket::AddConnection(), HttpPostSocket::AddFile(), UdpSocket::AddMulticastMembership(), UdpSocket::Bind(), SctpSocket::Bind(), Socket::CheckConnect(), Socket::Close(), Socket::CreateSocket(), HttpdSocket::datetime2httpdate(), UdpSocket::DropMulticastMembership(), Socket::GetClientRemoteAddress(), SctpSocket::getladdrs(), UdpSocket::GetMulticastTTL(), SctpSocket::getpaddrs(), Socket::GetPort(), Socket::GetRemoteIP4(), TcpSocket::GetSsl(), TcpSocket::GetSslContext(), HttpGetSocket::HttpGetSocket(), HttpDebugSocket::Init(), TcpSocket::InitializeContext(), TcpSocket::InitSSLServer(), UdpSocket::IsBroadcast(), UdpSocket::IsMulticastLoop(), HttpClientSocket::OnData(), ResolvSocket::OnDetached(), Socket::OnException(), HttpClientSocket::OnFirst(), UdpSocket::OnRead(), TcpSocket::OnRead(), SctpSocket::OnRead(), TcpSocket::OnResolved(), Socket::OnSocks4Connect(), TcpSocket::OnSocks4ConnectFailed(), Socket::OnSocks4ConnectFailed(), TcpSocket::OnSocks4Read(), Socket::OnSocks4Read(), TcpSocket::OnWrite(), UdpSocket::Open(), TcpSocket::Open(), SctpSocket::Open(), SctpSocket::PeelOff(), CircularBuffer::Read(), SocketHandler::Remove(), SctpSocket::RemoveAddress(), SocketHandler::Resolve(), SocketHandler::Select(), UdpSocket::SendBuf(), TcpSocket::SendBuf(), UdpSocket::SendToBuf(), UdpSocket::SetBroadcast(), Socket::SetClientRemoteAddress(), HttpPutSocket::SetFile(), UdpSocket::SetMulticastLoop(), UdpSocket::SetMulticastTTL(), Socket::SetNonblocking(), TcpSocket::SSLNegotiate(), HTTPSocket::url_this(), CircularBuffer::Write(), and TcpSocket::~TcpSocket().

00099 {
00100         if (m_stdlog)
00101         {
00102                 m_stdlog -> error(this, p, user_text, err, sys_err, t);
00103         }
00104 }

virtual void ISocketHandler::Add ( Socket  )  [pure virtual]

Add socket instance to socket map.

Removal is always automatic.

Implemented in EventHandler, and SocketHandler.

Referenced by MinderSocket::OnLine(), TcpSocket::OnResolved(), and SctpSocket::PeelOff().

virtual void ISocketHandler::Remove ( Socket  )  [private, pure virtual]

Remove socket from socket map, used by Socket class.

Implemented in SocketHandler.

Referenced by Socket::~Socket().

virtual void ISocketHandler::Get ( SOCKET  s,
bool &  r,
bool &  w,
bool &  e 
) [pure virtual]

Get status of read/write/exception file descriptor set for a socket.

Implemented in SocketHandler.

Referenced by TcpSocket::OnWrite().

virtual void ISocketHandler::Set ( SOCKET  s,
bool  bRead,
bool  bWrite,
bool  bException = true 
) [pure virtual]

Set read/write/exception file descriptor sets (fd_set).

Implemented in SocketHandler.

Referenced by Socket::Set().

virtual int ISocketHandler::Select ( long  sec,
long  usec 
) [pure virtual]

Wait for events, generate callbacks.

Implemented in SocketHandler.

virtual int ISocketHandler::Select (  )  [pure virtual]

This method will not return until an event has been detected.

Implemented in SocketHandler.

virtual int ISocketHandler::Select ( struct timeval *  tsel  )  [pure virtual]

Wait for events, generate callbacks.

Implemented in SocketHandler.

virtual bool ISocketHandler::Valid ( Socket  )  [pure virtual]

Check that a socket really is handled by this socket handler.

Implemented in SocketHandler.

virtual size_t ISocketHandler::GetCount (  )  [pure virtual]

Return number of sockets handled by this handler.

Implemented in SocketHandler.

virtual bool ISocketHandler::OkToAccept ( Socket p  )  [pure virtual]

Override and return false to deny all incoming connections.

Parameters:
p ListenSocket class pointer (use GetPort to identify which one)

Implemented in SocketHandler.

virtual void ISocketHandler::AddList ( SOCKET  s,
list_t  which_one,
bool  add 
) [pure virtual]

virtual ISocketHandler::PoolSocket* ISocketHandler::FindConnection ( int  type,
const std::string &  protocol,
SocketAddress  
) [inline, virtual]

Find available open connection (used by connection pool).

Reimplemented in SocketHandler.

Definition at line 150 of file ISocketHandler.h.

Referenced by TcpSocket::Open().

00150                                                                                                             {
00151                 return NULL;
00152         }

virtual void ISocketHandler::EnablePool ( bool  = true  )  [inline, virtual]

Enable connection pool (by default disabled).

Reimplemented in SocketHandler.

Definition at line 154 of file ISocketHandler.h.

00154 {}

virtual bool ISocketHandler::PoolEnabled (  )  [inline, virtual]

Check pool status.

Returns:
true if connection pool is enabled

Reimplemented in SocketHandler.

Definition at line 157 of file ISocketHandler.h.

00157                                    {
00158                 return false;
00159         }

virtual void ISocketHandler::SetSocks4Host ( ipaddr_t   )  [inline, virtual]

Set socks4 server ip that all new tcp sockets should use.

Reimplemented in SocketHandler.

Definition at line 167 of file ISocketHandler.h.

00167 {}

virtual void ISocketHandler::SetSocks4Host ( const std::string &   )  [inline, virtual]

Set socks4 server hostname that all new tcp sockets should use.

Reimplemented in SocketHandler.

Definition at line 169 of file ISocketHandler.h.

00169 {}

virtual void ISocketHandler::SetSocks4Port ( port_t   )  [inline, virtual]

Set socks4 server port number that all new tcp sockets should use.

Reimplemented in SocketHandler.

Definition at line 171 of file ISocketHandler.h.

00171 {};

virtual void ISocketHandler::SetSocks4Userid ( const std::string &   )  [inline, virtual]

Set optional socks4 userid.

Reimplemented in SocketHandler.

Definition at line 173 of file ISocketHandler.h.

00173 {}

virtual void ISocketHandler::SetSocks4TryDirect ( bool  = true  )  [inline, virtual]

If connection to socks4 server fails, immediately try direct connection to final host.

Reimplemented in SocketHandler.

Definition at line 175 of file ISocketHandler.h.

00175 {}

virtual ipaddr_t ISocketHandler::GetSocks4Host (  )  [inline, virtual]

Get socks4 server ip.

Returns:
socks4 server ip

Reimplemented in SocketHandler.

Definition at line 178 of file ISocketHandler.h.

00178                                          {
00179                 return (ipaddr_t)0;
00180         }

virtual port_t ISocketHandler::GetSocks4Port (  )  [inline, virtual]

Get socks4 port number.

Returns:
socks4 port number

Reimplemented in SocketHandler.

Definition at line 183 of file ISocketHandler.h.

00183                                        {
00184                 return 0;
00185         }

virtual const std::string& ISocketHandler::GetSocks4Userid (  )  [pure virtual]

Get socks4 userid (optional).

Returns:
socks4 userid

Implemented in SocketHandler.

virtual bool ISocketHandler::Socks4TryDirect (  )  [inline, virtual]

Check status of socks4 try direct flag.

Returns:
true if direct connection should be tried if connection to socks4 server fails

Reimplemented in SocketHandler.

Definition at line 191 of file ISocketHandler.h.

00191                                        {
00192                 return false;
00193         }

virtual void ISocketHandler::EnableResolver ( port_t  = 16667  )  [inline, virtual]

Enable asynchronous DNS.

Parameters:
port Listen port of asynchronous dns server

Reimplemented in SocketHandler.

Definition at line 202 of file ISocketHandler.h.

00202 {}

virtual bool ISocketHandler::ResolverEnabled (  )  [inline, virtual]

Check resolver status.

Returns:
true if resolver is enabled

Reimplemented in SocketHandler.

Definition at line 205 of file ISocketHandler.h.

00205                                        {
00206                 return false;
00207         }

virtual int ISocketHandler::Resolve ( Socket ,
const std::string &  host,
port_t  port 
) [inline, virtual]

Queue a dns request.

Parameters:
host Hostname to be resolved
port Port number will be echoed in Socket::OnResolved callback

Reimplemented in SocketHandler.

Definition at line 211 of file ISocketHandler.h.

Referenced by Socket::Resolve().

00211                                                                         {
00212                 return -1;
00213         }

virtual int ISocketHandler::Resolve ( Socket ,
ipaddr_t  a 
) [inline, virtual]

Do a reverse dns lookup.

Reimplemented in SocketHandler.

Definition at line 220 of file ISocketHandler.h.

00220                                                  {
00221                 return -1;
00222         }

virtual port_t ISocketHandler::GetResolverPort (  )  [inline, virtual]

Get listen port of asynchronous dns server.

Reimplemented in SocketHandler.

Definition at line 229 of file ISocketHandler.h.

00229                                          {
00230                 return 0;
00231         }

virtual bool ISocketHandler::ResolverReady (  )  [inline, virtual]

Resolver thread ready for queries.

Reimplemented in SocketHandler.

Definition at line 233 of file ISocketHandler.h.

00233                                      {
00234                 return false;
00235         }


Friends And Related Function Documentation

friend class Socket [friend]

Definition at line 63 of file ISocketHandler.h.


Member Data Documentation

Registered log class, or NULL.

Definition at line 239 of file ISocketHandler.h.

Referenced by LogError(), and RegStdLog().

bool ISocketHandler::m_slave [protected]

Indicates that this is a ISocketHandler run in SocketThread.

Definition at line 241 of file ISocketHandler.h.

Referenced by IsSlave(), SocketHandler::Select(), SetSlave(), and SocketHandler::~SocketHandler().

Mutex correctly initialized.

Definition at line 244 of file ISocketHandler.h.

Referenced by SocketHandler::Select(), and SocketHandler::~SocketHandler().


The documentation for this class was generated from the following files:
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4