Page MenuHomeFreeBSD

Restore ability to shutdown datagram sockets
ClosedPublic

Authored by sobomax on Apr 10 2017, 6:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Mar 21, 8:34 PM
Unknown Object (File)
Feb 29 2024, 8:37 PM
Unknown Object (File)
Jan 31 2024, 10:38 PM
Unknown Object (File)
Jan 13 2024, 11:41 AM
Unknown Object (File)
Jan 6 2024, 6:48 AM
Unknown Object (File)
Dec 22 2023, 10:50 PM
Unknown Object (File)
Nov 15 2023, 8:10 AM
Unknown Object (File)
Nov 1 2023, 10:47 AM

Details

Summary

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

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
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.