fix(libkernel): report EINVAL, EACCES, ENOBUFS, ETIMEDOUT and EINTR from Linux sockets

The Linux branch of NativeError lacked five codes the Windows branch
already translates, so they fell through to EIO. bind on a bound socket
and accept on a socket that is not listening set errno to 5 on Linux
and to 22 on Windows.

Assisted-by: Claude Opus 5.5
This commit is contained in:
Jakub Krasuski 2026-10-05 21:41:12 +02:00
parent 681f83e51e
commit cefdea7d14
2 changed files with 7 additions and 0 deletions

View File

@ -57,6 +57,7 @@ int NativeError() {
case EAGAIN: return 35;
case EADDRINUSE: return 48;
case EADDRNOTAVAIL: return 49;
case EACCES: return 13;
case EMSGSIZE: return 40;
case ENETUNREACH: return 51;
case EHOSTUNREACH: return 65;
@ -65,6 +66,10 @@ int NativeError() {
case ECONNABORTED: return 53;
case EISCONN: return 56;
case ENOTCONN: return 57;
case ENOBUFS: return 55;
case ETIMEDOUT: return 60;
case EINTR: return 4;
case EINVAL: return 22;
default: return 5;
}
#endif

View File

@ -27,6 +27,7 @@ int main() {
Require(listener >= 0);
std::array<std::uint8_t, 16> address{16, 2, 0, 0, 127, 0, 0, 1};
Require(bind_nid_postfix(listener, address.data(), address.size()) == 0);
Require(bind_nid_postfix(listener, address.data(), address.size()) == -1 && *__error_nid_postfix() == 22);
Require(listen_nid_postfix(listener, 4) == 0);
std::uint32_t address_size = address.size();
Require(getsockname_nid_postfix(listener, address.data(), &address_size) == 0);
@ -34,6 +35,7 @@ int main() {
const int client = socket_nid_postfix(2, 1, 0);
Require(client >= 0);
Require(accept_nid_postfix(client, nullptr, nullptr) == -1 && *__error_nid_postfix() == 22);
Require(connect_nid_postfix(client, address.data(), address.size()) == 0);
std::array<std::uint8_t, 16> peer{};
address_size = peer.size();