MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / TcpReceiveMessage

Function TcpReceiveMessage

source/tcpcon.cpp:178–287  ·  view source on GitHub ↗

---------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

176}
177//---------------------------------------------------------------------------
178void TcpReceiveMessage(void)
179{
180 int rl;
181 TSyslogdTcpConn * c;
182 MSocket * p;
183 for(int i=0; i<tcp_cons->Count; i++)
184 {
185 c = (TSyslogdTcpConn *)tcp_cons->Items[i];
186 p = c->Socket;
187
188 if( p->Poll(true, false, false, 0) ) // wait 0 msec
189 {
190 rl = p->ReadLength();
191
192 if( rl > 0 )
193 {
194 // Ready to receive rl bytes
195 if( p->Read(c->GetBufferSize(rl), rl) )
196 {
197 c->DataSize += rl;
198 }
199 else
200 {
201 if( p->bytes > 0 && p->bytes < rl )
202 {
203 c->DataSize += p->bytes;
204 WriteToLogError("WARNING\tTCP received %ld, wait %ld, error=%ld", p->bytes, rl, p->errcode);
205 }
206 else
207 {
208 if( p->errcode==WSAESHUTDOWN )
209 {
210 WriteToLogError("WARNING\tTCP shutdown from %s", p->GetRemoteAddrPort().c_str());
211 TcpDeleteConnection(i--);
212 continue;
213 }
214 else
215 {
216 WriteToLogError("ERROR\tTCP read(rl=%ld) from %s\tbytes=%ld error=%ld",
217 p->GetRemoteAddrPort().c_str(), rl, p->bytes, p->errcode);
218 }
219 }
220 }
221 }
222 else // Readed 0 bytes !
223 {
224 BYTE b;
225 if( ! p->Read(&b, 1) )
226 {
227 if( p->errcode==0 && p->bytes==0 )
228 {
229 // Good disconnect
230 TcpDeleteConnection(i--);
231 continue;
232 }
233 else
234 {
235 WriteToLogError("ERROR\tTCP error from %s: %s [%d]",

Callers 1

NetTimerTimerMethod · 0.85

Calls 15

WriteToLogErrorFunction · 0.85
TcpDeleteConnectionFunction · 0.85
WriteToLogRawMessageFunction · 0.85
ProcessMessageRulesFunction · 0.85
GetBufferSizeMethod · 0.80
FromStringSyslogdMethod · 0.80
ToStringMethod · 0.80
PollMethod · 0.45
ReadLengthMethod · 0.45
ReadMethod · 0.45
GetRemoteAddrPortMethod · 0.45
GetErrorMessageEngMethod · 0.45

Tested by

no test coverage detected