diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-04 13:07:41 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-04 13:07:41 +0100 |
commit | 43a6c70c2a6d9d1453ebd63c898f3a26128f6a93 (patch) | |
tree | 3775e54fd588d100e48f1378c61ad8dbb9fa1b69 /Libraries | |
parent | e4c80961d961d0cb02c991fa6da521057cfb3371 (diff) | |
download | serenity-43a6c70c2a6d9d1453ebd63c898f3a26128f6a93.zip |
LibCore: Make CTCPServer's local address/port getters return Optionals
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibCore/CTCPServer.cpp | 12 | ||||
-rw-r--r-- | Libraries/LibCore/CTCPServer.h | 4 |
2 files changed, 8 insertions, 8 deletions
diff --git a/Libraries/LibCore/CTCPServer.cpp b/Libraries/LibCore/CTCPServer.cpp index 190eacf6bd..3b5420bc5d 100644 --- a/Libraries/LibCore/CTCPServer.cpp +++ b/Libraries/LibCore/CTCPServer.cpp @@ -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); } diff --git a/Libraries/LibCore/CTCPServer.h b/Libraries/LibCore/CTCPServer.h index dcf6c54363..0539b3734f 100644 --- a/Libraries/LibCore/CTCPServer.h +++ b/Libraries/LibCore/CTCPServer.h @@ -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; |