ISocketHandler Class ReferenceSocket container class, event generator.
More...
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Public Member Functions | |
| virtual | ~ISocketHandler () |
| virtual ISocketHandler * | Create (StdLog *=NULL)=0 |
| Return another instance. | |
| virtual ISocketHandler * | Create (IMutex &, ISocketHandler &, StdLog *=NULL)=0 |
| Return another instance. | |
| virtual bool | ParentHandlerIsValid ()=0 |
| Handler created with parent. | |
| virtual ISocketHandler & | ParentHandler ()=0 |
| Get parent sockethandler. | |
| virtual ISocketHandler & | GetRandomHandler ()=0 |
| Get thread handler with least connections. | |
| virtual ISocketHandler & | GetEffectiveHandler ()=0 |
| Return parent handler if valid, otherwise return normal handler. | |
| virtual void | SetNumberOfThreads (size_t n)=0 |
| Enable threading. | |
| virtual bool | IsThreaded ()=0 |
| Threading is enabled. | |
| virtual void | EnableRelease ()=0 |
| Enable select release. | |
| virtual void | Release ()=0 |
| Make select release. | |
| virtual IMutex & | GetMutex () const =0 |
| Get mutex reference for threadsafe operations. | |
| virtual void | RegStdLog (StdLog *log)=0 |
| Register StdLog object for error callback. | |
| virtual void | LogError (Socket *p, const std::string &user_text, int err, const std::string &sys_err, loglevel_t t=LOG_LEVEL_WARNING)=0 |
| Log error to log class for print out / storage. | |
| virtual void | Add (Socket *)=0 |
| Add socket instance to socket map. | |
| virtual void | ISocketHandler_Add (Socket *, bool bRead, bool bWrite)=0 |
| Set read/write/exception file descriptor sets (fd_set). | |
| virtual void | ISocketHandler_Mod (Socket *, bool bRead, bool bWrite)=0 |
| virtual void | ISocketHandler_Del (Socket *)=0 |
| 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 bool | Valid (socketuid_t)=0 |
| Preferred method - Check that a socket still is handled by this socket handler. | |
| virtual size_t | GetCount ()=0 |
| Return number of sockets handled by this handler. | |
| virtual size_t | MaxCount ()=0 |
| Return maximum number of sockets allowed. | |
| virtual bool | OkToAccept (Socket *p)=0 |
| Override and return false to deny all incoming connections. | |
| virtual const std::map< SOCKET, Socket * > & | AllSockets ()=0 |
| Use with care, always lock with h.GetMutex() if multithreaded. | |
| virtual size_t | MaxTcpLineSize ()=0 |
| Override to accept longer lines than TCP_LINE_SIZE. | |
| virtual void | SetCallOnConnect (bool=true)=0 |
| virtual void | SetDetach (bool=true)=0 |
| virtual void | SetTimeout (bool=true)=0 |
| virtual void | SetRetry (bool=true)=0 |
| virtual void | SetClose (bool=true)=0 |
| virtual ISocketHandler::PoolSocket * | FindConnection (int type, const std::string &protocol, SocketAddress &)=0 |
| Find available open connection (used by connection pool). | |
| virtual void | EnablePool (bool=true)=0 |
| Enable connection pool (by default disabled). | |
| virtual bool | PoolEnabled ()=0 |
| Check pool status. | |
| virtual void | SetSocks4Host (ipaddr_t)=0 |
| Set socks4 server ip that all new tcp sockets should use. | |
| virtual void | SetSocks4Host (const std::string &)=0 |
| Set socks4 server hostname that all new tcp sockets should use. | |
| virtual void | SetSocks4Port (port_t)=0 |
| Set socks4 server port number that all new tcp sockets should use. | |
| virtual void | SetSocks4Userid (const std::string &)=0 |
| Set optional socks4 userid. | |
| virtual void | SetSocks4TryDirect (bool=true)=0 |
| If connection to socks4 server fails, immediately try direct connection to final host. | |
| virtual ipaddr_t | GetSocks4Host ()=0 |
| Get socks4 server ip. | |
| virtual port_t | GetSocks4Port ()=0 |
| Get socks4 port number. | |
| virtual const std::string & | GetSocks4Userid ()=0 |
| Get socks4 userid (optional). | |
| virtual bool | Socks4TryDirect ()=0 |
| Check status of socks4 try direct flag. | |
| virtual void | EnableResolver (port_t=16667)=0 |
| Enable asynchronous DNS. | |
| virtual bool | ResolverEnabled ()=0 |
| Check resolver status. | |
| virtual int | Resolve (Socket *, const std::string &host, port_t port)=0 |
| Queue a dns request. | |
| virtual int | Resolve (Socket *, ipaddr_t a)=0 |
| Do a reverse dns lookup. | |
| virtual port_t | GetResolverPort ()=0 |
| Get listen port of asynchronous dns server. | |
| virtual bool | ResolverReady ()=0 |
| Resolver thread ready for queries. | |
| virtual bool | Resolving (Socket *)=0 |
| Returns true if socket waiting for a resolve event. | |
| virtual void | SetSlave (bool x=true)=0 |
| Indicates that the handler runs under SocketThread. | |
| virtual bool | IsSlave ()=0 |
| Indicates that the handler runs under SocketThread. | |
Protected Member Functions | |
| virtual void | Remove (Socket *)=0 |
| Remove socket from socket map, used by Socket class. | |
| virtual int | ISocketHandler_Select (struct timeval *)=0 |
| Actual call to select(). | |
Friends | |
| class | Socket |
Classes | |
| class | PoolSocket |
| Connection pool class for internal use by the ISocketHandler. More... | |
Definition at line 53 of file ISocketHandler.h.
| virtual ISocketHandler::~ISocketHandler | ( | ) | [inline, virtual] |
| virtual ISocketHandler* ISocketHandler::Create | ( | StdLog * | = NULL |
) | [pure virtual] |
Return another instance.
Implemented in SocketHandler, and SocketHandlerEp.
Referenced by SocketHandlerThread::Run().
| virtual ISocketHandler* ISocketHandler::Create | ( | IMutex & | , | |
| ISocketHandler & | , | |||
| StdLog * | = NULL | |||
| ) | [pure virtual] |
| virtual bool ISocketHandler::ParentHandlerIsValid | ( | ) | [pure virtual] |
| virtual ISocketHandler& ISocketHandler::ParentHandler | ( | ) | [pure virtual] |
| virtual ISocketHandler& ISocketHandler::GetRandomHandler | ( | ) | [pure virtual] |
| virtual ISocketHandler& ISocketHandler::GetEffectiveHandler | ( | ) | [pure virtual] |
| virtual void ISocketHandler::SetNumberOfThreads | ( | size_t | n | ) | [pure virtual] |
| virtual bool ISocketHandler::IsThreaded | ( | ) | [pure virtual] |
| virtual void ISocketHandler::EnableRelease | ( | ) | [pure virtual] |
| virtual void ISocketHandler::Release | ( | ) | [pure virtual] |
| virtual IMutex& ISocketHandler::GetMutex | ( | ) | const [pure virtual] |
Get mutex reference for threadsafe operations.
Implemented in SocketHandler.
Referenced by SocketHandler::GetRandomHandler(), and ListenSocket< X >::OnRead().
| virtual void ISocketHandler::RegStdLog | ( | StdLog * | log | ) | [pure virtual] |
Register StdLog object for error callback.
| log | Pointer to log class |
Implemented in SocketHandler.
| virtual void ISocketHandler::LogError | ( | Socket * | p, | |
| const std::string & | user_text, | |||
| int | err, | |||
| const std::string & | sys_err, | |||
| loglevel_t | t = LOG_LEVEL_WARNING | |||
| ) | [pure virtual] |
Log error to log class for print out / storage.
Implemented in SocketHandler.
Referenced by SctpSocket::AddAddress(), SctpSocket::AddConnection(), HttpPostSocket::AddFile(), UdpSocket::AddMulticastMembership(), UdpSocket::Bind(), SctpSocket::Bind(), TcpSocket::Close(), Socket::Close(), Socket::CreateSocket(), HttpdSocket::datetime2httpdate(), HttpGetSocket::DoConnect(), UdpSocket::DropMulticastMembership(), Socket::GetClientRemoteAddress(), SctpSocket::getladdrs(), UdpSocket::GetMulticastTTL(), SctpSocket::getpaddrs(), Socket::GetPort(), Socket::GetRemoteIP4(), TcpSocket::GetSsl(), TcpSocket::GetSslContext(), HttpDebugSocket::Init(), TcpSocket::InitializeContext(), TcpSocket::InitSSLServer(), Socket::IpAddMembership(), Socket::IpDropMembership(), Socket::IpMulticastTTL(), Socket::IpTOS(), Socket::IpTTL(), UdpSocket::IsBroadcast(), UdpSocket::IsMulticastLoop(), TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), HttpClientSocket::OnData(), ResolvSocket::OnDetached(), Socket::OnException(), HttpClientSocket::OnFirst(), HTTPSocket::OnLine(), UdpSocket::OnRead(), TcpSocket::OnRead(), SctpSocket::OnRead(), TcpSocket::OnResolved(), Socket::OnSocks4Connect(), TcpSocket::OnSocks4ConnectFailed(), Socket::OnSocks4ConnectFailed(), TcpSocket::OnSocks4Read(), Socket::OnSocks4Read(), TcpSocket::OnWrite(), SctpSocket::OnWrite(), UdpSocket::Open(), TcpSocket::Open(), SctpSocket::Open(), SctpSocket::PeelOff(), SctpSocket::RemoveAddress(), UdpSocket::SendBuf(), TcpSocket::SendBuf(), TcpSocket::SendFromOutputBuffer(), UdpSocket::SendToBuf(), UdpSocket::SetBroadcast(), Socket::SetClientRemoteAddress(), HttpPutSocket::SetFile(), Socket::SetIpHdrincl(), Socket::SetIpMulticastTTL(), Socket::SetIpOptions(), Socket::SetIpTOS(), Socket::SetIpTTL(), UdpSocket::SetMulticastDefaultInterface(), UdpSocket::SetMulticastLoop(), Socket::SetMulticastLoop(), UdpSocket::SetMulticastTTL(), Socket::SetNonblocking(), Socket::SetSoBroadcast(), Socket::SetSoDebug(), Socket::SetSoDontroute(), Socket::SetSoKeepalive(), Socket::SetSoLinger(), Socket::SetSoOobinline(), Socket::SetSoRcvbuf(), Socket::SetSoRcvlowat(), Socket::SetSoRcvtimeo(), Socket::SetSoReuseaddr(), Socket::SetSoSndbuf(), Socket::SetSoSndlowat(), Socket::SetSoSndtimeo(), TcpSocket::SetTcpNodelay(), Socket::SoAcceptconn(), Socket::SoError(), Socket::SoRcvbuf(), Socket::SoSndbuf(), Socket::SoType(), TcpSocket::SSLNegotiate(), TcpSocket::TryWrite(), HTTPSocket::url_this(), and TcpSocket::UseCertificateChainFile().
| virtual void ISocketHandler::Add | ( | Socket * | ) | [pure virtual] |
Add socket instance to socket map.
Removal is always automatic.
Implemented in EventHandler, and SocketHandler.
Referenced by ListenSocket< X >::OnRead(), TcpSocket::OnResolved(), and SctpSocket::PeelOff().
| virtual void ISocketHandler::Remove | ( | Socket * | ) | [protected, pure virtual] |
Remove socket from socket map, used by Socket class.
Implemented in SocketHandler.
Referenced by Socket::~Socket().
| virtual int ISocketHandler::ISocketHandler_Select | ( | struct timeval * | ) | [protected, pure virtual] |
| virtual void ISocketHandler::ISocketHandler_Add | ( | Socket * | , | |
| bool | bRead, | |||
| bool | bWrite | |||
| ) | [pure virtual] |
| virtual void ISocketHandler::ISocketHandler_Mod | ( | Socket * | , | |
| bool | bRead, | |||
| bool | bWrite | |||
| ) | [pure virtual] |
Implemented in SocketHandler.
Referenced by TcpSocket::OnWrite(), TcpSocket::SendBuf(), and TcpSocket::SendFromOutputBuffer().
| virtual void ISocketHandler::ISocketHandler_Del | ( | Socket * | ) | [pure virtual] |
| virtual int ISocketHandler::Select | ( | long | sec, | |
| long | usec | |||
| ) | [pure virtual] |
Wait for events, generate callbacks.
Implemented in SocketHandler.
Referenced by SocketHandlerThread::Run().
| virtual int ISocketHandler::Select | ( | ) | [pure virtual] |
| virtual int ISocketHandler::Select | ( | struct timeval * | tsel | ) | [pure virtual] |
| virtual bool ISocketHandler::Valid | ( | Socket * | ) | [pure virtual] |
Check that a socket really is handled by this socket handler.
Implemented in SocketHandler.
Referenced by SocketStream::IStreamRead(), SocketStream::IStreamWrite(), and ResolvSocket::OnLine().
| virtual bool ISocketHandler::Valid | ( | socketuid_t | ) | [pure virtual] |
Preferred method - Check that a socket still 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.
Referenced by SocketHandler::GetRandomHandler().
| virtual size_t ISocketHandler::MaxCount | ( | ) | [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.
| virtual size_t ISocketHandler::MaxTcpLineSize | ( | ) | [pure virtual] |
| virtual void ISocketHandler::SetCallOnConnect | ( | bool | = true |
) | [pure virtual] |
| virtual void ISocketHandler::SetDetach | ( | bool | = true |
) | [pure virtual] |
| virtual void ISocketHandler::SetTimeout | ( | bool | = true |
) | [pure virtual] |
| virtual void ISocketHandler::SetRetry | ( | bool | = true |
) | [pure virtual] |
| virtual void ISocketHandler::SetClose | ( | bool | = true |
) | [pure virtual] |
| virtual ISocketHandler::PoolSocket* ISocketHandler::FindConnection | ( | int | type, | |
| const std::string & | protocol, | |||
| SocketAddress & | ||||
| ) | [pure virtual] |
Find available open connection (used by connection pool).
Implemented in SocketHandler.
Referenced by TcpSocket::Open().
| virtual void ISocketHandler::EnablePool | ( | bool | = true |
) | [pure virtual] |
| virtual bool ISocketHandler::PoolEnabled | ( | ) | [pure virtual] |
| virtual void ISocketHandler::SetSocks4Host | ( | ipaddr_t | ) | [pure virtual] |
| virtual void ISocketHandler::SetSocks4Host | ( | const std::string & | ) | [pure virtual] |
| virtual void ISocketHandler::SetSocks4Port | ( | port_t | ) | [pure virtual] |
| virtual void ISocketHandler::SetSocks4Userid | ( | const std::string & | ) | [pure virtual] |
| virtual void ISocketHandler::SetSocks4TryDirect | ( | bool | = true |
) | [pure virtual] |
If connection to socks4 server fails, immediately try direct connection to final host.
Implemented in SocketHandler.
| virtual ipaddr_t ISocketHandler::GetSocks4Host | ( | ) | [pure virtual] |
| virtual port_t ISocketHandler::GetSocks4Port | ( | ) | [pure virtual] |
| virtual const std::string& ISocketHandler::GetSocks4Userid | ( | ) | [pure virtual] |
| virtual bool ISocketHandler::Socks4TryDirect | ( | ) | [pure virtual] |
Check status of socks4 try direct flag.
Implemented in SocketHandler.
| virtual void ISocketHandler::EnableResolver | ( | port_t | = 16667 |
) | [pure virtual] |
Enable asynchronous DNS.
| port | Listen port of asynchronous dns server |
Implemented in SocketHandler.
| virtual bool ISocketHandler::ResolverEnabled | ( | ) | [pure virtual] |
| virtual int ISocketHandler::Resolve | ( | Socket * | , | |
| const std::string & | host, | |||
| port_t | port | |||
| ) | [pure virtual] |
Queue a dns request.
| host | Hostname to be resolved | |
| port | Port number will be echoed in Socket::OnResolved callback |
Implemented in SocketHandler.
Referenced by Socket::Resolve().
| virtual port_t ISocketHandler::GetResolverPort | ( | ) | [pure virtual] |
| virtual bool ISocketHandler::ResolverReady | ( | ) | [pure virtual] |
| virtual bool ISocketHandler::Resolving | ( | Socket * | ) | [pure virtual] |
Returns true if socket waiting for a resolve event.
Implemented in SocketHandler.
Referenced by ResolvSocket::OnLine().
| virtual void ISocketHandler::SetSlave | ( | bool | x = true |
) | [pure virtual] |
| virtual bool ISocketHandler::IsSlave | ( | ) | [pure virtual] |
friend class Socket [friend] |
Definition at line 55 of file ISocketHandler.h.
1.4.4