wahern / cqueues

Continuation Queues: Embeddable asynchronous networking, threading, and notification framework for Lua on Unix.
http://25thandclement.com/~william/projects/cqueues.html
MIT License
244 stars 37 forks source link

SO_RCVLOWAT code in lib/socket.c? #163

Open daurnimator opened 8 years ago

daurnimator commented 8 years ago

In so_peek, SO_RCVLOWAT is used when there is currently no data and the fd needs to be poll()'d.

From socket(7) man page:

The select(2) and poll(2) system calls currently do not respect the SO_RCVLOWAT setting on Linux, and mark a socket readable when even a single byte of data is available. A subsequent read from the socket will block until SO_RCVLOWAT bytes are available.

Are there platforms where this actually works?

daurnimator commented 8 years ago

This does work on BSD, but not on linux.

On linux, instead we can use edge triggering to know when more data has come in. Example: https://gist.github.com/katlogic/82fa650b8d4196c26e18ca0ebefa77d6

daurnimator commented 6 years ago

From https://lwn.net/SubscriberLink/752188/0dd72ae73f89c231/

problem appears to to have been fixed in 2008 for the 2.6.28 kernel, though, so the man page is a bit behind the times. Even so, there were still some shortcomings with SO_RCVLOWAT, including spurious wakeups, that Dumazet fixed as a part of this series.