Title: [267370] trunk/Source
Revision
267370
Author
[email protected]
Date
2020-09-21 14:45:23 -0700 (Mon, 21 Sep 2020)

Log Message

[WinCairo][PlayStation] Support different instances of listener client.
https://bugs.webkit.org/show_bug.cgi?id=216733

Reviewed by Don Olmstead.

Source/_javascript_Core:

Currently RemoteInspectorSocketEndpoint support one client instance for all
listeners. This patch allows listeners to create its own listener client on
accept timing.

* inspector/remote/RemoteControllableTarget.h:
* inspector/remote/RemoteInspector.h:
* inspector/remote/socket/RemoteInspectorConnectionClient.cpp:
(Inspector::RemoteInspectorConnectionClient::didReceive):
* inspector/remote/socket/RemoteInspectorConnectionClient.h:
* inspector/remote/socket/RemoteInspectorServer.cpp:
(Inspector::RemoteInspectorServer::start):
(Inspector::RemoteInspectorServer::doAccept):
* inspector/remote/socket/RemoteInspectorServer.h:
* inspector/remote/socket/RemoteInspectorSocket.cpp:
(Inspector::RemoteInspector::didClose):
* inspector/remote/socket/RemoteInspectorSocket.h:
* inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp:
(Inspector::RemoteInspectorSocketEndpoint::RemoteInspectorSocketEndpoint):
(Inspector::RemoteInspectorSocketEndpoint::~RemoteInspectorSocketEndpoint):
(Inspector::RemoteInspectorSocketEndpoint::listenInet):
(Inspector::RemoteInspectorSocketEndpoint::workerThread):
(Inspector::RemoteInspectorSocketEndpoint::generateConnectionID):
(Inspector::RemoteInspectorSocketEndpoint::createClient):
(Inspector::RemoteInspectorSocketEndpoint::disconnect):
(Inspector::RemoteInspectorSocketEndpoint::createListener):
(Inspector::RemoteInspectorSocketEndpoint::invalidateClient):
(Inspector::RemoteInspectorSocketEndpoint::invalidateListener):
(Inspector::RemoteInspectorSocketEndpoint::getPort const):
(Inspector::RemoteInspectorSocketEndpoint::recvIfEnabled):
(Inspector::RemoteInspectorSocketEndpoint::sendIfEnabled):
(Inspector::RemoteInspectorSocketEndpoint::send):
(Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled):
* inspector/remote/socket/RemoteInspectorSocketEndpoint.h:

Source/WebKit:

Follows the change of RemoteInspectorSocketEndpoint::Client interface change.

No new tests because there's no behaivior change.

* UIProcess/Inspector/socket/RemoteInspectorClient.cpp:
(WebKit::RemoteInspectorClient::didClose):
* UIProcess/Inspector/socket/RemoteInspectorClient.h:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (267369 => 267370)


--- trunk/Source/_javascript_Core/ChangeLog	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/ChangeLog	2020-09-21 21:45:23 UTC (rev 267370)
@@ -1,3 +1,44 @@
+2020-09-21  Basuke Suzuki  <[email protected]>
+
+        [WinCairo][PlayStation] Support different instances of listener client.
+        https://bugs.webkit.org/show_bug.cgi?id=216733
+
+        Reviewed by Don Olmstead.
+
+        Currently RemoteInspectorSocketEndpoint support one client instance for all
+        listeners. This patch allows listeners to create its own listener client on
+        accept timing.
+
+        * inspector/remote/RemoteControllableTarget.h:
+        * inspector/remote/RemoteInspector.h:
+        * inspector/remote/socket/RemoteInspectorConnectionClient.cpp:
+        (Inspector::RemoteInspectorConnectionClient::didReceive):
+        * inspector/remote/socket/RemoteInspectorConnectionClient.h:
+        * inspector/remote/socket/RemoteInspectorServer.cpp:
+        (Inspector::RemoteInspectorServer::start):
+        (Inspector::RemoteInspectorServer::doAccept):
+        * inspector/remote/socket/RemoteInspectorServer.h:
+        * inspector/remote/socket/RemoteInspectorSocket.cpp:
+        (Inspector::RemoteInspector::didClose):
+        * inspector/remote/socket/RemoteInspectorSocket.h:
+        * inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp:
+        (Inspector::RemoteInspectorSocketEndpoint::RemoteInspectorSocketEndpoint):
+        (Inspector::RemoteInspectorSocketEndpoint::~RemoteInspectorSocketEndpoint):
+        (Inspector::RemoteInspectorSocketEndpoint::listenInet):
+        (Inspector::RemoteInspectorSocketEndpoint::workerThread):
+        (Inspector::RemoteInspectorSocketEndpoint::generateConnectionID):
+        (Inspector::RemoteInspectorSocketEndpoint::createClient):
+        (Inspector::RemoteInspectorSocketEndpoint::disconnect):
+        (Inspector::RemoteInspectorSocketEndpoint::createListener):
+        (Inspector::RemoteInspectorSocketEndpoint::invalidateClient):
+        (Inspector::RemoteInspectorSocketEndpoint::invalidateListener):
+        (Inspector::RemoteInspectorSocketEndpoint::getPort const):
+        (Inspector::RemoteInspectorSocketEndpoint::recvIfEnabled):
+        (Inspector::RemoteInspectorSocketEndpoint::sendIfEnabled):
+        (Inspector::RemoteInspectorSocketEndpoint::send):
+        (Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled):
+        * inspector/remote/socket/RemoteInspectorSocketEndpoint.h:
+
 2020-09-21  Keith Miller  <[email protected]>
 
         Functions should consistently enumerate length before name

