LibCore: Add Windows impl of System::socket, getaddrinfo, connect

This commit is contained in:
stasoid 2025-06-13 21:56:20 +05:00 committed by Andrew Kaster
commit c14e6473d6
Notes: github-actions[bot] 2025-06-24 00:59:21 +00:00
2 changed files with 32 additions and 1 deletions

View file

@ -292,4 +292,35 @@ ErrorOr<bool> isatty(int handle)
return GetFileType(to_handle(handle)) == FILE_TYPE_CHAR;
}
ErrorOr<int> socket(int domain, int type, int protocol)
{
auto socket = ::socket(domain, type, protocol);
if (socket == INVALID_SOCKET)
return Error::from_windows_error();
return socket;
}
ErrorOr<AddressInfoVector> getaddrinfo(char const* nodename, char const* servname, struct addrinfo const& hints)
{
struct addrinfo* results = nullptr;
int rc = ::getaddrinfo(nodename, servname, &hints, &results);
if (rc != 0)
return Error::from_windows_error(rc);
Vector<struct addrinfo> addresses;
for (auto* result = results; result != nullptr; result = result->ai_next)
TRY(addresses.try_append(*result));
return AddressInfoVector { move(addresses), results };
}
ErrorOr<void> connect(int socket, struct sockaddr const* address, socklen_t address_length)
{
if (::connect(socket, address, address_length) == SOCKET_ERROR)
return Error::from_windows_error();
return {};
}
}