mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibCore: Make CTCPServer's local address/port getters return Optionals
This commit is contained in:
parent
e4c80961d9
commit
43a6c70c2a
Notes:
sideshowbarker
2024-07-19 11:23:53 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/43a6c70c2a6
2 changed files with 8 additions and 8 deletions
|
@ -1,8 +1,8 @@
|
|||
#include <AK/IPv4Address.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCore/CNotifier.h>
|
||||
#include <LibCore/CTCPServer.h>
|
||||
#include <LibCore/CTCPSocket.h>
|
||||
#include <LibCore/CNotifier.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
@ -54,7 +54,7 @@ RefPtr<CTCPSocket> CTCPServer::accept()
|
|||
return CTCPSocket::construct(accepted_fd);
|
||||
}
|
||||
|
||||
IPv4Address CTCPServer::local_address() const
|
||||
Optional<IPv4Address> CTCPServer::local_address() const
|
||||
{
|
||||
if (m_fd == -1)
|
||||
return {};
|
||||
|
@ -62,20 +62,20 @@ IPv4Address CTCPServer::local_address() const
|
|||
sockaddr_in address;
|
||||
socklen_t len = sizeof(address);
|
||||
if (getsockname(m_fd, (sockaddr*)&address, &len) != 0)
|
||||
return 0;
|
||||
return {};
|
||||
|
||||
return IPv4Address(address.sin_addr.s_addr);
|
||||
}
|
||||
|
||||
u16 CTCPServer::local_port() const
|
||||
Optional<u16> CTCPServer::local_port() const
|
||||
{
|
||||
if (m_fd == -1)
|
||||
return 0;
|
||||
return {};
|
||||
|
||||
sockaddr_in address;
|
||||
socklen_t len = sizeof(address);
|
||||
if (getsockname(m_fd, (sockaddr*)&address, &len) != 0)
|
||||
return 0;
|
||||
return {};
|
||||
|
||||
return ntohs(address.sin_port);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@ public:
|
|||
|
||||
RefPtr<CTCPSocket> accept();
|
||||
|
||||
IPv4Address local_address() const;
|
||||
u16 local_port() const;
|
||||
Optional<IPv4Address> local_address() const;
|
||||
Optional<u16> local_port() const;
|
||||
|
||||
Function<void()> on_ready_to_accept;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue