1 | #include "StreamSocket.h" |
---|
2 | #include "ISocketHandler.h" |
---|
3 | |
---|
4 | |
---|
5 | #ifdef SOCKETS_NAMESPACE |
---|
6 | namespace SOCKETS_NAMESPACE { |
---|
7 | #endif |
---|
8 | |
---|
9 | |
---|
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) |
---|
20 | { |
---|
21 | } |
---|
22 | |
---|
23 | |
---|
24 | StreamSocket::~StreamSocket() |
---|
25 | { |
---|
26 | } |
---|
27 | |
---|
28 | |
---|
29 | void StreamSocket::SetConnecting(bool x) |
---|
30 | { |
---|
31 | if (x != m_bConnecting) |
---|
32 | { |
---|
33 | m_bConnecting = x; |
---|
34 | if (x) |
---|
35 | { |
---|
36 | SetTimeout( GetConnectTimeout() ); |
---|
37 | } |
---|
38 | else |
---|
39 | { |
---|
40 | SetTimeout( 0 ); |
---|
41 | } |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | bool StreamSocket::Connecting() |
---|
47 | { |
---|
48 | return m_bConnecting; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | bool StreamSocket::Ready() |
---|
53 | { |
---|
54 | if (GetSocket() != INVALID_SOCKET && !Connecting() && !CloseAndDelete()) |
---|
55 | return true; |
---|
56 | return false; |
---|
57 | } |
---|
58 | |
---|
59 | |
---|
60 | void StreamSocket::SetConnectTimeout(int x) |
---|
61 | { |
---|
62 | m_connect_timeout = x; |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | int StreamSocket::GetConnectTimeout() |
---|
67 | { |
---|
68 | return m_connect_timeout; |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | void StreamSocket::SetFlushBeforeClose(bool x) |
---|
73 | { |
---|
74 | m_flush_before_close = x; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | bool StreamSocket::GetFlushBeforeClose() |
---|
79 | { |
---|
80 | return m_flush_before_close; |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | int StreamSocket::GetConnectionRetry() |
---|
85 | { |
---|
86 | return m_connection_retry; |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | void StreamSocket::SetConnectionRetry(int x) |
---|
91 | { |
---|
92 | m_connection_retry = x; |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | int StreamSocket::GetConnectionRetries() |
---|
97 | { |
---|
98 | return m_retries; |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | void StreamSocket::IncreaseConnectionRetries() |
---|
103 | { |
---|
104 | m_retries++; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | void StreamSocket::ResetConnectionRetries() |
---|
109 | { |
---|
110 | m_retries = 0; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | void StreamSocket::SetCallOnConnect(bool x) |
---|
115 | { |
---|
116 | Handler().AddList(GetSocket(), LIST_CALLONCONNECT, x); |
---|
117 | m_call_on_connect = x; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | bool StreamSocket::CallOnConnect() |
---|
122 | { |
---|
123 | return m_call_on_connect; |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | void StreamSocket::SetRetryClientConnect(bool x) |
---|
128 | { |
---|
129 | Handler().AddList(GetSocket(), LIST_RETRY, x); |
---|
130 | m_b_retry_connect = x; |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | bool StreamSocket::RetryClientConnect() |
---|
135 | { |
---|
136 | return m_b_retry_connect; |
---|
137 | } |
---|
138 | |
---|
139 | |
---|
140 | void StreamSocket::SetLineProtocol(bool x) |
---|
141 | { |
---|
142 | m_line_protocol = x; |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | bool StreamSocket::LineProtocol() |
---|
147 | { |
---|
148 | return m_line_protocol; |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | void StreamSocket::SetShutdown(int x) |
---|
153 | { |
---|
154 | m_shutdown = x; |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | int StreamSocket::GetShutdown() |
---|
159 | { |
---|
160 | return m_shutdown; |
---|
161 | } |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | |
---|
166 | #ifdef SOCKETS_NAMESPACE |
---|
167 | } // namespace SOCKETS_NAMESPACE { |
---|
168 | #endif |
---|
169 | |
---|