I have managed to fix the problem and my client application does not
hang/block anymore. I realised that it blocked when reading answer of
CMD1. Since the socket is specifally modified to 0_NDELAY |
O_NONBLOCKING i do not experience this blocking anymore, which does not
happen so often but ... from time to time.
CREAT SOCKET
SET SOCKET TO NON-BLOCKING <--- prevents blocking :-))
CONNECT TO PEER
WRITE CMD0 = SESSION
WRITE CMD1 = SCAN filepath-1
READ ANSWER of CMD1 <--- blocked here before
WRITE CMD2 = SCAN filepath-2
READ ANSWER of CMD2
WRITE CMD3 = SCAN filepath-3
READ ANSWER of CMD2
WRITE END
CLOSE SOCKET
here a code excerpt on how to use fcntl :
/// Sets socket to non-blocking with fcntl and must be
/// called before connecting to the peer.
void apevs::Socket::setNonBlocking()
{
// Needed to properly read from Non-blocking sockets.
mType = apevs::Socket::NON_BLOCKING;
int flags = fcntl(mFd, F_GETFL, 0);
DEBUG ("socket %d: fcntl flags 0x%x", mFd, flags);
if (flags == -1 || fcntl(mFd, F_SETFL, flags | O_NDELAY) < 0) {
flags = fcntl(mFd, F_GETFL, 0);
WARNING ("socket %d: failed to set fcntl flags 0x%x",
mFd, flags);
}
flags = fcntl(mFd, F_GETFL, 0);
DEBUG ("socket %d: fcntl flags 0x%x", mFd, flags);
}
_______________________________________________
http://lists.clamav.net/cgi-bin/mailman/listinfo/clamav-devel