StreamSocket Class ReferenceSOCK_STREAM Socket base class.
More...
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Public Member Functions | |
| StreamSocket (ISocketHandler &) | |
| ~StreamSocket () | |
| void | SetConnecting (bool=true) |
| Socket should Check Connect on next write event from select(). | |
| bool | Connecting () |
| Check connecting flag. | |
| bool | Ready () |
| Returns true when socket file descriptor is valid, socket connection is established, and socket is not about to be closed. | |
| void | SetConnectTimeout (int x) |
| Set timeout to use for connection attempt. | |
| int | GetConnectTimeout () |
| Return number of seconds to wait for a connection. | |
| void | SetFlushBeforeClose (bool=true) |
| Set flush before close to make a tcp socket completely empty its output buffer before closing the connection. | |
| bool | GetFlushBeforeClose () |
| Check flush before status. | |
| void | SetConnectionRetry (int n) |
| Define number of connection retries (tcp only). | |
| int | GetConnectionRetry () |
| Get number of maximum connection retries (tcp only). | |
| void | IncreaseConnectionRetries () |
| Increase number of actual connection retries (tcp only). | |
| int | GetConnectionRetries () |
| Get number of actual connection retries (tcp only). | |
| void | ResetConnectionRetries () |
| Reset actual connection retries (tcp only). | |
| void | SetCallOnConnect (bool x=true) |
| Instruct socket to call OnConnect callback next sockethandler cycle. | |
| bool | CallOnConnect () |
| Check call on connect flag. | |
| void | SetRetryClientConnect (bool x=true) |
| Set flag to initiate a connection attempt after a connection timeout. | |
| bool | RetryClientConnect () |
| Check if a connection attempt should be made. | |
| virtual void | SetLineProtocol (bool=true) |
| Called after OnRead if socket is in line protocol mode. | |
| bool | LineProtocol () |
| Check line protocol mode. | |
| void | SetShutdown (int) |
| Set shutdown status. | |
| int | GetShutdown () |
| Get shutdown status. | |
| virtual int | Protocol ()=0 |
| Returns IPPROTO_TCP or IPPROTO_SCTP. | |
Protected Member Functions | |
| StreamSocket (const StreamSocket &) | |
Private Member Functions | |
| StreamSocket & | operator= (const StreamSocket &) |
Private Attributes | |
| bool | m_bConnecting |
| Flag indicating connection in progress. | |
| int | m_connect_timeout |
| Connection timeout (seconds). | |
| bool | m_flush_before_close |
| Send all data before closing (default true). | |
| int | m_connection_retry |
| Maximum connection retries (tcp). | |
| int | m_retries |
| Actual number of connection retries (tcp). | |
| bool | m_call_on_connect |
| OnConnect will be called next ISocketHandler cycle if true. | |
| bool | m_b_retry_connect |
| Try another connection attempt next ISocketHandler cycle. | |
| bool | m_line_protocol |
| Line protocol mode flag. | |
| int | m_shutdown |
| Shutdown status. | |
Definition at line 44 of file StreamSocket.h.
| StreamSocket::StreamSocket | ( | ISocketHandler & | h | ) |
Definition at line 40 of file StreamSocket.cpp.
00040 : Socket(h) 00041 ,m_bConnecting(false) 00042 ,m_connect_timeout(5) 00043 ,m_flush_before_close(true) 00044 ,m_connection_retry(0) 00045 ,m_retries(0) 00046 ,m_call_on_connect(false) 00047 ,m_b_retry_connect(false) 00048 ,m_line_protocol(false) 00049 ,m_shutdown(0) 00050 { 00051 }
| StreamSocket::~StreamSocket | ( | ) |
| StreamSocket::StreamSocket | ( | const StreamSocket & | ) | [inline, protected] |
| void StreamSocket::SetConnecting | ( | bool | x = true |
) |
Socket should Check Connect on next write event from select().
Definition at line 59 of file StreamSocket.cpp.
References GetConnectTimeout(), m_bConnecting, and Socket::SetTimeout().
Referenced by SctpSocket::AddConnection(), TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), TcpSocket::OnSocks4ConnectFailed(), TcpSocket::OnSocks4Read(), TcpSocket::OnWrite(), SctpSocket::OnWrite(), TcpSocket::Open(), and SctpSocket::Open().
00060 { 00061 if (x != m_bConnecting) 00062 { 00063 m_bConnecting = x; 00064 if (x) 00065 { 00066 SetTimeout( GetConnectTimeout() ); 00067 } 00068 else 00069 { 00070 SetTimeout( 0 ); 00071 } 00072 } 00073 }
| bool StreamSocket::Connecting | ( | ) |
Check connecting flag.
Definition at line 76 of file StreamSocket.cpp.
References m_bConnecting.
Referenced by HttpGetSocket::HttpGetSocket(), TcpSocket::OnWrite(), SctpSocket::OnWrite(), Ready(), and TcpSocket::SendBuf().
00077 { 00078 return m_bConnecting; 00079 }
| bool StreamSocket::Ready | ( | ) | [virtual] |
Returns true when socket file descriptor is valid, socket connection is established, and socket is not about to be closed.
Reimplemented from Socket.
Definition at line 82 of file StreamSocket.cpp.
References Socket::CloseAndDelete(), Connecting(), Socket::GetSocket(), and INVALID_SOCKET.
Referenced by TcpSocket::OnRead(), and TcpSocket::SendBuf().
00083 { 00084 if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete()) 00085 return true; 00086 return false; 00087 }
| void StreamSocket::SetConnectTimeout | ( | int | x | ) |
Set timeout to use for connection attempt.
| x | Timeout in seconds |
Definition at line 90 of file StreamSocket.cpp.
References m_connect_timeout.
00091 { 00092 m_connect_timeout = x; 00093 }
| int StreamSocket::GetConnectTimeout | ( | ) |
Return number of seconds to wait for a connection.
Definition at line 96 of file StreamSocket.cpp.
References m_connect_timeout.
Referenced by SetConnecting().
00097 { 00098 return m_connect_timeout; 00099 }
| void StreamSocket::SetFlushBeforeClose | ( | bool | x = true |
) |
Set flush before close to make a tcp socket completely empty its output buffer before closing the connection.
Definition at line 102 of file StreamSocket.cpp.
References m_flush_before_close.
Referenced by TcpSocket::OnRead(), and TcpSocket::TryWrite().
00103 { 00104 m_flush_before_close = x; 00105 }
| bool StreamSocket::GetFlushBeforeClose | ( | ) |
Check flush before status.
Definition at line 108 of file StreamSocket.cpp.
References m_flush_before_close.
00109 { 00110 return m_flush_before_close; 00111 }
| void StreamSocket::SetConnectionRetry | ( | int | n | ) |
Define number of connection retries (tcp only).
n = 0 - no retry n > 0 - number of retries n = -1 - unlimited retries
Definition at line 120 of file StreamSocket.cpp.
References m_connection_retry.
00121 { 00122 m_connection_retry = x; 00123 }
| int StreamSocket::GetConnectionRetry | ( | ) |
Get number of maximum connection retries (tcp only).
Definition at line 114 of file StreamSocket.cpp.
References m_connection_retry.
Referenced by TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), TcpSocket::OnWrite(), and SctpSocket::OnWrite().
00115 { 00116 return m_connection_retry; 00117 }
| void StreamSocket::IncreaseConnectionRetries | ( | ) |
Increase number of actual connection retries (tcp only).
Definition at line 132 of file StreamSocket.cpp.
References m_retries.
Referenced by TcpSocket::OnConnectTimeout(), and SctpSocket::OnConnectTimeout().
00133 { 00134 m_retries++; 00135 }
| int StreamSocket::GetConnectionRetries | ( | ) |
Get number of actual connection retries (tcp only).
Definition at line 126 of file StreamSocket.cpp.
References m_retries.
Referenced by TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), TcpSocket::OnWrite(), and SctpSocket::OnWrite().
00127 { 00128 return m_retries; 00129 }
| void StreamSocket::ResetConnectionRetries | ( | ) |
Reset actual connection retries (tcp only).
Definition at line 138 of file StreamSocket.cpp.
References m_retries.
00139 { 00140 m_retries = 0; 00141 }
| void StreamSocket::SetCallOnConnect | ( | bool | x = true |
) |
Instruct socket to call OnConnect callback next sockethandler cycle.
Definition at line 144 of file StreamSocket.cpp.
References ISocketHandler::AddList(), Socket::GetSocket(), Socket::Handler(), LIST_CALLONCONNECT, and m_call_on_connect.
Referenced by TcpSocket::OnWrite(), SctpSocket::OnWrite(), and TcpSocket::Open().
00145 { 00146 Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x); 00147 m_call_on_connect = x; 00148 }
| bool StreamSocket::CallOnConnect | ( | ) |
Check call on connect flag.
Definition at line 151 of file StreamSocket.cpp.
References m_call_on_connect.
00152 { 00153 return m_call_on_connect; 00154 }
| void StreamSocket::SetRetryClientConnect | ( | bool | x = true |
) |
Set flag to initiate a connection attempt after a connection timeout.
Definition at line 157 of file StreamSocket.cpp.
References ISocketHandler::AddList(), Socket::GetSocket(), Socket::Handler(), LIST_RETRY, and m_b_retry_connect.
Referenced by TcpSocket::OnConnectTimeout(), SctpSocket::OnConnectTimeout(), and TcpSocket::OnSocks4ConnectFailed().
00158 { 00159 Handler().AddList(GetSocket(), LIST_RETRY, x); 00160 m_b_retry_connect = x; 00161 }
| bool StreamSocket::RetryClientConnect | ( | ) |
Check if a connection attempt should be made.
Definition at line 164 of file StreamSocket.cpp.
References m_b_retry_connect.
00165 { 00166 return m_b_retry_connect; 00167 }
| void StreamSocket::SetLineProtocol | ( | bool | x = true |
) | [virtual] |
Called after OnRead if socket is in line protocol mode.
Reimplemented in TcpSocket.
Definition at line 170 of file StreamSocket.cpp.
References m_line_protocol.
Referenced by TcpSocket::SetLineProtocol().
00171 { 00172 m_line_protocol = x; 00173 }
| bool StreamSocket::LineProtocol | ( | ) |
Check line protocol mode.
Definition at line 176 of file StreamSocket.cpp.
References m_line_protocol.
Referenced by TcpSocket::OnRead().
00177 { 00178 return m_line_protocol; 00179 }
| void StreamSocket::SetShutdown | ( | int | x | ) |
Set shutdown status.
Definition at line 182 of file StreamSocket.cpp.
References m_shutdown.
Referenced by TcpSocket::OnRead().
00183 { 00184 m_shutdown = x; 00185 }
| int StreamSocket::GetShutdown | ( | ) |
Get shutdown status.
Definition at line 188 of file StreamSocket.cpp.
References m_shutdown.
Referenced by TcpSocket::Close().
00189 { 00190 return m_shutdown; 00191 }
| virtual int StreamSocket::Protocol | ( | ) | [pure virtual] |
| StreamSocket& StreamSocket::operator= | ( | const StreamSocket & | ) | [inline, private] |
bool StreamSocket::m_bConnecting [private] |
Flag indicating connection in progress.
Definition at line 139 of file StreamSocket.h.
Referenced by Connecting(), and SetConnecting().
int StreamSocket::m_connect_timeout [private] |
Connection timeout (seconds).
Definition at line 140 of file StreamSocket.h.
Referenced by GetConnectTimeout(), and SetConnectTimeout().
bool StreamSocket::m_flush_before_close [private] |
Send all data before closing (default true).
Definition at line 141 of file StreamSocket.h.
Referenced by GetFlushBeforeClose(), and SetFlushBeforeClose().
int StreamSocket::m_connection_retry [private] |
Maximum connection retries (tcp).
Definition at line 142 of file StreamSocket.h.
Referenced by GetConnectionRetry(), and SetConnectionRetry().
int StreamSocket::m_retries [private] |
Actual number of connection retries (tcp).
Definition at line 143 of file StreamSocket.h.
Referenced by GetConnectionRetries(), IncreaseConnectionRetries(), and ResetConnectionRetries().
bool StreamSocket::m_call_on_connect [private] |
OnConnect will be called next ISocketHandler cycle if true.
Definition at line 144 of file StreamSocket.h.
Referenced by CallOnConnect(), and SetCallOnConnect().
bool StreamSocket::m_b_retry_connect [private] |
Try another connection attempt next ISocketHandler cycle.
Definition at line 145 of file StreamSocket.h.
Referenced by RetryClientConnect(), and SetRetryClientConnect().
bool StreamSocket::m_line_protocol [private] |
Line protocol mode flag.
Definition at line 146 of file StreamSocket.h.
Referenced by LineProtocol(), and SetLineProtocol().
int StreamSocket::m_shutdown [private] |
Shutdown status.
Definition at line 147 of file StreamSocket.h.
Referenced by GetShutdown(), and SetShutdown().
1.4.4