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

Function UdpReceiveMessage

source/udpcon.cpp:73–116  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

71}
72//---------------------------------------------------------------------------
73void UdpReceiveMessage(void)
74{
75 if( ! udp )
76 return;
77 if( ! udp->IsOpen() )
78 return;
79
80 struct sockaddr_in a;
81 DWORD rl;
82 while( (rl = udp->ReadLength()) > 0 )
83 {
84 BYTE * ReceiveBuffer = new BYTE[rl + 1];
85 if( ! udp->ReadFrom(ReceiveBuffer, rl, (struct sockaddr *)&a) )
86 {
87 if( udp->GetWSAError() == MYERROR_READCOUNT )
88 ; // Good error :) In the receive buffer still have UDP packets
89 else
90 {
91 WriteToLogError(String("ERROR\tudp: ") + udp->GetErrorMessageEng());
92 }
93 }
94
95 if( udp->bytes > 0 )
96 {
97 // NULL terminate syslog message
98 ReceiveBuffer[udp->bytes] = 0;
99
100 WriteToLogRawMessage((char *)ReceiveBuffer);
101
102 TSyslogMessage sm;
103 sm.FromStringSyslogd((char *)ReceiveBuffer, udp->bytes, &a);
104
105 if( ProcessMessageRules(&sm) )
106 {
107 // option is not set: "Ignore (do not save to the default file "syslog")"
108 TStorageFile * sf = fdb->Get(0);
109 if( sf )
110 if( ! sf->Save( sm.ToString() ) )
111 WriteToLogError("ERROR\tSave message to file: %s", sf->GetFileName().c_str());
112 }
113 }
114 delete [] ReceiveBuffer;
115 }
116}
117//---------------------------------------------------------------------------
118#pragma package(smart_init)

Callers 1

NetTimerTimerMethod · 0.85

Calls 13

WriteToLogErrorFunction · 0.85
WriteToLogRawMessageFunction · 0.85
ProcessMessageRulesFunction · 0.85
ReadFromMethod · 0.80
GetWSAErrorMethod · 0.80
FromStringSyslogdMethod · 0.80
ToStringMethod · 0.80
IsOpenMethod · 0.45
ReadLengthMethod · 0.45
GetErrorMessageEngMethod · 0.45
GetMethod · 0.45
SaveMethod · 0.45

Tested by

no test coverage detected