ioctlsocket with FIONREAD report 0 byte in buffer

sikai han 1 Reputation point
2021-11-30T02:13:40.067+00:00

I am writing a Delphi windows console app with three client sockets. One socket is created in its own thread, the other two are created in another thread. Both threads are running its own windows message pump. All three sockets use WSAAsyncSelect registered with events FD_READ|FD_WRITE|FD_CONNECT. Each socket will also create its own windows handle for the purpose of WSAAsyncSelect
My testing program would run like the following:
create three sockets -> send/receive data for a few minutes -> tear them down then do it all over again.
The test can only last a few hours. then it will hit the following problem:
One of the socket (either the one created in the first thread or the first one of the two created in the second thread) after socket connection and one success write, it can only receive maximum one read, then followed by two or three consecutive read event notifications within a millisecond. The ioctlsocket always report 0 bytes for read in these read notification callback. Though the Wireshark has verified the data has been successfully sent to my client with tcp ack.
Many thanks for your help.

Windows development | Windows API - Win32
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.