Page MenuHomeFreeBSD

Restore ability to shutdown datagram sockets

Authored by sobomax on Apr 10 2017, 6:01 PM.



Historically, the FreeBSD shutdown(2) system call did not make distinction between datagram and stream sockets. This allowed one thread (or process) to interrupt other thread (or process) blocked in recvXXX(2) by calling shutdown() on that socket. The revision D3039 (subsequently checked into svn rev 285910) has removed this behavior. Unfortunately POSIX provides no other clean way to do that and there are quite lot of software that depends on the old behavior. In addition, analysis done in the D3039 used as a basis for making this change is not entirely correct, for example fairly recent Linux kernel (4.4.0 as of time of this writing) actually tears socket down even for datagram socket and causes any current or future blocking reads on that socket to fail with 0-lengh result.

Attached patch makes FreeBSD behavior match our historical behavior and that of our Linux 4.4.0, i.e. return ENOTCONN but still "disconnect" socket and fail any current or future readers.

Test Plan

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

sobomax edited the summary of this revision. (Show Details)

Looks good to me. Still, could you add a comment to the code explaining the situation?

This revision is now accepted and ready to land.Apr 10 2017, 8:45 PM

I'm not sure I approve of calling a local variable 'fakeerror'. Given that the only value it can take on is ENOTCONN, how about making it a boolean 'soerror_enotconn'?

sobomax edited edge metadata.

Rework previous change to restore ability to shutdown datagram
sockets to be easier to understand and put a comment explaining
what's going on and why.

Suggested by: rwatson, ed

This revision now requires review to proceed.Apr 13 2017, 4:39 PM

Collapse if/return/else/return into a single return statement.

hiren added a subscriber: hiren.

Other than it not being able to build, I like the var name change requested by Robert and the general approach.

This revision is now accepted and ready to land.Apr 13 2017, 4:58 PM
This revision was automatically updated to reflect the committed changes.