---------------------------------------------------------------------------
| 176 | } |
| 177 | //--------------------------------------------------------------------------- |
| 178 | void 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]", |
no test coverage detected