Modified: trunk/Source/_javascript_Core/inspector/remote/RemoteControllableTarget.h (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/RemoteControllableTarget.h	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/RemoteControllableTarget.h	2020-09-21 21:45:23 UTC (rev 267370)
@@ -27,6 +27,7 @@
 
 #if ENABLE(REMOTE_INSPECTOR)
 
+#include "JSExportMacros.h"
 #include <wtf/TypeCasts.h>
 #include <wtf/text/WTFString.h>
 

Modified: trunk/Source/_javascript_Core/inspector/remote/RemoteInspector.h (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/RemoteInspector.h	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/RemoteInspector.h	2020-09-21 21:45:23 UTC (rev 267370)
@@ -79,7 +79,7 @@
 #endif
 {
 public:
-    class Client {
+    class JS_EXPORT_PRIVATE Client {
     public:
         struct Capabilities {
             bool remoteAutomationAllowed : 1;
@@ -224,7 +224,7 @@
 #endif
 #if USE(INSPECTOR_SOCKET_SERVER)
     HashMap<String, CallHandler>& dispatchMap() final;
-    void didClose(ConnectionID) final;
+    void didClose(RemoteInspectorSocketEndpoint&, ConnectionID) final;
 
     void sendWebInspectorEvent(const String&);
 

Modified: trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorConnectionClient.cpp (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorConnectionClient.cpp	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorConnectionClient.cpp	2020-09-21 21:45:23 UTC (rev 267370)
@@ -62,7 +62,7 @@
     endpoint.send(id, message.data(), message.size());
 }
 
-void RemoteInspectorConnectionClient::didReceive(ConnectionID clientID, Vector<uint8_t>&& data)
+void RemoteInspectorConnectionClient::didReceive(RemoteInspectorSocketEndpoint&, ConnectionID clientID, Vector<uint8_t>&& data)
 {
     ASSERT(!isMainThread());
 

Modified: trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorConnectionClient.h (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorConnectionClient.h	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorConnectionClient.h	2020-09-21 21:45:23 UTC (rev 267370)
@@ -46,7 +46,7 @@
     Optional<ConnectionID> createClient(PlatformSocketType);
     void send(ConnectionID, const uint8_t* data, size_t);
 
-    void didReceive(ConnectionID, Vector<uint8_t>&&) override;
+    void didReceive(RemoteInspectorSocketEndpoint&, ConnectionID, Vector<uint8_t>&&) override;
 
     struct Event {
         String methodName;

Modified: trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorServer.cpp (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorServer.cpp	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorServer.cpp	2020-09-21 21:45:23 UTC (rev 267370)
@@ -55,7 +55,7 @@
         return false;
 
     auto& endpoint = Inspector::RemoteInspectorSocketEndpoint::singleton();
-    m_server = endpoint.listenInet(address, port, *this, RemoteInspector::singleton());
+    m_server = endpoint.listenInet(address, port, *this);
     return isRunning();
 }
 
@@ -68,7 +68,7 @@
     return endpoint.getPort(m_server.value());
 }
 
-bool RemoteInspectorServer::didAccept(ConnectionID acceptedID, ConnectionID, Socket::Domain)
+Optional<ConnectionID> RemoteInspectorServer::doAccept(RemoteInspectorSocketEndpoint& endpoint, PlatformSocketType socket)
 {
     ASSERT(!isMainThread());
 
@@ -75,11 +75,15 @@
     auto& inspector = RemoteInspector::singleton();
     if (inspector.isConnected()) {
         LOG_ERROR("RemoteInspector can accept only 1 client");
+        return WTF::nullopt;
+    }
 
-        return false;
+    if (auto newID = endpoint.createClient(socket, inspector)) {
+        inspector.connect(newID.value());
+        return newID;
     }
-    inspector.connect(acceptedID);
-    return true;
+
+    return WTF::nullopt;
 }
 
 } // namespace Inspector

Modified: trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorServer.h (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorServer.h	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorServer.h	2020-09-21 21:45:23 UTC (rev 267370)
@@ -46,8 +46,8 @@
     friend class LazyNeverDestroyed<RemoteInspectorServer>;
     RemoteInspectorServer() { Socket::init(); }
 
-    bool didAccept(ConnectionID acceptedID, ConnectionID listenerID, Socket::Domain) final;
-    void didClose(ConnectionID) final { }
+    Optional<ConnectionID> doAccept(RemoteInspectorSocketEndpoint&, PlatformSocketType) final;
+    void didClose(RemoteInspectorSocketEndpoint&, ConnectionID) final { };
 
     Optional<ConnectionID> m_server;
 };

Modified: trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocket.cpp (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocket.cpp	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocket.cpp	2020-09-21 21:45:23 UTC (rev 267370)
@@ -63,7 +63,7 @@
     start();
 }
 
-void RemoteInspector::didClose(ConnectionID)
+void RemoteInspector::didClose(RemoteInspectorSocketEndpoint&, ConnectionID)
 {
     ASSERT(isConnected());
 

Modified: trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocket.h (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocket.h	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocket.h	2020-09-21 21:45:23 UTC (rev 267370)
@@ -27,6 +27,7 @@
 
 #if ENABLE(REMOTE_INSPECTOR)
 
+#include "JSExportMacros.h"
 #include <array>
 #include <wtf/Optional.h>
 #include <wtf/Vector.h>
@@ -64,20 +65,20 @@
 
 void init();
 
-Optional<PlatformSocketType> connect(const char* serverAddress, uint16_t serverPort);
-Optional<PlatformSocketType> listen(const char* address, uint16_t port);
-Optional<PlatformSocketType> accept(PlatformSocketType);
-Optional<std::array<PlatformSocketType, 2>> createPair();
+JS_EXPORT_PRIVATE Optional<PlatformSocketType> connect(const char* serverAddress, uint16_t serverPort);
+JS_EXPORT_PRIVATE Optional<PlatformSocketType> listen(const char* address, uint16_t port);
+JS_EXPORT_PRIVATE Optional<PlatformSocketType> accept(PlatformSocketType);
+JS_EXPORT_PRIVATE Optional<std::array<PlatformSocketType, 2>> createPair();
 
-bool setup(PlatformSocketType);
-bool isValid(PlatformSocketType);
-bool isListening(PlatformSocketType);
-Optional<uint16_t> getPort(PlatformSocketType);
+JS_EXPORT_PRIVATE bool setup(PlatformSocketType);
+JS_EXPORT_PRIVATE bool isValid(PlatformSocketType);
+JS_EXPORT_PRIVATE bool isListening(PlatformSocketType);
+JS_EXPORT_PRIVATE Optional<uint16_t> getPort(PlatformSocketType);
 
-Optional<size_t> read(PlatformSocketType, void* buffer, int bufferSize);
-Optional<size_t> write(PlatformSocketType, const void* data, int size);
+JS_EXPORT_PRIVATE Optional<size_t> read(PlatformSocketType, void* buffer, int bufferSize);
+JS_EXPORT_PRIVATE Optional<size_t> write(PlatformSocketType, const void* data, int size);
 
-void close(PlatformSocketType&);
+JS_EXPORT_PRIVATE void close(PlatformSocketType&);
 
 PollingDescriptor preparePolling(PlatformSocketType);
 bool poll(Vector<PollingDescriptor>&, int timeout);

Modified: trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp	2020-09-21 21:45:23 UTC (rev 267370)
@@ -47,6 +47,8 @@
 
 RemoteInspectorSocketEndpoint::RemoteInspectorSocketEndpoint()
 {
+    Socket::init();
+
     if (auto sockets = Socket::createPair()) {
         m_wakeupSendSocket = sockets->at(0);
         m_wakeupReceiveSocket = sockets->at(1);
@@ -67,7 +69,7 @@
 
     Socket::close(m_wakeupSendSocket);
     Socket::close(m_wakeupReceiveSocket);
-    for (const auto& connection : m_connections.values())
+    for (const auto& connection : m_clients.values())
         Socket::close(connection->socket);
     for (const auto& connection : m_listeners.values())
         Socket::close(connection->socket);
@@ -86,10 +88,10 @@
     return WTF::nullopt;
 }
 
-Optional<ConnectionID> RemoteInspectorSocketEndpoint::listenInet(const char* address, uint16_t port, Listener& listener, Client& client)
+Optional<ConnectionID> RemoteInspectorSocketEndpoint::listenInet(const char* address, uint16_t port, Listener& listener)
 {
     if (auto socket = Socket::listen(address, port))
-        return createListener(*socket, listener, client);
+        return createListener(*socket, listener);
 
     return WTF::nullopt;
 }
@@ -121,7 +123,7 @@
         Vector<ConnectionID> ids;
         {
             LockHolder lock(m_connectionsLock);
-            for (const auto& connection : m_connections) {
+            for (const auto& connection : m_clients) {
                 pollfds.append(connection.value->poll);
                 ids.append(connection.key);
             }
@@ -166,35 +168,53 @@
     ConnectionID id;
     do {
         id = cryptographicallyRandomNumber();
-    } while (!id || m_connections.contains(id) || m_listeners.contains(id));
+    } while (!id || m_clients.contains(id) || m_listeners.contains(id));
 
     return id;
 }
 
-std::unique_ptr<RemoteInspectorSocketEndpoint::Connection> RemoteInspectorSocketEndpoint::makeConnection(PlatformSocketType socket, Client& client)
+Optional<ConnectionID> RemoteInspectorSocketEndpoint::createClient(PlatformSocketType socket, Client& client)
 {
-    ASSERT(m_connectionsLock.isLocked());
+    ASSERT(Socket::isValid(socket));
 
-    Socket::setup(socket);
+    LockHolder lock(m_connectionsLock);
+    auto id = generateConnectionID();
+    auto connection = makeUnique<ClientConnection>(id, socket, client);
+    m_clients.add(id, WTFMove(connection));
+    wakeupWorkerThread();
 
-    auto connection = makeUnique<Connection>(client);
+    return id;
+}
 
-    connection->id = generateConnectionID();
-    connection->poll = Socket::preparePolling(socket);
-    connection->socket = socket;
+void RemoteInspectorSocketEndpoint::disconnect(ConnectionID id)
+{
+    LockHolder lock(m_connectionsLock);
 
-    return connection;
+    if (const auto& connection = m_listeners.get(id)) {
+        m_listeners.remove(id);
+        Socket::close(connection->socket);
+        lock.unlockEarly();
+        connection->listener.didClose(*this, id);
+    } else if (const auto& connection = m_clients.get(id)) {
+        m_clients.remove(id);
+        Socket::close(connection->socket);
+        lock.unlockEarly();
+        connection->client.didClose(*this, id);
+    } else
+        LOG_ERROR("Error: Cannot disconnect: Invalid id");
 }
 
-Optional<ConnectionID> RemoteInspectorSocketEndpoint::createClient(PlatformSocketType socket, Client& client)
+Optional<ConnectionID> RemoteInspectorSocketEndpoint::createListener(PlatformSocketType socket, Listener& listener)
 {
-    if (!Socket::isValid(socket))
+    ASSERT(Socket::isValid(socket));
+
+    if (!Socket::setup(socket))
         return WTF::nullopt;
 
     LockHolder lock(m_connectionsLock);
-    auto connection = makeConnection(socket, client);
-    auto id = connection->id;
-    m_connections.add(id, WTFMove(connection));
+    auto id = generateConnectionID();
+    auto connection = makeUnique<ListenerConnection>(id, socket, listener);
+    m_listeners.add(id, WTFMove(connection));
     wakeupWorkerThread();
 
     return id;
@@ -202,17 +222,14 @@
 
 Optional<ConnectionID> RemoteInspectorSocketEndpoint::createListener(PlatformSocketType socket, Listener& listener, Client& client)
 {
-    if (!Socket::isValid(socket))
-        return WTF::nullopt;
+    ASSERT(Socket::isValid(socket));
 
-    LockHolder lock(m_connectionsLock);
-
     if (!Socket::setup(socket))
         return WTF::nullopt;
 
-    auto connection = makeConnection(socket, client);
-    auto id = connection->id;
-    connection->listener = &listener;
+    LockHolder lock(m_connectionsLock);
+    auto id = generateConnectionID();
+    auto connection = makeUnique<ListenerConnection>(id, socket, listener);
     m_listeners.add(id, WTFMove(connection));
     wakeupWorkerThread();
 
@@ -222,7 +239,7 @@
 void RemoteInspectorSocketEndpoint::invalidateClient(Client& client)
 {
     LockHolder lock(m_connectionsLock);
-    m_connections.removeIf([&client](auto& keyValue) {
+    m_clients.removeIf([&client](auto& keyValue) {
         const auto& connection = keyValue.value;
 
         if (&connection->client != &client)
@@ -240,7 +257,7 @@
     m_listeners.removeIf([&listener](auto& keyValue) {
         const auto& connection = keyValue.value;
 
-        if (connection->listener == &listener) {
+        if (&connection->listener == &listener) {
             Socket::close(connection->socket);
             return true;
         }
@@ -254,7 +271,7 @@
     LockHolder lock(m_connectionsLock);
     if (const auto& connection = m_listeners.get(id))
         return Socket::getPort(connection->socket);
-    if (const auto& connection = m_connections.get(id))
+    if (const auto& connection = m_clients.get(id))
         return Socket::getPort(connection->socket);
 
     return WTF::nullopt;
@@ -263,21 +280,22 @@
 void RemoteInspectorSocketEndpoint::recvIfEnabled(ConnectionID id)
 {
     LockHolder lock(m_connectionsLock);
-    if (const auto& connection = m_connections.get(id)) {
+    if (const auto& connection = m_clients.get(id)) {
         Vector<uint8_t> recvBuffer(Socket::BufferSize);
         if (auto readSize = Socket::read(connection->socket, recvBuffer.data(), recvBuffer.size())) {
             if (*readSize > 0) {
                 recvBuffer.shrink(*readSize);
-                connection->client.didReceive(id, WTFMove(recvBuffer));
+                lock.unlockEarly();
+                connection->client.didReceive(*this, id, WTFMove(recvBuffer));
                 return;
             }
         }
 
         Socket::close(connection->socket);
-        m_connections.remove(id);
+        m_clients.remove(id);
 
         lock.unlockEarly();
-        connection->client.didClose(id);
+        connection->client.didClose(*this, id);
     }
 }
 
@@ -284,7 +302,7 @@
 void RemoteInspectorSocketEndpoint::sendIfEnabled(ConnectionID id)
 {
     LockHolder lock(m_connectionsLock);
-    if (const auto& connection = m_connections.get(id)) {
+    if (const auto& connection = m_clients.get(id)) {
         Socket::clearWaitingWritable(connection->poll);
 
         auto& buffer = connection->sendBuffer;
@@ -309,7 +327,7 @@
 void RemoteInspectorSocketEndpoint::send(ConnectionID id, const uint8_t* data, size_t size)
 {
     LockHolder lock(m_connectionsLock);
-    if (const auto& connection = m_connections.get(id)) {
+    if (const auto& connection = m_clients.get(id)) {
         size_t offset = 0;
         if (connection->sendBuffer.isEmpty()) {
             // Try to call send() directly if buffer is empty.
@@ -339,13 +357,8 @@
         if (auto socket = Socket::accept(connection->socket)) {
             // Need to unlock before calling createClient as it also attempts to lock.
             lock.unlockEarly();
-            if (auto newID = createClient(*socket, connection->client)) {
-                if (connection->listener->didAccept(newID.value(), connection->id, Socket::Domain::Network))
-                    return;
-
-                m_connections.remove(id);
-            }
-
+            if (connection->listener.doAccept(*this, socket.value()))
+                return;
             Socket::close(*socket);
         }
     }

Modified: trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocketEndpoint.h (267369 => 267370)


--- trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocketEndpoint.h	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/_javascript_Core/inspector/remote/socket/RemoteInspectorSocketEndpoint.h	2020-09-21 21:45:23 UTC (rev 267370)
@@ -28,7 +28,6 @@
 #if ENABLE(REMOTE_INSPECTOR)
 
 #include "RemoteInspectorSocket.h"
-
 #include <wtf/Condition.h>
 #include <wtf/Function.h>
 #include <wtf/HashMap.h>
@@ -38,19 +37,21 @@
 
 namespace Inspector {
 
-class RemoteInspectorSocketEndpoint {
+class JS_EXPORT_PRIVATE RemoteInspectorSocketEndpoint {
     WTF_MAKE_FAST_ALLOCATED;
 public:
     class Client {
     public:
-        virtual void didReceive(ConnectionID, Vector<uint8_t>&&) = 0;
-        virtual void didClose(ConnectionID) = 0;
+        virtual ~Client() { }
+        virtual void didReceive(RemoteInspectorSocketEndpoint&, ConnectionID, Vector<uint8_t>&&) = 0;
+        virtual void didClose(RemoteInspectorSocketEndpoint&, ConnectionID) = 0;
     };
 
     class Listener {
     public:
-        virtual bool didAccept(ConnectionID acceptedID, ConnectionID listenerID, Socket::Domain) = 0;
-        virtual void didClose(ConnectionID) = 0;
+        virtual ~Listener() { }
+        virtual Optional<ConnectionID> doAccept(RemoteInspectorSocketEndpoint&, PlatformSocketType) = 0;
+        virtual void didClose(RemoteInspectorSocketEndpoint&, ConnectionID) = 0;
     };
 
     static RemoteInspectorSocketEndpoint& singleton();
@@ -59,11 +60,13 @@
     ~RemoteInspectorSocketEndpoint();
 
     Optional<ConnectionID> connectInet(const char* serverAddr, uint16_t serverPort, Client&);
-    Optional<ConnectionID> listenInet(const char* address, uint16_t port, Listener&, Client&);
+    Optional<ConnectionID> listenInet(const char* address, uint16_t port, Listener&);
     void invalidateClient(Client&);
     void invalidateListener(Listener&);
 
     void send(ConnectionID, const uint8_t* data, size_t);
+    inline void send(ConnectionID id, const Vector<uint8_t>& data) { send(id, data.data(), data.size()); }
+    inline void send(ConnectionID id, const char* data, size_t length) { send(id, reinterpret_cast<const uint8_t*>(data), length); }
 
     Optional<ConnectionID> createClient(PlatformSocketType, Client&);
     Optional<ConnectionID> createListener(PlatformSocketType, Listener&, Client&);
@@ -70,24 +73,48 @@
 
     Optional<uint16_t> getPort(ConnectionID) const;
 
+    void disconnect(ConnectionID);
+
 protected:
-    struct Connection {
+    struct BaseConnection {
         WTF_MAKE_STRUCT_FAST_ALLOCATED;
-        explicit Connection(Client& client)
-            : client(client)
+
+        BaseConnection(ConnectionID id, PlatformSocketType socket)
+            : id { id }
+            , socket { socket }
+            , poll { Socket::preparePolling(socket) }
         {
+            ASSERT(Socket::isValid(socket));
         }
 
         ConnectionID id;
-        Vector<uint8_t> sendBuffer;
-        PlatformSocketType socket { INVALID_SOCKET_VALUE };
+        PlatformSocketType socket;
         PollingDescriptor poll;
+    };
+
+    struct ClientConnection : public BaseConnection {
+        ClientConnection(ConnectionID id, PlatformSocketType socket, Client& client)
+            : BaseConnection(id, socket)
+            , client { client }
+        {
+        }
+
         Client& client;
-        Listener* listener { };
+        Vector<uint8_t> sendBuffer;
     };
 
+    struct ListenerConnection : public BaseConnection {
+        ListenerConnection(ConnectionID id, PlatformSocketType socket, Listener& listener)
+            : BaseConnection(id, socket)
+            , listener { listener }
+        {
+        }
+
+        Listener& listener;
+    };
+
     ConnectionID generateConnectionID();
-    std::unique_ptr<Connection> makeConnection(PlatformSocketType, Client&);
+    Optional<ConnectionID> createListener(PlatformSocketType, Listener&);
 
     void recvIfEnabled(ConnectionID);
     void sendIfEnabled(ConnectionID);
@@ -97,8 +124,8 @@
     bool isListening(ConnectionID);
 
     mutable Lock m_connectionsLock;
-    HashMap<ConnectionID, std::unique_ptr<Connection>> m_connections;
-    HashMap<ConnectionID, std::unique_ptr<Connection>> m_listeners;
+    HashMap<ConnectionID, std::unique_ptr<ClientConnection>> m_clients;
+    HashMap<ConnectionID, std::unique_ptr<ListenerConnection>> m_listeners;
 
     PlatformSocketType m_wakeupSendSocket { INVALID_SOCKET_VALUE };
     PlatformSocketType m_wakeupReceiveSocket { INVALID_SOCKET_VALUE };

Modified: trunk/Source/WebKit/ChangeLog (267369 => 267370)


--- trunk/Source/WebKit/ChangeLog	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/WebKit/ChangeLog	2020-09-21 21:45:23 UTC (rev 267370)
@@ -1,3 +1,18 @@
+2020-09-21  Basuke Suzuki  <[email protected]>
+
+        [WinCairo][PlayStation] Support different instances of listener client.
+        https://bugs.webkit.org/show_bug.cgi?id=216733
+
+        Reviewed by Don Olmstead.
+
+        Follows the change of RemoteInspectorSocketEndpoint::Client interface change.
+
+        No new tests because there's no behaivior change.
+
+        * UIProcess/Inspector/socket/RemoteInspectorClient.cpp:
+        (WebKit::RemoteInspectorClient::didClose):
+        * UIProcess/Inspector/socket/RemoteInspectorClient.h:
+
 2020-09-21  Youenn Fablet  <[email protected]>
 
         [iOS] MediaRecorder incorrect screen orientation handling

Modified: trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorClient.cpp (267369 => 267370)


--- trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorClient.cpp	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorClient.cpp	2020-09-21 21:45:23 UTC (rev 267370)
@@ -145,7 +145,7 @@
     m_observer.targetListChanged(*this);
 }
 
-void RemoteInspectorClient::didClose(ConnectionID)
+void RemoteInspectorClient::didClose(Inspector::RemoteInspectorSocketEndpoint&, ConnectionID)
 {
     callOnMainThread([this] {
         connectionClosed();

Modified: trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorClient.h (267369 => 267370)


--- trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorClient.h	2020-09-21 21:32:21 UTC (rev 267369)
+++ trunk/Source/WebKit/UIProcess/Inspector/socket/RemoteInspectorClient.h	2020-09-21 21:45:23 UTC (rev 267370)
@@ -82,7 +82,7 @@
     void sendMessageToFrontend(const Event&);
     void setBackendCommands(const Event&);
 
-    void didClose(ConnectionID) final;
+    void didClose(Inspector::RemoteInspectorSocketEndpoint&, ConnectionID) final;
     HashMap<String, CallHandler>& dispatchMap() final;
 
     void sendWebInspectorEvent(const String&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to