![]() |
ISocketHandler Class ReferenceSocket container class, event generator.
More...
|
Public Member Functions | |
ISocketHandler (StdLog *log) | |
ISocketHandler constructor. | |
ISocketHandler (Mutex &mutex, StdLog *log) | |
ISocketHandler threadsafe constructor. | |
virtual | ~ISocketHandler () |
Mutex & | GetMutex () 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::PoolSocket * | FindConnection (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 | |
StdLog * | m_stdlog |
Registered log class, or NULL. | |
bool | m_slave |
Indicates that this is a ISocketHandler run in SocketThread. | |
Mutex & | m_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... |
Definition at line 61 of file ISocketHandler.h.
ISocketHandler::ISocketHandler | ( | StdLog * | log | ) |
ISocketHandler constructor.
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 threadsafe constructor.
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] |
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.
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] |
virtual int ISocketHandler::Select | ( | ) | [pure virtual] |
virtual int ISocketHandler::Select | ( | struct timeval * | tsel | ) | [pure virtual] |
virtual bool ISocketHandler::Valid | ( | Socket * | ) | [pure virtual] |
virtual size_t ISocketHandler::GetCount | ( | ) | [pure virtual] |
virtual bool ISocketHandler::OkToAccept | ( | Socket * | p | ) | [pure virtual] |
Override and return false to deny all incoming connections.
p | ListenSocket class pointer (use GetPort to identify which one) |
Implemented in SocketHandler.
Called by Socket when a socket changes state.
Implemented in SocketHandler.
Referenced by Socket::Close(), Socket::SetCallOnConnect(), Socket::SetCloseAndDelete(), Socket::SetConnecting(), Socket::SetDetach(), and Socket::SetRetryClientConnect().
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().
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.
virtual bool ISocketHandler::PoolEnabled | ( | ) | [inline, virtual] |
Check pool status.
Reimplemented in SocketHandler.
Definition at line 157 of file ISocketHandler.h.
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.
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.
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.
virtual void ISocketHandler::SetSocks4Userid | ( | const std::string & | ) | [inline, virtual] |
Set optional socks4 userid.
Reimplemented in SocketHandler.
Definition at line 173 of file ISocketHandler.h.
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.
virtual ipaddr_t ISocketHandler::GetSocks4Host | ( | ) | [inline, virtual] |
Get 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.
Reimplemented in SocketHandler.
Definition at line 183 of file ISocketHandler.h.
virtual const std::string& ISocketHandler::GetSocks4Userid | ( | ) | [pure virtual] |
virtual bool ISocketHandler::Socks4TryDirect | ( | ) | [inline, virtual] |
Check status of socks4 try direct flag.
Reimplemented in SocketHandler.
Definition at line 191 of file ISocketHandler.h.
virtual void ISocketHandler::EnableResolver | ( | port_t | = 16667 |
) | [inline, virtual] |
Enable asynchronous DNS.
port | Listen port of asynchronous dns server |
Reimplemented in SocketHandler.
Definition at line 202 of file ISocketHandler.h.
virtual bool ISocketHandler::ResolverEnabled | ( | ) | [inline, virtual] |
Check resolver status.
Reimplemented in SocketHandler.
Definition at line 205 of file ISocketHandler.h.
virtual int ISocketHandler::Resolve | ( | Socket * | , | |
const std::string & | host, | |||
port_t | port | |||
) | [inline, virtual] |
Queue a dns request.
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().
Do a reverse dns lookup.
Reimplemented in SocketHandler.
Definition at line 220 of file ISocketHandler.h.
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.
virtual bool ISocketHandler::ResolverReady | ( | ) | [inline, virtual] |
Resolver thread ready for queries.
Reimplemented in SocketHandler.
Definition at line 233 of file ISocketHandler.h.
friend class Socket [friend] |
Definition at line 63 of file ISocketHandler.h.
StdLog* ISocketHandler::m_stdlog [protected] |
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& ISocketHandler::m_mutex [protected] |
Thread safety mutex.
Definition at line 243 of file ISocketHandler.h.
Referenced by GetMutex(), SocketHandler::Select(), SocketHandler::SocketHandler(), and SocketHandler::~SocketHandler().
bool ISocketHandler::m_b_use_mutex [protected] |
Mutex correctly initialized.
Definition at line 244 of file ISocketHandler.h.
Referenced by SocketHandler::Select(), and SocketHandler::~SocketHandler().