LookupServer: Be a little more robust in case accept() fails

This commit is contained in:
Andreas Kling 2021-01-30 11:55:21 +01:00
parent 5cbc9d5724
commit 489d413fc7
Notes: sideshowbarker 2024-07-18 22:44:15 +09:00
2 changed files with 6 additions and 4 deletions

View file

@ -52,9 +52,11 @@ LookupServer::LookupServer()
m_local_server = Core::LocalServer::construct(this);
m_local_server->on_ready_to_accept = [this]() {
auto socket = m_local_server->accept();
if (!socket)
return;
socket->on_ready_to_read = [this, socket]() {
service_client(socket);
RefPtr<Core::LocalSocket> keeper = socket;
service_client(*socket);
NonnullRefPtr keeper = *socket;
const_cast<Core::LocalSocket&>(*socket).on_ready_to_read = [] {};
};
};
@ -97,7 +99,7 @@ void LookupServer::load_etc_hosts()
}
}
void LookupServer::service_client(RefPtr<Core::LocalSocket> socket)
void LookupServer::service_client(NonnullRefPtr<Core::LocalSocket> socket)
{
u8 client_buffer[1024];
int nrecv = socket->read(client_buffer, sizeof(client_buffer) - 1);

View file

@ -40,7 +40,7 @@ private:
LookupServer();
void load_etc_hosts();
void service_client(RefPtr<Core::LocalSocket>);
void service_client(NonnullRefPtr<Core::LocalSocket>);
Vector<String> lookup(const String& hostname, const String& nameserver, bool& did_get_response, unsigned short record_type, ShouldRandomizeCase = ShouldRandomizeCase::Yes);
struct CachedLookup {