Polyfill ENOTSOCK in getsockname() and getpeername()

This commit is contained in:
Justine Tunney 2023-07-24 02:11:25 -07:00
parent eb84a25994
commit 925219bdf3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328

View file

@ -39,8 +39,11 @@ static int __getsockpeername(int fd, struct sockaddr *out_addr,
uint32_t size = sizeof(ss);
if (IsWindows()) {
if (__isfdkind(fd, kFdSocket)) {
if ((rc = impl_win32(g_fds.p[fd].handle, &ss, &size))) {
if (!__isfdopen(fd)) {
rc = ebadf();
} else if (!__isfdkind(fd, kFdSocket)) {
rc = enotsock();
} else if ((rc = impl_win32(g_fds.p[fd].handle, &ss, &size))) {
if (impl_win32 == __sys_getsockname_nt &&
WSAGetLastError() == WSAEINVAL) {
// The socket has not been bound to an address with bind, or
@ -52,9 +55,6 @@ static int __getsockpeername(int fd, struct sockaddr *out_addr,
rc = __winsockerr();
}
}
} else {
rc = ebadf();
}
} else {
rc = impl_sysv(fd, &ss, &size);
}