Problems of AF_INET domain socket regarding out-of-band data.

Takashi Yano
Thu Jun 21 01:35:00 GMT 2018

Hi Corinna,

On Wed, 13 Jun 2018 22:48:58 +0900
Takashi Yano wrote:
> 1. recv() with MSG_OOB flag eats normal data if no OOB data
>   is sent yet.
> 2. Calling recv() with MSG_OOB flag is blocked if no OOB data
>   is sent yet.
> 3. Calling recv() without MSG_OOB flag after receiving OOB data
>   is blocked even if received data exist in buffer. 

I looked into these problems and found these are due to bug of

Problem 1:
If recv() is called with MSG_OOB, in fhandler_socket_inet::
recv_internal(), wsamsg->dwFlags with MSG_OOB flag set is passed
to WSARecv() and this fails because no OOB data exists. At this time,
wsamsg-> dwFlags is modified by WSARecv() so that it does not have
the MSG_OOB flag. Then, WSARecv() is called again without MSG_OOB
flag in while loop. At this time, normal data is read and returned.

Problem 2:
In fhandler_socket_inet::recv_internal(), wait_for_events() is
called. This blocks the call until OOB data arrives.

Problem 3:
If recv() is called with MSG_OOB flag set, fhandler_socket_inet::
recv_internal() calls wait_for_events() with both FD_OOB and
FD_READ. If both OOB data and normal data already arrived,
not only the event of FD_OOB but also the event of FD_READ are
reset to non signaled state. I'm not sure where the signal is
reset, though.

Moreover, return value of ioctl command SIOCATMARK of winsock
is not as expected. In winsock, SIOCATMARK returns TRUE if no
OOB data exists, FALSE otherwise. This is almost opposite to

Furthermore, inline mode (SO_OOBINLINE) of winsock is completely
broken. If SO_OOBINLINE is set, SIOATMARK always returns TRUE.
This means application cannot determine OOB data at all in inline

To solve these problems, I made a patch attached.

Could you please have a look?

Takashi Yano <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-the-handling-of-out-band-data-OOB-in-a-socket.patch
Type: application/octet-stream
Size: 13017 bytes
Desc: not available
URL: <>
-------------- next part --------------

Problem reports:
Unsubscribe info:

More information about the Cygwin mailing list