Project

General

Profile

Feature #11145

[PATCH] socket: avoid redundant fcntl with MSG_DONTWAIT

Added by normalperson (Eric Wong) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:69154]

Description

MSG_DONTWAIT is enough to force non-blocking I/O under Linux,
so avoid changing the state of a socket. This will allow certain
threads to do a non-destructive non-blocking "peek" while others
block (without relying on an extra ppoll syscall).

I suspect any OS with the MSG_DONTWAIT flag implements it correctly. AFAIK,
MSG_DONTWAIT is only on FreeBSD and Linux, and I've only tested on Linux.

  • ext/socket/init.c (rsock_s_recvfrom_nonblock): avoid redundant fcntl

Files

Updated by normalperson (Eric Wong) about 5 years ago

Better patch to support sending, too. I'm limiting this to Linux-only since
it seems newer FreeBSD has support for MSG_DONTWAIT, but I'm not sure it is
complete.

I'll commit in a few days

#2

Updated by Anonymous about 5 years ago

  • Status changed from Open to Closed

Applied in changeset r50666.


socket: avoid redundant fcntl on Linux

  • ext/socket/ancdata.c (bsock_sendmsg_internal, bsock_recvmsg_internal): avoid redundant fcntl on Linux [ruby-core:69154] [Feature #11145]
  • ext/socket/init.c (rsock_s_recvfrom_nonblock): ditto
  • ext/socket/rubysocket.h (MSG_DONTWAIT_RELIABLE): new macro

MSG_DONTWAIT is enough to force non-blocking I/O under Linux,
so avoid changing the state of a socket. This will allow certain
threads to do a non-destructive non-blocking "peek" while others
block (without relying on an extra ppoll syscall).

We shall be conservative about enabling this feature since some
OSes may have incomplete support for MSG_DONTWAIT. I shall
defer to a FreeBSD expert to enable that for FreeBSD.

Also available in: Atom PDF