added generic tool code
[anytun.git] / Sockets / StreamSocket.cpp
blob5c5780e308521baf40b37f0dba0a3ea8b1cec3d5
1 #include "StreamSocket.h"
2 #include "ISocketHandler.h"
5 #ifdef SOCKETS_NAMESPACE
6 namespace SOCKETS_NAMESPACE {
7 #endif
10 StreamSocket::StreamSocket(ISocketHandler& h) : Socket(h)
11 ,m_bConnecting(false)
12 ,m_connect_timeout(5)
13 ,m_flush_before_close(true)
14 ,m_connection_retry(0)
15 ,m_retries(0)
16 ,m_call_on_connect(false)
17 ,m_b_retry_connect(false)
18 ,m_line_protocol(false)
19 ,m_shutdown(0)
24 StreamSocket::~StreamSocket()
29 void StreamSocket::SetConnecting(bool x)
31 if (x != m_bConnecting)
33 m_bConnecting = x;
34 if (x)
36 SetTimeout( GetConnectTimeout() );
38 else
40 SetTimeout( 0 );
46 bool StreamSocket::Connecting()
48 return m_bConnecting;
52 bool StreamSocket::Ready()
54 if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete())
55 return true;
56 return false;
60 void StreamSocket::SetConnectTimeout(int x)
62 m_connect_timeout = x;
66 int StreamSocket::GetConnectTimeout()
68 return m_connect_timeout;
72 void StreamSocket::SetFlushBeforeClose(bool x)
74 m_flush_before_close = x;
78 bool StreamSocket::GetFlushBeforeClose()
80 return m_flush_before_close;
84 int StreamSocket::GetConnectionRetry()
86 return m_connection_retry;
90 void StreamSocket::SetConnectionRetry(int x)
92 m_connection_retry = x;
96 int StreamSocket::GetConnectionRetries()
98 return m_retries;
102 void StreamSocket::IncreaseConnectionRetries()
104 m_retries++;
108 void StreamSocket::ResetConnectionRetries()
110 m_retries = 0;
114 void StreamSocket::SetCallOnConnect(bool x)
116 Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x);
117 m_call_on_connect = x;
121 bool StreamSocket::CallOnConnect()
123 return m_call_on_connect;
127 void StreamSocket::SetRetryClientConnect(bool x)
129 Handler().AddList(GetSocket(), LIST_RETRY, x);
130 m_b_retry_connect = x;
134 bool StreamSocket::RetryClientConnect()
136 return m_b_retry_connect;
140 void StreamSocket::SetLineProtocol(bool x)
142 m_line_protocol = x;
146 bool StreamSocket::LineProtocol()
148 return m_line_protocol;
152 void StreamSocket::SetShutdown(int x)
154 m_shutdown = x;
158 int StreamSocket::GetShutdown()
160 return m_shutdown;
166 #ifdef SOCKETS_NAMESPACE
167 } // namespace SOCKETS_NAMESPACE {
168 #endif