GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-12887 and bpo-14345: Document the availability and uses of the SO_ constants. Document SOL_SOCKET by ammaraskar · Pull Request #3072 · python/cpython Conversation
|
|
|
||
| When a socket is set to linger. A call to :meth:`socket.close` or | ||
| :meth:`socket.shutdown` will not return until all queued messages | ||
| for the socket have been successfully sent or the linger timeout |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
First sentence does not make sense. Perhaps you should have a comma (,) instead of the full stop (.)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| .. data:: SO_DONTROUTE | ||
|
|
||
| Indicates that packets sent through this socket should be routed | ||
| through the interface its bound to. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It’s or it is
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| SO_RCVLOWAT sets the minimum number of bytes that must be present in | ||
| the socket's internal receive buffer before they are passed on to able | ||
| read call. SO_SNDLOWAT similiary sets the minimum bytes before data is |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I don’t understand “passed on to able read call”. Perhaps do you mean something like “before the socket becomes readable” or “before they are returned by a read”?
Spelling: similarly
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| SO_SNDLOWAT is read-only on Linux and SO_RCVLOWAT is read-only on | ||
| Linux versions below 2.4. | ||
|
|
||
| Both these values default to 1. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
According to Posix, the SNDLOWAT default depends on the implementation and protocol.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| SO_SNDTIMEO | ||
|
|
||
| Specifies the amount of time send and receive calls for this socket willl | ||
| block before timing out. The default timeout of zero means that operations |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Extra l in will.
Is it worth clarifying that these timeouts (which raise EAGAIN etc) are independent of the settimeout mechanism (which raises socket.timeout for non-zero timeouts)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| When bound, only packets received from that particular device are | ||
| processsed by the socket. | ||
|
|
||
| .. versionadded:: 3.1 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Extra s in processed.
According to my patch at https://bugs.python.org/issue27409 this was only added in 3.3 (or did I make a mistake?). See also https://hg.python.org/cpython/rev/6159311f0f44.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Oh I came to the 3.1 number by going to https://github.com/python/cpython/blob/master/Modules/socketmodule.c
Clicking the blame button and checking the tag in the commit. The tag says 3.1 but it looks like that is incorrect, since the README at the time says: This is Python version 3.3 alpha 0
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| Passing ``SO_DOMAIN`` to :meth:`socket.getsockopt` allows for the retrival | ||
| of the ``family`` value as defined in the :func:`socket.socket` function. | ||
| ``SO_PROTOCOL`` returns the ``proto`` value. Both these options are read only. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actually it can return the real protocol, e.g. IPPROTO_TCP, even when proto is zero.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ``SO_PROTOCOL`` returns the ``proto`` value. Both these options are read only. | ||
|
|
||
| The value returned for the ``family`` is an integer and not one of the | ||
| friendly constants above like :const:`AF_INET`. In order to get a constant |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The integer value normally does equal one of those enumeration members; it is just that the integer object is never an enumeration member.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| SO_PEERCRED | ||
|
|
||
| Allows for the passing of SCM credentials over unix sockets. | ||
| See the end of :func:`socket.recvmsg` for details. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I’m not familiar with either API, but it seems this only applies to PASSCRED, and PEERCRED returns credentials straight away.
There seems to be something missing with the reference to recvmsg. The end of that entry covers Python versions, platforms, and before that, receiving file descriptors with SCM_RIGHTS. But as I understand it, when using PASSCRED you would look for SCM_CREDENTIALS messages, with a different data structure. The first couple of paragraphs, about receiving anciliary messages in general, are more relevant.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yeah I'm not familiar with this API either, I'm just going to add an easily searchable keyword of ancillary message and point to recvmsg
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| .. versionadded:: 3.6 | ||
|
|
||
| .. Availability: Linux >= 2.6.13 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Where does this come from? What I found was SO_PASSSEC added to Linux 2.6.18 (https://repo.or.cz/linux-2.6-linus.git/commitdiff/877ce7c), and SO_PEERSEC to 2.6.2 (schwabe/tglx-history@da6e57a).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Aah that's my mistake. I think 2.6.2 is the right number to include here. I came up with 2.6.13 because I was looking at the blame for sock.c here: https://github.com/torvalds/linux/blame/add459aa1afe05472abc96f6a29aefd0c84e73d6/net/core/sock.c
I scrolled to
case SO_PEERSEC: return security_socket_getpeersec_stream(sock, optval, optlen, len);
and saw "Linux-2.6.12-rc2" in the commit message. But it looks like that was a big commit for when Linux switched from bitkeeper to git.
But if we look at the commit that adds
case SO_PASSSEC: v.val = test_bit(SOCK_PASSSEC, &sock->flags) ? 1 : 0; break;
the commit message says "[AF_UNIX]: Datagram getpeersec" and we can find the same commit in the 2.6.2 changelogs here: https://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.2
So I think its safe to say both of these options are available on >= 2.6.2
Sorry, something went wrong.
There was an error while loading. Please reload this page.
90ef897 to
86cece8
Compare
There was an error while loading. Please reload this page.
|
Hi @ammaraskar! I appreciate the level of work you've put into this. On the other hand, I wonder about the maintenance cost of updating this each time an OS gains support for one those options. My personal take would be that people who use the (rather low-level) Not sure what others think about this. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I think this will be far and in between, the core socket options are usually a fairly stable OS level API. With the current ones documented, it should hopefully encourage maintainers to document newly added ones and then check their availability accordingly. As far as an OS gaining support, I think that will be fairly rare but in that case having the documentation being slightly outdated wouldn't be the worst of situations. There is some older discussion about this on the bpo thread.
I agree, however there is no real documentation on what constants python exposes from the underlying socket library. At the very minimum I think documenting the list of options and brief descriptions of them would be a good idea. Short of doing |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hi, @pitrou you are right about the list of the options, we have to check in the official documentation (man pages or MSDN site) but this table with some references can be useful for the beginners, and also for the maintainer, because we can check if an option is directly supported by Python or not. @ammaraskar |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
At the very least, I think adding documentation for the list of options that socketmodule exports and getsockopt/setsockopt would be useful. I agree that the compatibility table is a bit of a pain to maintain. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ammaraskar How did you find the entries for your table. I propose another solution, for the most used entries, we could keep them in the tables. Add a small paragraph with the link to the official documentation of macOS, Windows and for the man pages for POSIX systems. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I pretty much just went down the list here: cpython/Modules/socketmodule.c Line 7217 in e359bc2
Then I looked them up in the man page here for Linux: http://man7.org/linux/man-pages/man7/socket.7.html FreeBSD here: https://www.freebsd.org/cgi/man.cgi?query=setsockopt&sektion=2&apropos=0&manpath=FreeBSD+7.0-RELEASE and finally Windows here: https://docs.microsoft.com/en-us/windows/desktop/WinSock/sol-socket-socket-options The availabilities took a bit more digging up but that was the basic idea. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I removed the " needs backport to 3.6" label, the 3.6 branch no longer accept bugfixes (only security fixes are accepted): https://devguide.python.org/#status-of-python-branches |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I agree. In one hand I like the table (not having to search the info for an OS you don't know is nice), but it's probably too much work to maintain. Let's just start by documenting the exposed options. @ammaraskar can you remove the compatibility list and fix the previous reviews about? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@ammaraskar, please address the review comments. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing as it's been more than two years since changes were requested. Feel free to reopen or submit a new PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.