To detect if a connection was closed by a client, nginx uses:
-
A EV_EOF flag as reported by kqueue. This only works if you use kqueue, i.e. on FreeBSD and friends.
-
The recv(MSG_PEEK) call to test a case when connection was closed. This works on all platforms, but only if there are no pending data.
Most notably, this doesn't cover Linux and SSL connections, which are usually closed with pending data (a shutdown alert). To improve things, the following should be implemented (in no particular order):