mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 19:59:17 +00:00
LibCore: Add Windows impl of System::socket, getaddrinfo, connect
This commit is contained in:
parent
fbf8ffe872
commit
c14e6473d6
Notes:
github-actions[bot]
2025-06-24 00:59:21 +00:00
Author: https://github.com/stasoid
Commit: c14e6473d6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5065
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/alimpfard
2 changed files with 32 additions and 1 deletions
|
@ -141,6 +141,7 @@ struct WaitPidResult {
|
|||
ErrorOr<WaitPidResult> waitpid(pid_t waitee, int options = 0);
|
||||
ErrorOr<void> fchown(int fd, uid_t, gid_t);
|
||||
ErrorOr<struct utsname> uname();
|
||||
#endif
|
||||
|
||||
class AddressInfoVector {
|
||||
AK_MAKE_NONCOPYABLE(AddressInfoVector);
|
||||
|
@ -173,7 +174,6 @@ private:
|
|||
};
|
||||
|
||||
ErrorOr<AddressInfoVector> getaddrinfo(char const* nodename, char const* servname, struct addrinfo const& hints);
|
||||
#endif
|
||||
|
||||
unsigned hardware_concurrency();
|
||||
u64 physical_memory_bytes();
|
||||
|
|
|
@ -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 {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue