فهرست منبع

LibCore: Add initializer for LocalServer from already connected socket

Andrew Kaster 1 سال پیش
والد
کامیت
70149079e4
2فایلهای تغییر یافته به همراه12 افزوده شده و 0 حذف شده
  1. 11 0
      Userland/Libraries/LibCore/LocalServer.cpp
  2. 1 0
      Userland/Libraries/LibCore/LocalServer.h

+ 11 - 0
Userland/Libraries/LibCore/LocalServer.cpp

@@ -47,6 +47,17 @@ ErrorOr<void> LocalServer::take_over_from_system_server(ByteString const& socket
     return {};
     return {};
 }
 }
 
 
+ErrorOr<void> LocalServer::take_over_fd(int socket_fd)
+{
+    if (m_listening)
+        return Error::from_string_literal("Core::LocalServer: Can't perform socket takeover when already listening");
+
+    m_fd = socket_fd;
+    m_listening = true;
+    setup_notifier();
+    return {};
+}
+
 void LocalServer::setup_notifier()
 void LocalServer::setup_notifier()
 {
 {
     m_notifier = Notifier::construct(m_fd, Notifier::Type::Read, this);
     m_notifier = Notifier::construct(m_fd, Notifier::Type::Read, this);

+ 1 - 0
Userland/Libraries/LibCore/LocalServer.h

@@ -17,6 +17,7 @@ public:
     virtual ~LocalServer() override;
     virtual ~LocalServer() override;
 
 
     ErrorOr<void> take_over_from_system_server(ByteString const& path = ByteString());
     ErrorOr<void> take_over_from_system_server(ByteString const& path = ByteString());
+    ErrorOr<void> take_over_fd(int socket_fd);
     bool is_listening() const { return m_listening; }
     bool is_listening() const { return m_listening; }
     bool listen(ByteString const& address);
     bool listen(ByteString const& address);