diff options
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r-- | Libraries/LibCore/EventLoop.cpp | 32 | ||||
-rw-r--r-- | Libraries/LibCore/EventLoop.h | 1 | ||||
-rw-r--r-- | Libraries/LibCore/LocalServer.cpp | 4 |
3 files changed, 22 insertions, 15 deletions
diff --git a/Libraries/LibCore/EventLoop.cpp b/Libraries/LibCore/EventLoop.cpp index 0c1e48073e..fdd82b8064 100644 --- a/Libraries/LibCore/EventLoop.cpp +++ b/Libraries/LibCore/EventLoop.cpp @@ -233,20 +233,10 @@ EventLoop::EventLoop() ASSERT(rc == 0); s_event_loop_stack->append(this); - auto rpc_path = String::format("/tmp/rpc.%d", getpid()); - rc = unlink(rpc_path.characters()); - if (rc < 0 && errno != ENOENT) { - perror("unlink"); - ASSERT_NOT_REACHED(); + if (!s_rpc_server) { + if (!start_rpc_server()) + dbg() << "Core::EventLoop: Failed to start an RPC server"; } - s_rpc_server = LocalServer::construct(); - s_rpc_server->set_name("Core::EventLoop_RPC_server"); - bool listening = s_rpc_server->listen(rpc_path); - ASSERT(listening); - - s_rpc_server->on_ready_to_accept = [&] { - RPCClient::construct(s_rpc_server->accept()); - }; } #ifdef CEVENTLOOP_DEBUG @@ -258,6 +248,22 @@ EventLoop::~EventLoop() { } +bool EventLoop::start_rpc_server() +{ + auto rpc_path = String::format("/tmp/rpc.%d", getpid()); + int rc = unlink(rpc_path.characters()); + if (rc < 0 && errno != ENOENT) { + perror("unlink"); + return false; + } + s_rpc_server = LocalServer::construct(); + s_rpc_server->set_name("Core::EventLoop_RPC_server"); + s_rpc_server->on_ready_to_accept = [&] { + RPCClient::construct(s_rpc_server->accept()); + }; + return s_rpc_server->listen(rpc_path); +} + EventLoop& EventLoop::main() { ASSERT(s_main_event_loop); diff --git a/Libraries/LibCore/EventLoop.h b/Libraries/LibCore/EventLoop.h index b122bdf860..eaa8d018e3 100644 --- a/Libraries/LibCore/EventLoop.h +++ b/Libraries/LibCore/EventLoop.h @@ -76,6 +76,7 @@ public: static void wake(); private: + bool start_rpc_server(); void wait_for_event(WaitMode); Optional<struct timeval> get_next_timer_expiration(); diff --git a/Libraries/LibCore/LocalServer.cpp b/Libraries/LibCore/LocalServer.cpp index bdff0a39ab..bd1c1e1a2e 100644 --- a/Libraries/LibCore/LocalServer.cpp +++ b/Libraries/LibCore/LocalServer.cpp @@ -123,13 +123,13 @@ bool LocalServer::listen(const String& address) rc = ::bind(m_fd, (const sockaddr*)&un, sizeof(un)); if (rc < 0) { perror("bind"); - ASSERT_NOT_REACHED(); + return false; } rc = ::listen(m_fd, 5); if (rc < 0) { perror("listen"); - ASSERT_NOT_REACHED(); + return false; } m_listening = true; |