Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket recv call freezes thread for approx. 5 seconds

I've a client server architecture implemented in C++ with blocking sockets under Windows 7. Everything is running well up to a certain level of load. If there are a couple of clients (e.g. > 4) receiving or sending megabytes of data, sometimes the communication with one client freezes for approximately 5 seconds. All other clients are working as expected in that case.

The buffer size is 8192 bytes and logging on the server side reads as follows:

TimeStamp (s.ms) - received bytes

1299514524.618 - 8192

1299514524.618 - 8192

1299514524.618 - 0004

1299514529.641 - 8192

1299514529.641 - 3744

1299514529.641 - 1460

1299514529.641 - 1460

1299514529.641 - 8192

It seems that only 4 bytes can be read within that 5 seconds. Furthermore I found out that the freezing time is always arounds that 5 seconds - never 4 or less and never 6 or more...

Any ideas?

Best regards

Michael

like image 606
michael Avatar asked Mar 23 '11 06:03

michael


People also ask

Is recv () a blocking call?

recv(IPC, Buffer, int n) is a blocking call, that is, if data is available it writes it to the buffer and immediately returns true, and if no data is available it waits for at least n seconds to receive any data.

What does recv () return?

If successful, recv() returns the length of the message or datagram in bytes. The value 0 indicates the connection is closed.

Does recv wait?

The recv() function receives a message from a socket. The recv() call can be used on a connection mode socket or a bound, connectionless socket. If no messages are available at the socket, the recv() call waits for a message to arrive unless the socket is nonblocking.

What does RECV return when there is still data in the buffer but the other side has closed the socket?

Return value If no error occurs, recv returns the number of bytes received and the buffer pointed to by the buf parameter will contain this data received. If the connection has been gracefully closed, the return value is zero.


1 Answers

This is a Windows bug.

KB 2020447 - Socket communication using the loopback address will intermittently encounter a five second delay

A Hotfix is available in

KB 2861819 - Data transfer stops for five seconds in a Windows Socket-based application in Windows 7 and Windows Server 2008 R2

like image 73
Martin85 Avatar answered Sep 21 '22 05:09

Martin85