![]() |
Socket Class ReferenceSocket base class.
More...
|
Public Member Functions | |
Socket (ISocketHandler &) | |
"Default" constructor | |
virtual | ~Socket () |
virtual Socket * | Create () |
Socket class instantiation method. | |
ISocketHandler & | Handler () const |
Returns reference to sockethandler that owns the socket. | |
ISocketHandler & | MasterHandler () const |
Returns reference to sockethandler that owns the socket. | |
virtual void | Init () |
Called by ListenSocket after accept but before socket is added to handler. | |
SOCKET | CreateSocket (int af, int type, const std::string &protocol="") |
Create a socket file descriptor. | |
void | Attach (SOCKET s) |
Assign this socket a file descriptor created by a call to socket() or otherwise. | |
SOCKET | GetSocket () |
Return file descriptor assigned to this socket. | |
virtual int | Close () |
Close connection immediately - internal use. | |
void | Set (bool bRead, bool bWrite, bool bException=true) |
Add file descriptor to sockethandler fd_set's. | |
virtual bool | Ready () |
Returns true when socket file descriptor is valid and socket is not about to be closed. | |
Socket * | GetParent () |
Returns pointer to ListenSocket that created this instance on an incoming connection. | |
void | SetParent (Socket *) |
Used by ListenSocket to set parent pointer of newly created socket instance. | |
virtual port_t | GetPort () |
Get listening port from ListenSocket<>. | |
bool | SetNonblocking (bool) |
Set socket non-block operation. | |
bool | SetNonblocking (bool, SOCKET) |
Set socket non-block operation. | |
time_t | Uptime () |
Total lifetime of instance. | |
void | SetClientRemoteAddress (SocketAddress &) |
Set address/port of last connect() call. | |
std::auto_ptr< SocketAddress > | GetClientRemoteAddress () |
Get address/port of last connect() call. | |
virtual void | SendBuf (const char *, size_t, int=0) |
Common interface for SendBuf used by Tcp and Udp sockets. | |
virtual void | Send (const std::string &, int=0) |
Common interface for Send used by Tcp and Udp sockets. | |
virtual uint64_t | GetBytesSent (bool clear=false) |
Outgoing traffic counter. | |
virtual uint64_t | GetBytesReceived (bool clear=false) |
Incoming traffic counter. | |
void | SetTimeout (time_t secs) |
Enable timeout control. | |
bool | Timeout (time_t tnow) |
Check timeout. | |
void | SetRemoteAddress (SocketAddress &) |
Used by ListenSocket. | |
void | SetTrafficMonitor (IFile *p) |
Write traffic to an IFile. | |
Event callbacks | |
virtual void | OnRead () |
Called when there is something to be read from the file descriptor. | |
virtual void | OnWrite () |
Called when there is room for another write on the file descriptor. | |
virtual void | OnException () |
Called on socket exception. | |
virtual void | OnDelete () |
Called before a socket class is deleted by the ISocketHandler. | |
virtual void | OnConnect () |
Called when a connection has completed. | |
virtual void | OnAccept () |
Called when an incoming connection has been completed. | |
virtual void | OnLine (const std::string &) |
Called when a complete line has been read and the socket is in line protocol mode. | |
virtual void | OnConnectFailed () |
Called on connect timeout (5s). | |
virtual void | OnOptions (int family, int type, int protocol, SOCKET s)=0 |
Called when a client socket is created, to set socket options. | |
virtual bool | OnConnectRetry () |
Connection retry callback - return false to abort connection attempts. | |
virtual void | OnReconnect () |
a reconnect has been made | |
virtual void | OnDisconnect () |
When a socket is set to reconnect, and a disconnect has been detected. | |
virtual void | OnTimeout () |
Timeout callback. | |
virtual void | OnConnectTimeout () |
Connection timeout. | |
Socket mode flags, set/reset | |
void | SetDeleteByHandler (bool=true) |
Set delete by handler true when you want the sockethandler to delete the socket instance after use. | |
bool | DeleteByHandler () |
Check delete by handler flag. | |
void | SetCloseAndDelete (bool=true) |
Set close and delete to terminate the connection. | |
bool | CloseAndDelete () |
Check close and delete flag. | |
time_t | TimeSinceClose () |
Return number of seconds since socket was ordered to close. | |
void | DisableRead (bool x=true) |
Ignore read events for an output only socket. | |
bool | IsDisableRead () |
Check ignore read events flag. | |
void | SetConnected (bool=true) |
Set connected status. | |
bool | IsConnected () |
Check connected status. | |
void | SetErasedByHandler (bool x=true) |
Set flag indicating the socket is being actively deleted by the sockethandler. | |
bool | ErasedByHandler () |
Get value of flag indicating socket is deleted by sockethandler. | |
Information about remote connection | |
std::auto_ptr< SocketAddress > | GetRemoteSocketAddress () |
Returns address of remote end. | |
ipaddr_t | GetRemoteIP4 () |
Returns address of remote end: ipv4. | |
port_t | GetRemotePort () |
Returns remote port number: ipv4 and ipv6. | |
std::string | GetRemoteAddress () |
Returns remote ip as string? ipv4 and ipv6. | |
std::string | GetRemoteHostname () |
ipv4 and ipv6(not implemented) | |
IP options | |
When an ip or socket option is available on all of the operating systems I'm testing on (linux 2.4.x, _win32, macosx, solaris9 intel) they are not checked with an ifdef below.
This might cause a compile error on other operating systems. | |
bool | SetIpOptions (const void *p, socklen_t len) |
bool | SetIpTOS (unsigned char tos) |
unsigned char | IpTOS () |
bool | SetIpTTL (int ttl) |
int | IpTTL () |
bool | SetIpHdrincl (bool x=true) |
bool | SetIpMulticastTTL (int) |
int | IpMulticastTTL () |
bool | SetMulticastLoop (bool x=true) |
bool | IpAddMembership (struct ip_mreq &) |
bool | IpDropMembership (struct ip_mreq &) |
Socket Options | |
bool | SoAcceptconn () |
bool | SetSoBroadcast (bool x=true) |
bool | SetSoDebug (bool x=true) |
int | SoError () |
bool | SetSoDontroute (bool x=true) |
bool | SetSoLinger (int onoff, int linger) |
bool | SetSoOobinline (bool x=true) |
bool | SetSoRcvlowat (int) |
bool | SetSoSndlowat (int) |
bool | SetSoRcvtimeo (struct timeval &) |
bool | SetSoSndtimeo (struct timeval &) |
bool | SetSoRcvbuf (int) |
int | SoRcvbuf () |
bool | SetSoSndbuf (int) |
int | SoSndbuf () |
int | SoType () |
bool | SetSoReuseaddr (bool x=true) |
bool | SetSoKeepalive (bool x=true) |
SSL Support | |
virtual void | OnSSLConnect () |
SSL client/server support - internal use. | |
virtual void | OnSSLAccept () |
SSL client/server support - internal use. | |
virtual void | OnSSLConnectFailed () |
SSL negotiation failed for client connect. | |
virtual void | OnSSLAcceptFailed () |
SSL negotiation failed for server accept. | |
virtual bool | SSLNegotiate () |
new SSL support | |
bool | IsSSL () |
Check if SSL is Enabled for this TcpSocket. | |
void | EnableSSL (bool x=true) |
Enable SSL operation for a TcpSocket. | |
bool | IsSSLNegotiate () |
Still negotiating ssl connection. | |
void | SetSSLNegotiate (bool x=true) |
Set flag indicating ssl handshaking still in progress. | |
bool | IsSSLServer () |
OnAccept called with SSL Enabled. | |
void | SetSSLServer (bool x=true) |
Set flag indicating that this is a TcpSocket with incoming SSL connection. | |
virtual SSL_CTX * | GetSslContext () |
SSL; Get pointer to ssl context structure. | |
virtual SSL * | GetSsl () |
SSL; Get pointer to ssl structure. | |
Connection Pool | |
void | SetIsClient () |
Client = connecting TcpSocket. | |
void | SetSocketType (int x) |
Socket type from socket() call. | |
int | GetSocketType () |
Socket type from socket() call. | |
void | SetSocketProtocol (const std::string &x) |
Protocol type from socket() call. | |
const std::string & | GetSocketProtocol () |
Protocol type from socket() call. | |
void | SetRetain () |
Instruct a client socket to stay open in the connection pool after use. | |
bool | Retain () |
Check retain flag. | |
void | SetLost () |
Connection lost - error while reading/writing from a socket - TcpSocket only. | |
bool | Lost () |
Check connection lost status flag, used by TcpSocket only. | |
void | CopyConnection (Socket *sock) |
Copy connection parameters from sock. | |
Socks4 support | |
virtual void | OnSocks4Connect () |
Socks4 client support internal use. | |
virtual void | OnSocks4ConnectFailed () |
Socks4 client support internal use. | |
virtual bool | OnSocks4Read () |
Socks4 client support internal use. | |
bool | Socks4 () |
socket still in socks4 negotiation mode | |
void | SetSocks4 (bool x=true) |
Set flag indicating Socks4 handshaking in progress. | |
void | SetSocks4Host (ipaddr_t a) |
Set socks4 server host address to use. | |
void | SetSocks4Host (const std::string &) |
Set socks4 server hostname to use. | |
void | SetSocks4Port (port_t p) |
Socks4 server port to use. | |
void | SetSocks4Userid (const std::string &x) |
Provide a socks4 userid if required by the socks4 server. | |
ipaddr_t | GetSocks4Host () |
Get the ip address of socks4 server to use. | |
port_t | GetSocks4Port () |
Get the socks4 server port to use. | |
const std::string & | GetSocks4Userid () |
Get socks4 userid. | |
Asynchronous Resolver | |
int | Resolve (const std::string &host, port_t port=0) |
Request an asynchronous dns resolution. | |
virtual void | OnResolved (int id, ipaddr_t a, port_t port) |
Callback returning a resolved address. | |
int | Resolve (ipaddr_t a) |
Request asynchronous reverse dns lookup. | |
virtual void | OnReverseResolved (int id, const std::string &name) |
Callback returning reverse resolve results. | |
virtual void | OnResolveFailed (int id) |
Callback indicating failed dns lookup. | |
Thread Support | |
virtual void | OnDetached () |
Callback fires when a new socket thread has started and this socket is ready for operation again. | |
void | SetDetach (bool x=true) |
Internal use. | |
bool | IsDetach () |
Check detach flag. | |
void | SetDetached (bool x=true) |
Internal use. | |
const bool | IsDetached () const |
Check detached flag. | |
bool | Detach () |
Order this socket to start its own thread and call OnDetached when ready for operation. | |
void | SetSlaveHandler (ISocketHandler *) |
Store the slave sockethandler pointer. | |
void | DetachSocket () |
Create new thread for this socket to run detached in. | |
Protected Member Functions | |
Socket () | |
default constructor not available | |
Socket (const Socket &s) | |
copy constructor not available | |
Socket & | operator= (const Socket &) |
assignment operator not available. | |
IFile * | GetTrafficMonitor () |
All traffic will be written to this IFile, if set. | |
Private Attributes | |
ISocketHandler & | m_handler |
Reference of ISocketHandler in control of this socket. | |
SOCKET | m_socket |
File descriptor. | |
bool | m_bDel |
Delete by handler flag. | |
bool | m_bClose |
Close and delete flag. | |
time_t | m_tCreate |
Time in seconds when this socket was created. | |
Socket * | m_parent |
Pointer to ListenSocket class, valid for incoming sockets. | |
bool | m_b_disable_read |
Disable checking for read events. | |
bool | m_connected |
Socket is connected (tcp/udp). | |
bool | m_b_erased_by_handler |
Set by handler before delete. | |
time_t | m_tClose |
Time in seconds when ordered to close. | |
std::auto_ptr< SocketAddress > | m_client_remote_address |
Address of last connect(). | |
std::auto_ptr< SocketAddress > | m_remote_address |
Remote end address. | |
IFile * | m_traffic_monitor |
time_t | m_timeout_start |
Set by SetTimeout. | |
time_t | m_timeout_limit |
Defined by SetTimeout. | |
bool | m_b_enable_ssl |
Enable SSL for this TcpSocket. | |
bool | m_b_ssl |
ssl negotiation mode (TcpSocket) | |
bool | m_b_ssl_server |
True if this is an incoming ssl TcpSocket connection. | |
int | m_socket_type |
Type of socket, from socket() call. | |
std::string | m_socket_protocol |
Protocol, from socket() call. | |
bool | m_bClient |
only client connections are pooled | |
bool | m_bRetain |
keep connection on close | |
bool | m_bLost |
connection lost | |
bool | m_bSocks4 |
socks4 negotiation mode (TcpSocket) | |
ipaddr_t | m_socks4_host |
socks4 server address | |
port_t | m_socks4_port |
socks4 server port number | |
std::string | m_socks4_userid |
socks4 server usedid | |
bool | m_detach |
Socket ordered to detach flag. | |
bool | m_detached |
Socket has been detached. | |
SocketThread * | m_pThread |
Detach socket thread class pointer. | |
ISocketHandler * | m_slave_handler |
Actual sockethandler while detached. | |
Friends | |
class | ISocketHandler |
Classes | |
class | SocketThread |
Detached socket run thread. More... |
Definition at line 61 of file Socket.h.
Socket::Socket | ( | ISocketHandler & | ) |
"Default" constructor
Definition at line 64 of file Socket.cpp.
00065 :m_flags(0) 00066 :m_handler(h) 00067 ,m_socket( INVALID_SOCKET ) 00068 ,m_bDel(false) 00069 ,m_bClose(false) 00070 ,m_tCreate(time(NULL)) 00071 ,m_parent(NULL) 00072 ,m_b_disable_read(false) 00073 ,m_connected(false) 00074 ,m_b_erased_by_handler(false) 00075 ,m_tClose(0) 00076 ,m_client_remote_address(NULL) 00077 ,m_remote_address(NULL) 00078 ,m_traffic_monitor(NULL) 00079 #ifdef HAVE_OPENSSL 00080 ,m_b_enable_ssl(false) 00081 ,m_b_ssl(false) 00082 ,m_b_ssl_server(false) 00083 #endif 00084 #ifdef ENABLE_IPV6 00085 ,m_ipv6(false) 00086 #endif 00087 #ifdef ENABLE_POOL 00088 ,m_socket_type(0) 00089 ,m_bClient(false) 00090 ,m_bRetain(false) 00091 ,m_bLost(false) 00092 #endif 00093 #ifdef ENABLE_SOCKS4 00094 ,m_bSocks4(false) 00095 ,m_socks4_host(h.GetSocks4Host()) 00096 ,m_socks4_port(h.GetSocks4Port()) 00097 ,m_socks4_userid(h.GetSocks4Userid()) 00098 #endif 00099 #ifdef ENABLE_DETACH 00100 ,m_detach(false) 00101 ,m_detached(false) 00102 ,m_pThread(NULL) 00103 ,m_slave_handler(NULL) 00104 #endif 00105 { 00106 }
Socket::~Socket | ( | ) | [virtual] |
Definition at line 109 of file Socket.cpp.
References Close(), Handler(), INVALID_SOCKET, m_bRetain, m_socket, and ISocketHandler::Remove().
00110 { 00111 Handler().Remove(this); 00112 if (m_socket != INVALID_SOCKET 00113 #ifdef ENABLE_POOL 00114 && !m_bRetain 00115 #endif 00116 ) 00117 { 00118 Close(); 00119 } 00120 }
Socket::Socket | ( | ) | [inline, protected] |
Socket::Socket | ( | const Socket & | s | ) | [inline, protected] |
virtual Socket* Socket::Create | ( | ) | [inline, virtual] |
Socket class instantiation method.
Used when a "non-standard" constructor needs to be used for the socket class. Note: the socket class still needs the "default" constructor with one ISocketHandler& as input parameter.
Definition at line 148 of file Socket.h.
Referenced by SctpSocket::PeelOff().
ISocketHandler & Socket::Handler | ( | ) | const |
Returns reference to sockethandler that owns the socket.
If the socket is detached, this is a reference to the slave sockethandler.
Definition at line 280 of file Socket.cpp.
References IsDetached(), m_handler, and m_slave_handler.
Referenced by SctpSocket::AddAddress(), SctpSocket::AddConnection(), HttpPostSocket::AddFile(), UdpSocket::AddMulticastMembership(), UdpSocket::Bind(), SctpSocket::Bind(), TcpSocket::Close(), Close(), CreateSocket(), HttpdSocket::datetime2httpdate(), UdpSocket::DropMulticastMembership(), GetClientRemoteAddress(), SctpSocket::getladdrs(), UdpSocket::GetMulticastTTL(), SctpSocket::getpaddrs(), GetPort(), GetRemoteIP4(), TcpSocket::GetSsl(), TcpSocket::GetSslContext(), HttpGetSocket::HttpGetSocket(), HttpDebugSocket::Init(), TcpSocket::InitializeContext(), TcpSocket::InitSSLServer(), IpAddMembership(), IpDropMembership(), IpMulticastTTL(), IpTOS(), IpTTL(), UdpSocket::IsBroadcast(), UdpSocket::IsMulticastLoop(), TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), HttpClientSocket::OnData(), ResolvSocket::OnDelete(), ResolvSocket::OnDetached(), OnException(), HttpClientSocket::OnFirst(), ResolvSocket::OnLine(), UdpSocket::OnRead(), TcpSocket::OnRead(), SctpSocket::OnRead(), TcpSocket::OnResolved(), OnSocks4Connect(), TcpSocket::OnSocks4ConnectFailed(), OnSocks4ConnectFailed(), TcpSocket::OnSocks4Read(), OnSocks4Read(), TcpSocket::OnWrite(), SctpSocket::OnWrite(), UdpSocket::Open(), TcpSocket::Open(), SctpSocket::Open(), SctpSocket::PeelOff(), SctpSocket::RemoveAddress(), Resolve(), UdpSocket::SendBuf(), TcpSocket::SendBuf(), UdpSocket::SendToBuf(), Set(), UdpSocket::SetBroadcast(), StreamSocket::SetCallOnConnect(), SetClientRemoteAddress(), SetCloseAndDelete(), SetDetach(), HttpPutSocket::SetFile(), SetIpHdrincl(), SetIpMulticastTTL(), SetIpOptions(), SetIpTOS(), SetIpTTL(), UdpSocket::SetMulticastLoop(), SetMulticastLoop(), UdpSocket::SetMulticastTTL(), SetNonblocking(), StreamSocket::SetRetryClientConnect(), SetSoBroadcast(), SetSoDebug(), SetSoDontroute(), SetSoKeepalive(), SetSoLinger(), SetSoOobinline(), SetSoRcvbuf(), SetSoRcvlowat(), SetSoRcvtimeo(), SetSoReuseaddr(), SetSoSndbuf(), SetSoSndlowat(), SetSoSndtimeo(), TcpSocket::SetTcpNodelay(), SetTimeout(), SoAcceptconn(), SoError(), SoRcvbuf(), SoSndbuf(), SoType(), TcpSocket::SSLNegotiate(), TcpSocket::TryWrite(), HTTPSocket::url_this(), and ~Socket().
00281 { 00282 #ifdef ENABLE_DETACH 00283 if (IsDetached()) 00284 return *m_slave_handler; 00285 #endif 00286 return m_handler; 00287 }
ISocketHandler & Socket::MasterHandler | ( | ) | const |
Returns reference to sockethandler that owns the socket.
This one always returns the reference to the original sockethandler, even if the socket is detached.
Definition at line 290 of file Socket.cpp.
References m_handler.
00291 { 00292 return m_handler; 00293 }
void Socket::Init | ( | ) | [virtual] |
Called by ListenSocket after accept but before socket is added to handler.
CTcpSocket uses this to create its ICrypt member variable. The ICrypt member variable is created by a virtual method, therefore it can't be called directly from the CTcpSocket constructor. Also used to determine if incoming HTTP connection is normal (port 80) or ssl (port 443).
Reimplemented in HttpDebugSocket.
Definition at line 123 of file Socket.cpp.
SOCKET Socket::CreateSocket | ( | int | af, | |
int | type, | |||
const std::string & | protocol = "" | |||
) |
Create a socket file descriptor.
af | Address family AF_INET / AF_INET6 / ... | |
type | SOCK_STREAM / SOCK_DGRAM / ... | |
protocol | "tcp" / "udp" / ... |
Definition at line 189 of file Socket.cpp.
References Attach(), Errno, Handler(), INVALID_SOCKET, LOG_LEVEL_FATAL, ISocketHandler::LogError(), m_socket_protocol, m_socket_type, OnOptions(), SetCloseAndDelete(), and StrError.
Referenced by UdpSocket::Bind(), SctpSocket::Bind(), UdpSocket::CreateConnection(), UdpSocket::Open(), TcpSocket::Open(), SctpSocket::Open(), and UdpSocket::SendToBuf().
00190 { 00191 struct protoent *p = NULL; 00192 SOCKET s; 00193 00194 #ifdef ENABLE_POOL 00195 m_socket_type = type; 00196 m_socket_protocol = protocol; 00197 #endif 00198 if (protocol.size()) 00199 { 00200 p = getprotobyname( protocol.c_str() ); 00201 if (!p) 00202 { 00203 Handler().LogError(this, "getprotobyname", Errno, StrError(Errno), LOG_LEVEL_FATAL); 00204 SetCloseAndDelete(); 00205 return INVALID_SOCKET; 00206 } 00207 } 00208 int protno = p ? p -> p_proto : 0; 00209 00210 s = socket(af, type, protno); 00211 if (s == INVALID_SOCKET) 00212 { 00213 Handler().LogError(this, "socket", Errno, StrError(Errno), LOG_LEVEL_FATAL); 00214 SetCloseAndDelete(); 00215 return INVALID_SOCKET; 00216 } 00217 Attach(s); 00218 OnOptions(af, type, protno, s); 00219 Attach(INVALID_SOCKET); 00220 return s; 00221 }
void Socket::Attach | ( | SOCKET | s | ) |
Assign this socket a file descriptor created by a call to socket() or otherwise.
Definition at line 224 of file Socket.cpp.
References m_socket.
Referenced by UdpSocket::Bind(), SctpSocket::Bind(), CopyConnection(), UdpSocket::CreateConnection(), CreateSocket(), UdpSocket::Open(), TcpSocket::Open(), SctpSocket::Open(), SctpSocket::PeelOff(), and UdpSocket::SendToBuf().
00225 { 00226 m_socket = s; 00227 }
SOCKET Socket::GetSocket | ( | ) |
Return file descriptor assigned to this socket.
Definition at line 230 of file Socket.cpp.
References m_socket.
Referenced by SctpSocket::AddAddress(), SctpSocket::AddConnection(), UdpSocket::AddMulticastMembership(), UdpSocket::Bind(), SctpSocket::Bind(), TcpSocket::Close(), CopyConnection(), UdpSocket::CreateConnection(), UdpSocket::DropMulticastMembership(), SctpSocket::getladdrs(), UdpSocket::GetMulticastTTL(), SctpSocket::getpaddrs(), IpAddMembership(), IpDropMembership(), IpMulticastTTL(), IpTOS(), IpTTL(), UdpSocket::IsBroadcast(), UdpSocket::IsMulticastLoop(), UdpSocket::OnRead(), TcpSocket::OnRead(), SctpSocket::OnRead(), TcpSocket::OnSSLAccept(), TcpSocket::OnSSLConnect(), TcpSocket::OnWrite(), UdpSocket::Open(), SctpSocket::Open(), SctpSocket::PeelOff(), StreamSocket::Ready(), SctpSocket::RemoveAddress(), UdpSocket::SendBuf(), TcpSocket::SendBuf(), UdpSocket::SendToBuf(), UdpSocket::SetBroadcast(), StreamSocket::SetCallOnConnect(), SetIpHdrincl(), SetIpMulticastTTL(), SetIpOptions(), SetIpTOS(), SetIpTTL(), UdpSocket::SetMulticastLoop(), SetMulticastLoop(), UdpSocket::SetMulticastTTL(), StreamSocket::SetRetryClientConnect(), SetSoBroadcast(), SetSoDebug(), SetSoDontroute(), SetSoKeepalive(), SetSoLinger(), SetSoOobinline(), SetSoRcvbuf(), SetSoRcvlowat(), SetSoRcvtimeo(), SetSoReuseaddr(), SetSoSndbuf(), SetSoSndlowat(), SetSoSndtimeo(), TcpSocket::SetTcpNodelay(), SoAcceptconn(), SoError(), SoRcvbuf(), SoSndbuf(), SoType(), and TcpSocket::TryWrite().
00231 { 00232 return m_socket; 00233 }
int Socket::Close | ( | ) | [virtual] |
Close connection immediately - internal use.
Reimplemented in ListenSocket< X >, and TcpSocket.
Definition at line 163 of file Socket.cpp.
References ISocketHandler::AddList(), closesocket, Errno, Handler(), INVALID_SOCKET, LIST_CALLONCONNECT, LIST_CLOSE, LIST_DETACH, LIST_RETRY, LIST_TIMEOUT, LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, ISocketHandler::LogError(), m_socket, ISocketHandler::Set(), and StrError.
Referenced by TcpSocket::Close(), ~Socket(), and UdpSocket::~UdpSocket().
00164 { 00165 if (m_socket == INVALID_SOCKET) // this could happen 00166 { 00167 Handler().LogError(this, "Socket::Close", 0, "file descriptor invalid", LOG_LEVEL_WARNING); 00168 return 0; 00169 } 00170 int n; 00171 if ((n = closesocket(m_socket)) == -1) 00172 { 00173 // failed... 00174 Handler().LogError(this, "close", Errno, StrError(Errno), LOG_LEVEL_ERROR); 00175 } 00176 Handler().Set(m_socket, false, false, false); // remove from fd_set's 00177 Handler().AddList(m_socket, LIST_CALLONCONNECT, false); 00178 #ifdef ENABLE_DETACH 00179 Handler().AddList(m_socket, LIST_DETACH, false); 00180 #endif 00181 Handler().AddList(m_socket, LIST_TIMEOUT, false); 00182 Handler().AddList(m_socket, LIST_RETRY, false); 00183 Handler().AddList(m_socket, LIST_CLOSE, false); 00184 m_socket = INVALID_SOCKET; 00185 return n; 00186 }
void Socket::Set | ( | bool | bRead, | |
bool | bWrite, | |||
bool | bException = true | |||
) |
Add file descriptor to sockethandler fd_set's.
Definition at line 435 of file Socket.cpp.
References Handler(), m_socket, and ISocketHandler::Set().
Referenced by TcpSocket::OnWrite(), SctpSocket::OnWrite(), and TcpSocket::SendBuf().
bool Socket::Ready | ( | ) | [virtual] |
Returns true when socket file descriptor is valid and socket is not about to be closed.
Reimplemented in StreamSocket.
Definition at line 441 of file Socket.cpp.
References CloseAndDelete(), INVALID_SOCKET, and m_socket.
00442 { 00443 if (m_socket != INVALID_SOCKET && !CloseAndDelete()) 00444 return true; 00445 return false; 00446 }
Socket * Socket::GetParent | ( | ) |
Returns pointer to ListenSocket that created this instance on an incoming connection.
Definition at line 459 of file Socket.cpp.
References m_parent.
Referenced by HttpDebugSocket::Init().
00460 { 00461 return m_parent; 00462 }
void Socket::SetParent | ( | Socket * | ) |
Used by ListenSocket to set parent pointer of newly created socket instance.
Definition at line 465 of file Socket.cpp.
References m_parent.
00466 { 00467 m_parent = x; 00468 }
port_t Socket::GetPort | ( | ) | [virtual] |
Get listening port from ListenSocket<>.
Reimplemented in ListenSocket< X >, and UdpSocket.
Definition at line 471 of file Socket.cpp.
References Handler(), LOG_LEVEL_WARNING, and ISocketHandler::LogError().
Referenced by GetRemotePort(), and HttpDebugSocket::Init().
00472 { 00473 Handler().LogError(this, "GetPort", 0, "GetPort only implemented for ListenSocket", LOG_LEVEL_WARNING); 00474 return 0; 00475 }
bool Socket::SetNonblocking | ( | bool | ) |
Set socket non-block operation.
Definition at line 369 of file Socket.cpp.
References Errno, Handler(), LOG_LEVEL_ERROR, ISocketHandler::LogError(), m_socket, and StrError.
Referenced by UdpSocket::Bind(), TcpSocket::Close(), UdpSocket::CreateConnection(), TcpSocket::OnSSLAccept(), TcpSocket::OnSSLConnect(), UdpSocket::Open(), TcpSocket::Open(), SctpSocket::Open(), UdpSocket::SendToBuf(), and TcpSocket::SSLNegotiate().
00370 { 00371 #ifdef _WIN32 00372 unsigned long l = bNb ? 1 : 0; 00373 int n = ioctlsocket(m_socket, FIONBIO, &l); 00374 if (n != 0) 00375 { 00376 Handler().LogError(this, "ioctlsocket(FIONBIO)", Errno, ""); 00377 return false; 00378 } 00379 return true; 00380 #else 00381 if (bNb) 00382 { 00383 if (fcntl(m_socket, F_SETFL, O_NONBLOCK) == -1) 00384 { 00385 Handler().LogError(this, "fcntl(F_SETFL, O_NONBLOCK)", Errno, StrError(Errno), LOG_LEVEL_ERROR); 00386 return false; 00387 } 00388 } 00389 else 00390 { 00391 if (fcntl(m_socket, F_SETFL, 0) == -1) 00392 { 00393 Handler().LogError(this, "fcntl(F_SETFL, 0)", Errno, StrError(Errno), LOG_LEVEL_ERROR); 00394 return false; 00395 } 00396 } 00397 return true; 00398 #endif 00399 }
bool Socket::SetNonblocking | ( | bool | , | |
SOCKET | ||||
) |
Set socket non-block operation.
Definition at line 402 of file Socket.cpp.
References Errno, Handler(), LOG_LEVEL_ERROR, ISocketHandler::LogError(), and StrError.
00403 { 00404 #ifdef _WIN32 00405 unsigned long l = bNb ? 1 : 0; 00406 int n = ioctlsocket(s, FIONBIO, &l); 00407 if (n != 0) 00408 { 00409 Handler().LogError(this, "ioctlsocket(FIONBIO)", Errno, ""); 00410 return false; 00411 } 00412 return true; 00413 #else 00414 if (bNb) 00415 { 00416 if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) 00417 { 00418 Handler().LogError(this, "fcntl(F_SETFL, O_NONBLOCK)", Errno, StrError(Errno), LOG_LEVEL_ERROR); 00419 return false; 00420 } 00421 } 00422 else 00423 { 00424 if (fcntl(s, F_SETFL, 0) == -1) 00425 { 00426 Handler().LogError(this, "fcntl(F_SETFL, 0)", Errno, StrError(Errno), LOG_LEVEL_ERROR); 00427 return false; 00428 } 00429 } 00430 return true; 00431 #endif 00432 }
time_t Socket::Uptime | ( | ) |
Total lifetime of instance.
Definition at line 491 of file Socket.cpp.
References m_tCreate.
00492 { 00493 return time(NULL) - m_tCreate; 00494 }
void Socket::SetClientRemoteAddress | ( | SocketAddress & | ) |
Set address/port of last connect() call.
Definition at line 570 of file Socket.cpp.
References SocketAddress::GetCopy(), Handler(), SocketAddress::IsValid(), LOG_LEVEL_ERROR, ISocketHandler::LogError(), and m_client_remote_address.
Referenced by CopyConnection(), and TcpSocket::Open().
00571 { 00572 if (!ad.IsValid()) 00573 { 00574 Handler().LogError(this, "SetClientRemoteAddress", 0, "remote address not valid", LOG_LEVEL_ERROR); 00575 } 00576 m_client_remote_address = ad.GetCopy(); 00577 }
std::auto_ptr< SocketAddress > Socket::GetClientRemoteAddress | ( | ) |
Get address/port of last connect() call.
Definition at line 580 of file Socket.cpp.
References Handler(), LOG_LEVEL_ERROR, ISocketHandler::LogError(), and m_client_remote_address.
Referenced by CopyConnection(), and TcpSocket::OnSocks4Connect().
00581 { 00582 if (!m_client_remote_address.get()) 00583 { 00584 Handler().LogError(this, "GetClientRemoteAddress", 0, "remote address not yet set", LOG_LEVEL_ERROR); 00585 } 00586 return std::auto_ptr<SocketAddress>(m_client_remote_address -> GetCopy()); 00587 }
void Socket::SendBuf | ( | const char * | , | |
size_t | , | |||
int | = 0 | |||
) | [virtual] |
Common interface for SendBuf used by Tcp and Udp sockets.
Reimplemented in TcpSocket, and UdpSocket.
Definition at line 523 of file Socket.cpp.
void Socket::Send | ( | const std::string & | , | |
int | = 0 | |||
) | [virtual] |
Common interface for Send used by Tcp and Udp sockets.
Reimplemented in TcpSocket, and UdpSocket.
Definition at line 528 of file Socket.cpp.
uint64_t Socket::GetBytesSent | ( | bool | clear = false |
) | [virtual] |
uint64_t Socket::GetBytesReceived | ( | bool | clear = false |
) | [virtual] |
void Socket::SetTimeout | ( | time_t | secs | ) |
Enable timeout control.
0=disable timeout check.
Definition at line 1751 of file Socket.cpp.
References ISocketHandler::AddList(), Handler(), LIST_TIMEOUT, m_socket, m_timeout_limit, and m_timeout_start.
Referenced by StreamSocket::SetConnecting().
01752 { 01753 if (!secs) 01754 { 01755 Handler().AddList(m_socket, LIST_TIMEOUT, false); 01756 return; 01757 } 01758 Handler().AddList(m_socket, LIST_TIMEOUT, true); 01759 m_timeout_start = time(NULL); 01760 m_timeout_limit = secs; 01761 }
bool Socket::Timeout | ( | time_t | tnow | ) |
Check timeout.
Definition at line 1774 of file Socket.cpp.
References m_timeout_limit, and m_timeout_start.
01775 { 01776 if (tnow - m_timeout_start > m_timeout_limit) 01777 return true; 01778 return false; 01779 }
void Socket::SetRemoteAddress | ( | SocketAddress & | ) |
Used by ListenSocket.
ipv4 and ipv6
Definition at line 268 of file Socket.cpp.
References SocketAddress::GetCopy(), and m_remote_address.
Referenced by CopyConnection(), and TcpSocket::Open().
00269 { 00270 m_remote_address = ad.GetCopy(); 00271 }
void Socket::OnRead | ( | ) | [virtual] |
Called when there is something to be read from the file descriptor.
Reimplemented in ISocketHandler::PoolSocket, ListenSocket< X >, SctpSocket, TcpSocket, and UdpSocket.
Definition at line 128 of file Socket.cpp.
void Socket::OnWrite | ( | ) | [virtual] |
Called when there is room for another write on the file descriptor.
Reimplemented in SctpSocket, and TcpSocket.
Definition at line 133 of file Socket.cpp.
void Socket::OnException | ( | ) | [virtual] |
Called on socket exception.
Definition at line 138 of file Socket.cpp.
References Handler(), LOG_LEVEL_FATAL, ISocketHandler::LogError(), SetCloseAndDelete(), SoError(), and StrError.
00139 { 00140 // %! exception doesn't always mean something bad happened, this code should be reworked 00141 // errno valid here? 00142 int err = SoError(); 00143 Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL); 00144 SetCloseAndDelete(); 00145 }
void Socket::OnDelete | ( | ) | [virtual] |
Called before a socket class is deleted by the ISocketHandler.
Reimplemented in HttpClientSocket, and ResolvSocket.
Definition at line 148 of file Socket.cpp.
void Socket::OnConnect | ( | ) | [virtual] |
Called when a connection has completed.
Reimplemented in HttpGetSocket, HttpPostSocket, HttpPutSocket, and ResolvSocket.
Definition at line 153 of file Socket.cpp.
Referenced by TcpSocket::OnSocks4Read(), and TcpSocket::SSLNegotiate().
void Socket::OnAccept | ( | ) | [virtual] |
Called when an incoming connection has been completed.
Reimplemented in ResolvSocket, and SmtpdSocket.
Definition at line 158 of file Socket.cpp.
Referenced by TcpSocket::SSLNegotiate().
void Socket::OnLine | ( | const std::string & | ) | [virtual] |
Called when a complete line has been read and the socket is in line protocol mode.
Reimplemented in HTTPSocket, ResolvSocket, SmtpdSocket, and TcpSocket.
Definition at line 449 of file Socket.cpp.
void Socket::OnConnectFailed | ( | ) | [virtual] |
Called on connect timeout (5s).
Definition at line 454 of file Socket.cpp.
Referenced by TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), TcpSocket::OnSocks4ConnectFailed(), TcpSocket::OnSocks4Read(), TcpSocket::OnWrite(), and SctpSocket::OnWrite().
virtual void Socket::OnOptions | ( | int | family, | |
int | type, | |||
int | protocol, | |||
SOCKET | s | |||
) | [pure virtual] |
Called when a client socket is created, to set socket options.
family | AF_INET, AF_INET6, etc | |
type | SOCK_STREAM, SOCK_DGRAM, etc | |
protocol | Protocol number (tcp, udp, sctp, etc) | |
s | Socket file descriptor |
Implemented in ISocketHandler::PoolSocket, ListenSocket< X >, SctpSocket, TcpSocket, and UdpSocket.
Referenced by CreateSocket().
bool Socket::OnConnectRetry | ( | ) | [virtual] |
Connection retry callback - return false to abort connection attempts.
Definition at line 478 of file Socket.cpp.
Referenced by TcpSocket::OnConnectTimeout(), and SctpSocket::OnConnectTimeout().
void Socket::OnReconnect | ( | ) | [virtual] |
a reconnect has been made
Definition at line 485 of file Socket.cpp.
Referenced by TcpSocket::SSLNegotiate().
void Socket::OnDisconnect | ( | ) | [virtual] |
When a socket is set to reconnect, and a disconnect has been detected.
Definition at line 546 of file Socket.cpp.
Referenced by TcpSocket::OnRead().
void Socket::OnTimeout | ( | ) | [virtual] |
void Socket::OnConnectTimeout | ( | ) | [virtual] |
Connection timeout.
Reimplemented in SctpSocket, and TcpSocket.
Definition at line 1769 of file Socket.cpp.
void Socket::SetDeleteByHandler | ( | bool | = true |
) |
Set delete by handler true when you want the sockethandler to delete the socket instance after use.
Definition at line 236 of file Socket.cpp.
References m_bDel.
Referenced by SctpSocket::PeelOff().
00237 { 00238 m_bDel = x; 00239 }
bool Socket::DeleteByHandler | ( | ) |
Check delete by handler flag.
Definition at line 242 of file Socket.cpp.
References m_bDel.
Referenced by Detach().
00243 { 00244 return m_bDel; 00245 }
void Socket::SetCloseAndDelete | ( | bool | = true |
) |
Set close and delete to terminate the connection.
Definition at line 248 of file Socket.cpp.
References ISocketHandler::AddList(), Handler(), LIST_CLOSE, m_bClose, m_socket, and m_tClose.
Referenced by HttpPostSocket::AddFile(), UdpSocket::Bind(), CreateSocket(), HttpGetSocket::HttpGetSocket(), TcpSocket::InitSSLServer(), TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), HttpDebugSocket::OnData(), HttpClientSocket::OnData(), ResolvSocket::OnDetached(), OnException(), HttpClientSocket::OnFirst(), HttpDebugSocket::OnHeaderComplete(), SmtpdSocket::OnLine(), ResolvSocket::OnLine(), TcpSocket::OnRead(), SctpSocket::OnRead(), TcpSocket::OnResolved(), TcpSocket::OnSocks4ConnectFailed(), TcpSocket::OnSocks4Read(), TcpSocket::OnSSLAccept(), TcpSocket::OnSSLConnect(), TcpSocket::OnWrite(), SctpSocket::OnWrite(), UdpSocket::Open(), TcpSocket::Open(), HttpPutSocket::SetFile(), TcpSocket::SSLNegotiate(), and TcpSocket::TryWrite().
00249 { 00250 if (x != m_bClose) 00251 { 00252 Handler().AddList(m_socket, LIST_CLOSE, x); 00253 m_bClose = x; 00254 if (x) 00255 { 00256 m_tClose = time(NULL); 00257 } 00258 } 00259 }
bool Socket::CloseAndDelete | ( | ) |
Check close and delete flag.
Definition at line 262 of file Socket.cpp.
References m_bClose.
Referenced by TcpSocket::OnRead(), StreamSocket::Ready(), Ready(), and TcpSocket::SendBuf().
00263 { 00264 return m_bClose; 00265 }
time_t Socket::TimeSinceClose | ( | ) |
Return number of seconds since socket was ordered to close.
Definition at line 564 of file Socket.cpp.
References m_tClose.
00565 { 00566 return time(NULL) - m_tClose; 00567 }
void Socket::DisableRead | ( | bool | x = true |
) |
Ignore read events for an output only socket.
Definition at line 511 of file Socket.cpp.
References m_b_disable_read.
00512 { 00513 m_b_disable_read = x; 00514 }
bool Socket::IsDisableRead | ( | ) |
Check ignore read events flag.
Definition at line 517 of file Socket.cpp.
References m_b_disable_read.
Referenced by TcpSocket::OnWrite(), and SctpSocket::OnWrite().
00518 { 00519 return m_b_disable_read; 00520 }
void Socket::SetConnected | ( | bool | = true |
) |
Set connected status.
Definition at line 533 of file Socket.cpp.
References m_connected.
Referenced by UdpSocket::Open(), and TcpSocket::SSLNegotiate().
00534 { 00535 m_connected = x; 00536 }
bool Socket::IsConnected | ( | ) |
Check connected status.
Definition at line 539 of file Socket.cpp.
References m_connected.
Referenced by TcpSocket::Close(), UdpSocket::SendBuf(), and TcpSocket::SendBuf().
00540 { 00541 return m_connected; 00542 }
void Socket::SetErasedByHandler | ( | bool | x = true |
) |
Set flag indicating the socket is being actively deleted by the sockethandler.
Definition at line 552 of file Socket.cpp.
References m_b_erased_by_handler.
00553 { 00554 m_b_erased_by_handler = x; 00555 }
bool Socket::ErasedByHandler | ( | ) |
Get value of flag indicating socket is deleted by sockethandler.
Definition at line 558 of file Socket.cpp.
References m_b_erased_by_handler.
00559 { 00560 return m_b_erased_by_handler; 00561 }
std::auto_ptr< SocketAddress > Socket::GetRemoteSocketAddress | ( | ) |
Returns address of remote end.
Definition at line 274 of file Socket.cpp.
References m_remote_address.
Referenced by CopyConnection().
00275 { 00276 return std::auto_ptr<SocketAddress>(m_remote_address -> GetCopy()); 00277 }
ipaddr_t Socket::GetRemoteIP4 | ( | ) |
Returns address of remote end: ipv4.
Definition at line 296 of file Socket.cpp.
References Handler(), LOG_LEVEL_WARNING, ISocketHandler::LogError(), and m_remote_address.
00297 { 00298 ipaddr_t l = 0; 00299 #ifdef ENABLE_IPV6 00300 if (m_ipv6) 00301 { 00302 Handler().LogError(this, "GetRemoteIP4", 0, "get ipv4 address for ipv6 socket", LOG_LEVEL_WARNING); 00303 } 00304 #endif 00305 if (m_remote_address.get() != NULL) 00306 { 00307 struct sockaddr *p = *m_remote_address; 00308 struct sockaddr_in *sa = (struct sockaddr_in *)p; 00309 memcpy(&l, &sa -> sin_addr, sizeof(struct in_addr)); 00310 } 00311 return l; 00312 }
port_t Socket::GetRemotePort | ( | ) |
Returns remote port number: ipv4 and ipv6.
Definition at line 339 of file Socket.cpp.
References GetPort(), and m_remote_address.
00340 { 00341 if (!m_remote_address.get()) 00342 { 00343 return 0; 00344 } 00345 return m_remote_address -> GetPort(); 00346 }
std::string Socket::GetRemoteAddress | ( | ) |
Returns remote ip as string? ipv4 and ipv6.
Definition at line 349 of file Socket.cpp.
References m_remote_address.
00350 { 00351 if (!m_remote_address.get()) 00352 { 00353 return ""; 00354 } 00355 return m_remote_address -> Convert(false); 00356 }
std::string Socket::GetRemoteHostname | ( | ) |
ipv4 and ipv6(not implemented)
Definition at line 359 of file Socket.cpp.
References m_remote_address.
00360 { 00361 if (!m_remote_address.get()) 00362 { 00363 return ""; 00364 } 00365 return m_remote_address -> Reverse(); 00366 }
bool Socket::SetIpOptions | ( | const void * | p, | |
socklen_t | len | |||
) |
Definition at line 966 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
00967 { 00968 #ifdef IP_OPTIONS 00969 if (setsockopt(GetSocket(), IPPROTO_IP, IP_OPTIONS, (char *)p, len) == -1) 00970 { 00971 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_OPTIONS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 00972 return false; 00973 } 00974 return true; 00975 #else 00976 Handler().LogError(this, "ip option not available", 0, "IP_OPTIONS", LOG_LEVEL_INFO); 00977 return false; 00978 #endif 00979 }
bool Socket::SetIpTOS | ( | unsigned char | tos | ) |
Definition at line 1052 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01053 { 01054 #ifdef IP_TOS 01055 if (setsockopt(GetSocket(), IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(tos)) == -1) 01056 { 01057 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01058 return false; 01059 } 01060 return true; 01061 #else 01062 Handler().LogError(this, "ip option not available", 0, "IP_TOS", LOG_LEVEL_INFO); 01063 return false; 01064 #endif 01065 }
unsigned char Socket::IpTOS | ( | ) |
Definition at line 1068 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01069 { 01070 unsigned char tos = 0; 01071 #ifdef IP_TOS 01072 socklen_t len = sizeof(tos); 01073 if (getsockopt(GetSocket(), IPPROTO_IP, IP_TOS, (char *)&tos, &len) == -1) 01074 { 01075 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01076 } 01077 #else 01078 Handler().LogError(this, "ip option not available", 0, "IP_TOS", LOG_LEVEL_INFO); 01079 #endif 01080 return tos; 01081 }
bool Socket::SetIpTTL | ( | int | ttl | ) |
Definition at line 1084 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01085 { 01086 #ifdef IP_TTL 01087 if (setsockopt(GetSocket(), IPPROTO_IP, IP_TTL, (char *)&ttl, sizeof(ttl)) == -1) 01088 { 01089 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01090 return false; 01091 } 01092 return true; 01093 #else 01094 Handler().LogError(this, "ip option not available", 0, "IP_TTL", LOG_LEVEL_INFO); 01095 return false; 01096 #endif 01097 }
int Socket::IpTTL | ( | ) |
Definition at line 1100 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01101 { 01102 int ttl = 0; 01103 #ifdef IP_TTL 01104 socklen_t len = sizeof(ttl); 01105 if (getsockopt(GetSocket(), IPPROTO_IP, IP_TTL, (char *)&ttl, &len) == -1) 01106 { 01107 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01108 } 01109 #else 01110 Handler().LogError(this, "ip option not available", 0, "IP_TTL", LOG_LEVEL_INFO); 01111 #endif 01112 return ttl; 01113 }
bool Socket::SetIpHdrincl | ( | bool | x = true |
) |
Definition at line 1116 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01117 { 01118 #ifdef IP_HDRINCL 01119 int optval = x ? 1 : 0; 01120 if (setsockopt(GetSocket(), IPPROTO_IP, IP_HDRINCL, (char *)&optval, sizeof(optval)) == -1) 01121 { 01122 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_HDRINCL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01123 return false; 01124 } 01125 return true; 01126 #else 01127 Handler().LogError(this, "ip option not available", 0, "IP_HDRINCL", LOG_LEVEL_INFO); 01128 return false; 01129 #endif 01130 }
bool Socket::SetIpMulticastTTL | ( | int | ) |
Definition at line 1189 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01190 { 01191 #ifdef IP_MULTICAST_TTL 01192 if (setsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) == -1) 01193 { 01194 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01195 return false; 01196 } 01197 return true; 01198 #else 01199 Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_TTL", LOG_LEVEL_INFO); 01200 return false; 01201 #endif 01202 }
int Socket::IpMulticastTTL | ( | ) |
Definition at line 1205 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01206 { 01207 int ttl = 0; 01208 #ifdef IP_MULTICAST_TTL 01209 socklen_t len = sizeof(ttl); 01210 if (getsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, &len) == -1) 01211 { 01212 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01213 } 01214 #else 01215 Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_TTL", LOG_LEVEL_INFO); 01216 #endif 01217 return ttl; 01218 }
bool Socket::SetMulticastLoop | ( | bool | x = true |
) |
Reimplemented in UdpSocket.
Definition at line 1221 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01222 { 01223 #ifdef IP_MULTICAST_LOOP 01224 int optval = x ? 1 : 0; 01225 if (setsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&optval, sizeof(optval)) == -1) 01226 { 01227 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_LOOP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01228 return false; 01229 } 01230 return true; 01231 #else 01232 Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_LOOP", LOG_LEVEL_INFO); 01233 return false; 01234 #endif 01235 }
bool Socket::IpAddMembership | ( | struct ip_mreq & | ) |
Definition at line 1256 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01257 { 01258 #ifdef IP_ADD_MEMBERSHIP 01259 if (setsockopt(GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreq)) == -1) 01260 { 01261 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01262 return false; 01263 } 01264 return true; 01265 #else 01266 Handler().LogError(this, "ip option not available", 0, "IP_ADD_MEMBERSHIP", LOG_LEVEL_INFO); 01267 return false; 01268 #endif 01269 }
bool Socket::IpDropMembership | ( | struct ip_mreq & | ) |
Definition at line 1290 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01291 { 01292 #ifdef IP_DROP_MEMBERSHIP 01293 if (setsockopt(GetSocket(), IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreq)) == -1) 01294 { 01295 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_DROP_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01296 return false; 01297 } 01298 return true; 01299 #else 01300 Handler().LogError(this, "ip option not available", 0, "IP_DROP_MEMBERSHIP", LOG_LEVEL_INFO); 01301 return false; 01302 #endif 01303 }
bool Socket::SoAcceptconn | ( | ) |
Definition at line 1357 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01358 { 01359 int value = 0; 01360 #ifdef SO_ACCEPTCONN 01361 socklen_t len = sizeof(value); 01362 if (getsockopt(GetSocket(), SOL_SOCKET, SO_ACCEPTCONN, (char *)&value, &len) == -1) 01363 { 01364 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_ACCEPTCONN)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01365 } 01366 #else 01367 Handler().LogError(this, "socket option not available", 0, "SO_ACCEPTCONN", LOG_LEVEL_INFO); 01368 #endif 01369 return value ? true : false; 01370 }
bool Socket::SetSoBroadcast | ( | bool | x = true |
) |
Definition at line 1400 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01401 { 01402 #ifdef SO_BROADCAST 01403 int optval = x ? 1 : 0; 01404 if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof(optval)) == -1) 01405 { 01406 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BROADCAST)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01407 return false; 01408 } 01409 return true; 01410 #else 01411 Handler().LogError(this, "socket option not available", 0, "SO_BROADCAST", LOG_LEVEL_INFO); 01412 return false; 01413 #endif 01414 }
bool Socket::SetSoDebug | ( | bool | x = true |
) |
Definition at line 1417 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01418 { 01419 #ifdef SO_DEBUG 01420 int optval = x ? 1 : 0; 01421 if (setsockopt(GetSocket(), SOL_SOCKET, SO_DEBUG, (char *)&optval, sizeof(optval)) == -1) 01422 { 01423 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_DEBUG)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01424 return false; 01425 } 01426 return true; 01427 #else 01428 Handler().LogError(this, "socket option not available", 0, "SO_DEBUG", LOG_LEVEL_INFO); 01429 return false; 01430 #endif 01431 }
int Socket::SoError | ( | ) |
Definition at line 1434 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
Referenced by OnException(), TcpSocket::OnWrite(), and SctpSocket::OnWrite().
01435 { 01436 int value = 0; 01437 #ifdef SO_ERROR 01438 socklen_t len = sizeof(value); 01439 if (getsockopt(GetSocket(), SOL_SOCKET, SO_ERROR, (char *)&value, &len) == -1) 01440 { 01441 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_ERROR)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01442 } 01443 #else 01444 Handler().LogError(this, "socket option not available", 0, "SO_ERROR", LOG_LEVEL_INFO); 01445 #endif 01446 return value ? true : false; 01447 }
bool Socket::SetSoDontroute | ( | bool | x = true |
) |
Definition at line 1450 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01451 { 01452 #ifdef SO_DONTROUTE 01453 int optval = x ? 1 : 0; 01454 if (setsockopt(GetSocket(), SOL_SOCKET, SO_DONTROUTE, (char *)&optval, sizeof(optval)) == -1) 01455 { 01456 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_DONTROUTE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01457 return false; 01458 } 01459 return true; 01460 #else 01461 Handler().LogError(this, "socket option not available", 0, "SO_DONTROUTE", LOG_LEVEL_INFO); 01462 return false; 01463 #endif 01464 }
bool Socket::SetSoLinger | ( | int | onoff, | |
int | linger | |||
) |
Definition at line 1467 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01468 { 01469 #ifdef SO_LINGER 01470 struct linger stl; 01471 stl.l_onoff = onoff; 01472 stl.l_linger = linger; 01473 if (setsockopt(GetSocket(), SOL_SOCKET, SO_LINGER, (char *)&stl, sizeof(stl)) == -1) 01474 { 01475 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_LINGER)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01476 return false; 01477 } 01478 return true; 01479 #else 01480 Handler().LogError(this, "socket option not available", 0, "SO_LINGER", LOG_LEVEL_INFO); 01481 return false; 01482 #endif 01483 }
bool Socket::SetSoOobinline | ( | bool | x = true |
) |
Definition at line 1486 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01487 { 01488 #ifdef SO_OOBINLINE 01489 int optval = x ? 1 : 0; 01490 if (setsockopt(GetSocket(), SOL_SOCKET, SO_OOBINLINE, (char *)&optval, sizeof(optval)) == -1) 01491 { 01492 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_OOBINLINE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01493 return false; 01494 } 01495 return true; 01496 #else 01497 Handler().LogError(this, "socket option not available", 0, "SO_OOBINLINE", LOG_LEVEL_INFO); 01498 return false; 01499 #endif 01500 }
bool Socket::SetSoRcvlowat | ( | int | ) |
Definition at line 1543 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01544 { 01545 #ifdef SO_RCVLOWAT 01546 if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVLOWAT, (char *)&x, sizeof(x)) == -1) 01547 { 01548 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVLOWAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01549 return false; 01550 } 01551 return true; 01552 #else 01553 Handler().LogError(this, "socket option not available", 0, "SO_RCVLOWAT", LOG_LEVEL_INFO); 01554 return false; 01555 #endif 01556 }
bool Socket::SetSoSndlowat | ( | int | ) |
Definition at line 1559 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01560 { 01561 #ifdef SO_SNDLOWAT 01562 if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDLOWAT, (char *)&x, sizeof(x)) == -1) 01563 { 01564 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDLOWAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01565 return false; 01566 } 01567 return true; 01568 #else 01569 Handler().LogError(this, "socket option not available", 0, "SO_SNDLOWAT", LOG_LEVEL_INFO); 01570 return false; 01571 #endif 01572 }
bool Socket::SetSoRcvtimeo | ( | struct timeval & | ) |
Definition at line 1575 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01576 { 01577 #ifdef SO_RCVTIMEO 01578 if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) == -1) 01579 { 01580 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVTIMEO)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01581 return false; 01582 } 01583 return true; 01584 #else 01585 Handler().LogError(this, "socket option not available", 0, "SO_RCVTIMEO", LOG_LEVEL_INFO); 01586 return false; 01587 #endif 01588 }
bool Socket::SetSoSndtimeo | ( | struct timeval & | ) |
Definition at line 1591 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01592 { 01593 #ifdef SO_SNDTIMEO 01594 if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv)) == -1) 01595 { 01596 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDTIMEO)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01597 return false; 01598 } 01599 return true; 01600 #else 01601 Handler().LogError(this, "socket option not available", 0, "SO_SNDTIMEO", LOG_LEVEL_INFO); 01602 return false; 01603 #endif 01604 }
bool Socket::SetSoRcvbuf | ( | int | ) |
Definition at line 1607 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01608 { 01609 #ifdef SO_RCVBUF 01610 if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUF, (char *)&x, sizeof(x)) == -1) 01611 { 01612 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01613 return false; 01614 } 01615 return true; 01616 #else 01617 Handler().LogError(this, "socket option not available", 0, "SO_RCVBUF", LOG_LEVEL_INFO); 01618 return false; 01619 #endif 01620 }
int Socket::SoRcvbuf | ( | ) |
Definition at line 1623 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01624 { 01625 int value = 0; 01626 #ifdef SO_RCVBUF 01627 socklen_t len = sizeof(value); 01628 if (getsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUF, (char *)&value, &len) == -1) 01629 { 01630 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01631 } 01632 #else 01633 Handler().LogError(this, "socket option not available", 0, "SO_RCVBUF", LOG_LEVEL_INFO); 01634 #endif 01635 return value ? true : false; 01636 }
bool Socket::SetSoSndbuf | ( | int | ) |
Definition at line 1652 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01653 { 01654 #ifdef SO_SNDBUF 01655 if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUF, (char *)&x, sizeof(x)) == -1) 01656 { 01657 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01658 return false; 01659 } 01660 return true; 01661 #else 01662 Handler().LogError(this, "socket option not available", 0, "SO_SNDBUF", LOG_LEVEL_INFO); 01663 return false; 01664 #endif 01665 }
int Socket::SoSndbuf | ( | ) |
Definition at line 1668 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01669 { 01670 int value = 0; 01671 #ifdef SO_SNDBUF 01672 socklen_t len = sizeof(value); 01673 if (getsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUF, (char *)&value, &len) == -1) 01674 { 01675 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01676 } 01677 #else 01678 Handler().LogError(this, "socket option not available", 0, "SO_SNDBUF", LOG_LEVEL_INFO); 01679 #endif 01680 return value ? true : false; 01681 }
int Socket::SoType | ( | ) |
Definition at line 1711 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
01712 { 01713 int value = 0; 01714 #ifdef SO_TYPE 01715 socklen_t len = sizeof(value); 01716 if (getsockopt(GetSocket(), SOL_SOCKET, SO_TYPE, (char *)&value, &len) == -1) 01717 { 01718 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_TYPE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01719 } 01720 #else 01721 Handler().LogError(this, "socket option not available", 0, "SO_TYPE", LOG_LEVEL_INFO); 01722 #endif 01723 return value ? true : false; 01724 }
bool Socket::SetSoReuseaddr | ( | bool | x = true |
) |
Definition at line 1309 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
Referenced by TcpSocket::OnOptions().
01310 { 01311 #ifdef SO_REUSEADDR 01312 int optval = x ? 1 : 0; 01313 if (setsockopt(GetSocket(), SOL_SOCKET, SO_REUSEADDR, (char *)&optval, sizeof(optval)) == -1) 01314 { 01315 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_REUSEADDR)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01316 return false; 01317 } 01318 return true; 01319 #else 01320 Handler().LogError(this, "socket option not available", 0, "SO_REUSEADDR", LOG_LEVEL_INFO); 01321 return false; 01322 #endif 01323 }
bool Socket::SetSoKeepalive | ( | bool | x = true |
) |
Definition at line 1326 of file Socket.cpp.
References Errno, GetSocket(), Handler(), LOG_LEVEL_FATAL, LOG_LEVEL_INFO, ISocketHandler::LogError(), and StrError.
Referenced by TcpSocket::OnOptions().
01327 { 01328 #ifdef SO_KEEPALIVE 01329 int optval = x ? 1 : 0; 01330 if (setsockopt(GetSocket(), SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) == -1) 01331 { 01332 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_KEEPALIVE)", Errno, StrError(Errno), LOG_LEVEL_FATAL); 01333 return false; 01334 } 01335 return true; 01336 #else 01337 Handler().LogError(this, "socket option not available", 0, "SO_KEEPALIVE", LOG_LEVEL_INFO); 01338 return false; 01339 #endif 01340 }
void Socket::OnSSLConnect | ( | ) | [virtual] |
SSL client/server support - internal use.
Reimplemented in TcpSocket.
Definition at line 603 of file Socket.cpp.
void Socket::OnSSLAccept | ( | ) | [virtual] |
SSL client/server support - internal use.
Reimplemented in TcpSocket.
Definition at line 608 of file Socket.cpp.
void Socket::OnSSLConnectFailed | ( | ) | [virtual] |
SSL negotiation failed for client connect.
Definition at line 655 of file Socket.cpp.
Referenced by TcpSocket::SSLNegotiate().
void Socket::OnSSLAcceptFailed | ( | ) | [virtual] |
SSL negotiation failed for server accept.
Definition at line 660 of file Socket.cpp.
Referenced by TcpSocket::SSLNegotiate().
bool Socket::SSLNegotiate | ( | ) | [virtual] |
bool Socket::IsSSL | ( | ) |
Check if SSL is Enabled for this TcpSocket.
Definition at line 619 of file Socket.cpp.
References m_b_enable_ssl.
Referenced by TcpSocket::Close(), TcpSocket::OnRead(), and TcpSocket::TryWrite().
00620 { 00621 return m_b_enable_ssl; 00622 }
void Socket::EnableSSL | ( | bool | x = true |
) |
Enable SSL operation for a TcpSocket.
Definition at line 625 of file Socket.cpp.
References m_b_enable_ssl.
Referenced by HttpDebugSocket::Init(), and HTTPSocket::url_this().
00626 { 00627 m_b_enable_ssl = x; 00628 }
bool Socket::IsSSLNegotiate | ( | ) |
Still negotiating ssl connection.
Definition at line 631 of file Socket.cpp.
References m_b_ssl.
00632 { 00633 return m_b_ssl; 00634 }
void Socket::SetSSLNegotiate | ( | bool | x = true |
) |
Set flag indicating ssl handshaking still in progress.
Definition at line 637 of file Socket.cpp.
References m_b_ssl.
Referenced by TcpSocket::OnSSLAccept(), TcpSocket::OnSSLConnect(), and TcpSocket::SSLNegotiate().
00638 { 00639 m_b_ssl = x; 00640 }
bool Socket::IsSSLServer | ( | ) |
OnAccept called with SSL Enabled.
Definition at line 643 of file Socket.cpp.
References m_b_ssl_server.
Referenced by TcpSocket::SSLNegotiate().
00644 { 00645 return m_b_ssl_server; 00646 }
void Socket::SetSSLServer | ( | bool | x = true |
) |
Set flag indicating that this is a TcpSocket with incoming SSL connection.
Definition at line 649 of file Socket.cpp.
References m_b_ssl_server.
Referenced by TcpSocket::OnSSLAccept().
00650 { 00651 m_b_ssl_server = x; 00652 }
virtual SSL_CTX* Socket::GetSslContext | ( | ) | [inline, virtual] |
virtual SSL* Socket::GetSsl | ( | ) | [inline, virtual] |
void Socket::SetIsClient | ( | ) |
Client = connecting TcpSocket.
Definition at line 681 of file Socket.cpp.
References m_bClient.
Referenced by TcpSocket::Open().
00682 { 00683 m_bClient = true; 00684 }
void Socket::SetSocketType | ( | int | x | ) |
Socket type from socket() call.
Definition at line 687 of file Socket.cpp.
References m_socket_type.
Referenced by CopyConnection().
00688 { 00689 m_socket_type = x; 00690 }
int Socket::GetSocketType | ( | ) |
Socket type from socket() call.
Definition at line 693 of file Socket.cpp.
References m_socket_type.
Referenced by CopyConnection().
00694 { 00695 return m_socket_type; 00696 }
void Socket::SetSocketProtocol | ( | const std::string & | x | ) |
Protocol type from socket() call.
Definition at line 699 of file Socket.cpp.
References m_socket_protocol.
Referenced by CopyConnection().
00700 { 00701 m_socket_protocol = x; 00702 }
const std::string & Socket::GetSocketProtocol | ( | ) |
Protocol type from socket() call.
Definition at line 705 of file Socket.cpp.
References m_socket_protocol.
Referenced by CopyConnection().
00706 { 00707 return m_socket_protocol; 00708 }
void Socket::SetRetain | ( | ) |
Instruct a client socket to stay open in the connection pool after use.
If you have connected to a server using tcp, you can call SetRetain to leave the connection open after your socket instance has been deleted. The next connection you make to the same server will reuse the already opened connection, if it is still available.
Definition at line 711 of file Socket.cpp.
References m_bClient, and m_bRetain.
Referenced by HTTPSocket::OnLine().
bool Socket::Retain | ( | ) |
Check retain flag.
Definition at line 717 of file Socket.cpp.
References m_bRetain.
00718 { 00719 return m_bRetain; 00720 }
void Socket::SetLost | ( | ) |
Connection lost - error while reading/writing from a socket - TcpSocket only.
Definition at line 723 of file Socket.cpp.
References m_bLost.
Referenced by TcpSocket::OnRead(), and TcpSocket::TryWrite().
00724 { 00725 m_bLost = true; 00726 }
bool Socket::Lost | ( | ) |
Check connection lost status flag, used by TcpSocket only.
Definition at line 729 of file Socket.cpp.
References m_bLost.
00730 { 00731 return m_bLost; 00732 }
void Socket::CopyConnection | ( | Socket * | sock | ) |
Copy connection parameters from sock.
Definition at line 667 of file Socket.cpp.
References Attach(), GetClientRemoteAddress(), GetRemoteSocketAddress(), GetSocket(), GetSocketProtocol(), GetSocketType(), SetClientRemoteAddress(), SetRemoteAddress(), SetSocketProtocol(), and SetSocketType().
Referenced by TcpSocket::Open().
00668 { 00669 Attach( sock -> GetSocket() ); 00670 #ifdef ENABLE_IPV6 00671 SetIpv6( sock -> IsIpv6() ); 00672 #endif 00673 SetSocketType( sock -> GetSocketType() ); 00674 SetSocketProtocol( sock -> GetSocketProtocol() ); 00675 00676 SetClientRemoteAddress( *sock -> GetClientRemoteAddress() ); 00677 SetRemoteAddress( *sock -> GetRemoteSocketAddress() ); 00678 }
void Socket::OnSocks4Connect | ( | ) | [virtual] |
Socks4 client support internal use.
Reimplemented in TcpSocket.
Definition at line 737 of file Socket.cpp.
References Handler(), and ISocketHandler::LogError().
void Socket::OnSocks4ConnectFailed | ( | ) | [virtual] |
Socks4 client support internal use.
Reimplemented in TcpSocket.
Definition at line 743 of file Socket.cpp.
References Handler(), and ISocketHandler::LogError().
Referenced by SctpSocket::OnConnectTimeout(), and SctpSocket::OnWrite().
00744 { 00745 Handler().LogError(this, "OnSocks4ConnectFailed", 0, "Use with TcpSocket only"); 00746 }
bool Socket::OnSocks4Read | ( | ) | [virtual] |
Socks4 client support internal use.
Reimplemented in TcpSocket.
Definition at line 749 of file Socket.cpp.
References Handler(), and ISocketHandler::LogError().
00750 { 00751 Handler().LogError(this, "OnSocks4Read", 0, "Use with TcpSocket only"); 00752 return true; 00753 }
bool Socket::Socks4 | ( | ) |
socket still in socks4 negotiation mode
Definition at line 762 of file Socket.cpp.
References m_bSocks4.
Referenced by TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), TcpSocket::OnRead(), TcpSocket::OnWrite(), SctpSocket::OnWrite(), and TcpSocket::Open().
00763 { 00764 return m_bSocks4; 00765 }
void Socket::SetSocks4 | ( | bool | x = true |
) |
Set flag indicating Socks4 handshaking in progress.
Definition at line 768 of file Socket.cpp.
References m_bSocks4.
Referenced by TcpSocket::OnSocks4Read(), and TcpSocket::Open().
00769 { 00770 m_bSocks4 = x; 00771 }
void Socket::SetSocks4Host | ( | ipaddr_t | a | ) |
Set socks4 server host address to use.
Definition at line 774 of file Socket.cpp.
References m_socks4_host.
00775 { 00776 m_socks4_host = a; 00777 }
void Socket::SetSocks4Host | ( | const std::string & | ) |
Set socks4 server hostname to use.
Definition at line 756 of file Socket.cpp.
References m_socks4_host, and Utility::u2ip().
00757 { 00758 Utility::u2ip(host, m_socks4_host); 00759 }
void Socket::SetSocks4Port | ( | port_t | p | ) |
Socks4 server port to use.
Definition at line 780 of file Socket.cpp.
References m_socks4_port.
00781 { 00782 m_socks4_port = p; 00783 }
void Socket::SetSocks4Userid | ( | const std::string & | x | ) |
Provide a socks4 userid if required by the socks4 server.
Definition at line 786 of file Socket.cpp.
References m_socks4_userid.
00787 { 00788 m_socks4_userid = x; 00789 }
ipaddr_t Socket::GetSocks4Host | ( | ) |
Get the ip address of socks4 server to use.
Definition at line 792 of file Socket.cpp.
References m_socks4_host.
Referenced by TcpSocket::Open().
00793 { 00794 return m_socks4_host; 00795 }
port_t Socket::GetSocks4Port | ( | ) |
Get the socks4 server port to use.
Definition at line 798 of file Socket.cpp.
References m_socks4_port.
Referenced by TcpSocket::Open().
00799 { 00800 return m_socks4_port; 00801 }
const std::string & Socket::GetSocks4Userid | ( | ) |
Get socks4 userid.
Definition at line 804 of file Socket.cpp.
References m_socks4_userid.
Referenced by TcpSocket::OnSocks4Connect().
00805 { 00806 return m_socks4_userid; 00807 }
int Socket::Resolve | ( | const std::string & | host, | |
port_t | port = 0 | |||
) |
Request an asynchronous dns resolution.
host | hostname to be resolved | |
port | port number passed along for the ride |
Definition at line 912 of file Socket.cpp.
References Handler(), and ISocketHandler::Resolve().
Referenced by TcpSocket::Open().
Callback returning a resolved address.
id | Resolve ID from Resolve call | |
a | resolved ip address | |
port | port number passed to Resolve |
Reimplemented in TcpSocket.
Definition at line 940 of file Socket.cpp.
int Socket::Resolve | ( | ipaddr_t | a | ) |
Request asynchronous reverse dns lookup.
a | in_addr to be translated |
Definition at line 926 of file Socket.cpp.
References Handler(), and ISocketHandler::Resolve().
void Socket::OnReverseResolved | ( | int | id, | |
const std::string & | name | |||
) | [virtual] |
Callback returning reverse resolve results.
id | Resolve ID | |
name | Resolved hostname |
Definition at line 952 of file Socket.cpp.
Referenced by ResolvSocket::OnLine().
void Socket::OnResolveFailed | ( | int | id | ) | [virtual] |
Callback indicating failed dns lookup.
id | Resolve ID |
Definition at line 957 of file Socket.cpp.
Referenced by ResolvSocket::OnDelete(), and ResolvSocket::OnLine().
void Socket::OnDetached | ( | ) | [virtual] |
Callback fires when a new socket thread has started and this socket is ready for operation again.
Reimplemented in ResolvSocket.
Definition at line 833 of file Socket.cpp.
Referenced by Socket::SocketThread::Run().
void Socket::SetDetach | ( | bool | x = true |
) |
Internal use.
Definition at line 838 of file Socket.cpp.
References ISocketHandler::AddList(), Handler(), LIST_DETACH, m_detach, and m_socket.
Referenced by Detach().
00839 { 00840 Handler().AddList(m_socket, LIST_DETACH, x); 00841 m_detach = x; 00842 }
bool Socket::IsDetach | ( | ) |
Check detach flag.
Definition at line 845 of file Socket.cpp.
References m_detach.
00846 { 00847 return m_detach; 00848 }
void Socket::SetDetached | ( | bool | x = true |
) |
Internal use.
Definition at line 851 of file Socket.cpp.
References m_detached.
Referenced by DetachSocket().
00852 { 00853 m_detached = x; 00854 }
const bool Socket::IsDetached | ( | ) | const |
Check detached flag.
Definition at line 857 of file Socket.cpp.
References m_detached.
Referenced by Handler().
00858 { 00859 return m_detached; 00860 }
bool Socket::Detach | ( | ) |
Order this socket to start its own thread and call OnDetached when ready for operation.
Definition at line 812 of file Socket.cpp.
References DeleteByHandler(), m_detached, m_pThread, and SetDetach().
Referenced by ResolvSocket::OnLine().
00813 { 00814 if (!DeleteByHandler()) 00815 return false; 00816 if (m_pThread) 00817 return false; 00818 if (m_detached) 00819 return false; 00820 SetDetach(); 00821 return true; 00822 }
void Socket::SetSlaveHandler | ( | ISocketHandler * | ) |
Store the slave sockethandler pointer.
Definition at line 863 of file Socket.cpp.
References m_slave_handler.
Referenced by Socket::SocketThread::Run().
00864 { 00865 m_slave_handler = p; 00866 }
void Socket::DetachSocket | ( | ) |
Create new thread for this socket to run detached in.
Definition at line 825 of file Socket.cpp.
References m_pThread, and SetDetached().
00826 { 00827 SetDetached(); 00828 m_pThread = new SocketThread(this); 00829 m_pThread -> SetRelease(true); 00830 }
void Socket::SetTrafficMonitor | ( | IFile * | p | ) | [inline] |
Write traffic to an IFile.
Socket will not delete this object.
Definition at line 635 of file Socket.h.
00635 { m_traffic_monitor = p; }
IFile* Socket::GetTrafficMonitor | ( | ) | [inline, protected] |
All traffic will be written to this IFile, if set.
Definition at line 661 of file Socket.h.
Referenced by TcpSocket::OnRead(), and TcpSocket::TryWrite().
00661 { return m_traffic_monitor; }
friend class ISocketHandler [friend] |
ISocketHandler& Socket::m_handler [private] |
Reference of ISocketHandler in control of this socket.
Definition at line 666 of file Socket.h.
Referenced by Handler(), and MasterHandler().
SOCKET Socket::m_socket [private] |
File descriptor.
Definition at line 667 of file Socket.h.
Referenced by Attach(), Close(), GetSocket(), Ready(), Set(), SetCloseAndDelete(), SetDetach(), SetNonblocking(), SetTimeout(), and ~Socket().
bool Socket::m_bDel [private] |
Delete by handler flag.
Definition at line 668 of file Socket.h.
Referenced by DeleteByHandler(), and SetDeleteByHandler().
bool Socket::m_bClose [private] |
Close and delete flag.
Definition at line 669 of file Socket.h.
Referenced by CloseAndDelete(), and SetCloseAndDelete().
time_t Socket::m_tCreate [private] |
Socket* Socket::m_parent [private] |
Pointer to ListenSocket class, valid for incoming sockets.
Reimplemented in ResolvSocket.
Definition at line 671 of file Socket.h.
Referenced by GetParent(), and SetParent().
bool Socket::m_b_disable_read [private] |
Disable checking for read events.
Definition at line 672 of file Socket.h.
Referenced by DisableRead(), and IsDisableRead().
bool Socket::m_connected [private] |
Socket is connected (tcp/udp).
Definition at line 673 of file Socket.h.
Referenced by IsConnected(), and SetConnected().
bool Socket::m_b_erased_by_handler [private] |
Set by handler before delete.
Definition at line 674 of file Socket.h.
Referenced by ErasedByHandler(), and SetErasedByHandler().
time_t Socket::m_tClose [private] |
Time in seconds when ordered to close.
Definition at line 675 of file Socket.h.
Referenced by SetCloseAndDelete(), and TimeSinceClose().
std::auto_ptr<SocketAddress> Socket::m_client_remote_address [private] |
Address of last connect().
Definition at line 676 of file Socket.h.
Referenced by GetClientRemoteAddress(), and SetClientRemoteAddress().
std::auto_ptr<SocketAddress> Socket::m_remote_address [private] |
Remote end address.
Definition at line 677 of file Socket.h.
Referenced by GetRemoteAddress(), GetRemoteHostname(), GetRemoteIP4(), GetRemotePort(), GetRemoteSocketAddress(), and SetRemoteAddress().
IFile* Socket::m_traffic_monitor [private] |
time_t Socket::m_timeout_start [private] |
Set by SetTimeout.
Definition at line 679 of file Socket.h.
Referenced by SetTimeout(), and Timeout().
time_t Socket::m_timeout_limit [private] |
Defined by SetTimeout.
Definition at line 680 of file Socket.h.
Referenced by SetTimeout(), and Timeout().
bool Socket::m_b_enable_ssl [private] |
Enable SSL for this TcpSocket.
Definition at line 687 of file Socket.h.
Referenced by EnableSSL(), and IsSSL().
bool Socket::m_b_ssl [private] |
ssl negotiation mode (TcpSocket)
Definition at line 688 of file Socket.h.
Referenced by IsSSLNegotiate(), and SetSSLNegotiate().
bool Socket::m_b_ssl_server [private] |
True if this is an incoming ssl TcpSocket connection.
Definition at line 689 of file Socket.h.
Referenced by IsSSLServer(), and SetSSLServer().
int Socket::m_socket_type [private] |
Type of socket, from socket() call.
Definition at line 697 of file Socket.h.
Referenced by CreateSocket(), GetSocketType(), and SetSocketType().
std::string Socket::m_socket_protocol [private] |
Protocol, from socket() call.
Definition at line 698 of file Socket.h.
Referenced by CreateSocket(), GetSocketProtocol(), and SetSocketProtocol().
bool Socket::m_bClient [private] |
only client connections are pooled
Definition at line 699 of file Socket.h.
Referenced by SetIsClient(), and SetRetain().
bool Socket::m_bRetain [private] |
keep connection on close
Definition at line 700 of file Socket.h.
Referenced by Retain(), SetRetain(), and ~Socket().
bool Socket::m_bLost [private] |
bool Socket::m_bSocks4 [private] |
socks4 negotiation mode (TcpSocket)
Definition at line 705 of file Socket.h.
Referenced by SetSocks4(), and Socks4().
ipaddr_t Socket::m_socks4_host [private] |
socks4 server address
Definition at line 706 of file Socket.h.
Referenced by GetSocks4Host(), and SetSocks4Host().
port_t Socket::m_socks4_port [private] |
socks4 server port number
Definition at line 707 of file Socket.h.
Referenced by GetSocks4Port(), and SetSocks4Port().
std::string Socket::m_socks4_userid [private] |
socks4 server usedid
Definition at line 708 of file Socket.h.
Referenced by GetSocks4Userid(), and SetSocks4Userid().
bool Socket::m_detach [private] |
Socket ordered to detach flag.
Definition at line 712 of file Socket.h.
Referenced by IsDetach(), and SetDetach().
bool Socket::m_detached [private] |
Socket has been detached.
Definition at line 713 of file Socket.h.
Referenced by Detach(), IsDetached(), and SetDetached().
SocketThread* Socket::m_pThread [private] |
Detach socket thread class pointer.
Definition at line 714 of file Socket.h.
Referenced by Detach(), and DetachSocket().
ISocketHandler* Socket::m_slave_handler [private] |
Actual sockethandler while detached.
Definition at line 715 of file Socket.h.
Referenced by Handler(), and SetSlaveHandler().