Used a more uniform of logging and added a commandline parser.
[UnsignedByte.git] / src / Sockets / StreamSocket.cpp
blob0faccfeb674fd9e9481cd44d1d37002a0c7b383a
1 //#include <stdio.h>
3 #include "StreamSocket.h"
4 #include "ISocketHandler.h"
7 #ifdef SOCKETS_NAMESPACE
8 namespace SOCKETS_NAMESPACE {
9 #endif
12 StreamSocket::StreamSocket(ISocketHandler& h) : Socket(h)
13 ,m_bConnecting(false)
14 ,m_connect_timeout(5)
15 ,m_flush_before_close(true)
16 ,m_connection_retry(0)
17 ,m_retries(0)
18 ,m_call_on_connect(false)
19 ,m_b_retry_connect(false)
20 ,m_line_protocol(false)
21 ,m_shutdown(0)
26 StreamSocket::~StreamSocket()
31 void StreamSocket::SetConnecting(bool x)
33 if (x != m_bConnecting)
35 m_bConnecting = x;
36 if (x)
38 SetTimeout( GetConnectTimeout() );
40 else
42 SetTimeout( 0 );
48 bool StreamSocket::Connecting()
50 return m_bConnecting;
54 bool StreamSocket::Ready()
56 if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete())
57 return true;
58 return false;
62 void StreamSocket::SetConnectTimeout(int x)
64 m_connect_timeout = x;
68 int StreamSocket::GetConnectTimeout()
70 return m_connect_timeout;
74 void StreamSocket::SetFlushBeforeClose(bool x)
76 m_flush_before_close = x;
80 bool StreamSocket::GetFlushBeforeClose()
82 return m_flush_before_close;
86 int StreamSocket::GetConnectionRetry()
88 return m_connection_retry;
92 void StreamSocket::SetConnectionRetry(int x)
94 m_connection_retry = x;
98 int StreamSocket::GetConnectionRetries()
100 return m_retries;
104 void StreamSocket::IncreaseConnectionRetries()
106 m_retries++;
110 void StreamSocket::ResetConnectionRetries()
112 m_retries = 0;
116 void StreamSocket::SetCallOnConnect(bool x)
118 Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x);
119 m_call_on_connect = x;
123 bool StreamSocket::CallOnConnect()
125 return m_call_on_connect;
129 void StreamSocket::SetRetryClientConnect(bool x)
131 Handler().AddList(GetSocket(), LIST_RETRY, x);
132 m_b_retry_connect = x;
136 bool StreamSocket::RetryClientConnect()
138 return m_b_retry_connect;
142 void StreamSocket::SetLineProtocol(bool x)
144 m_line_protocol = x;
148 bool StreamSocket::LineProtocol()
150 return m_line_protocol;
154 void StreamSocket::SetShutdown(int x)
156 m_shutdown = x;
160 int StreamSocket::GetShutdown()
162 return m_shutdown;
168 #ifdef SOCKETS_NAMESPACE
169 } // namespace SOCKETS_NAMESPACE {
170 #endif