Conversation
There was a problem hiding this comment.
Shouldn't the versionadded (and similarly for fdtype) be 3.7?
|
#1349 implements a fix that does not require a new API and fixes all existing usage of socket(fileno) automatically. |
Get socket information from a file descriptor. The return value is a 3-tuple with the following structure: (family, type, proto). Not supported on all platforms.
8ed70ea to
7180891
Compare
|
Changed title, I think with the socket.socket change proposed by @tiran, we don't need fromf2(). I still think socket.fdtype() is potentially useful. As suggested by @DimitrisJim, I have fixed the version number to be 3.7. The HAVE_FDTYPE define may need some tweaking yet. Based on testing I did some months ago, platforms define SO_TYPE and SO_PROTOCOL but the fdtype() implementation doesn't work on them. Having this function in socket would allow the unit tests for #1349 to check for it and only run the tests if fdtype() is supported on the platform. |
| } | ||
|
|
||
| l = sizeof(sa); | ||
| if (getsockname(fd, &sa, &l) < 0) { |
There was a problem hiding this comment.
Your code doesn't work on Windows for IPv6 addresses. You have to make the buffer large enough to fit all possible address types in it.
sock_addr_t addrbuf;
socklen_t addrlen = sizeof(sock_addr_t);
memset(&addrbuf, 0, addrlen);
if (getsockname(fd, SAS2SA(&addrbuf), &addrlen) == 0) {
family = SAS2SA(&addrbuf)->sa_family;
} else {
return set_error();
}
|
Closing because Christian Heimes wants to fix a different way (which sounds fine to me). |
This is a recreation of pull request #1333 as there seems no way to move the source branch into my own repo. I have removed the redundant definitions as pointed out by @tiran. I could maybe be convinced that socket.socket() get this functionality as suggested.
Comment from @tiran copied here::