<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[244919] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/244919">244919</a></dd>
<dt>Author</dt> <dd>Basuke.Suzuki@sony.com</dd>
<dt>Date</dt> <dd>2019-05-03 14:03:34 -0700 (Fri, 03 May 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WinCairo] Implement and enable RemoteInspector Server.
https://bugs.webkit.org/show_bug.cgi?id=197432

Reviewed by Ross Kirsling.

.:

Add new build flag USE_INSPECTOR_SOCKET_SERVER to indicate using Socket implementation for RemoteInspector
protocol. Currently PlayStation is the only platform which uses this. WinCairo is the second one.

* Source/cmake/OptionsPlayStation.cmake:
* Source/cmake/OptionsWin.cmake:
* Source/cmake/OptionsWinCairo.cmake:

Source/JavaScriptCore:

Implement Windows implementation for Socket Backend of RemoteInspector and enable it on WinCairo
for experimental feature.

Also add listener interface for connection between RemoteInspector and RemoteInspectorServer
for flexible configuration.

* PlatformWin.cmake:
* inspector/remote/RemoteInspector.h:
* inspector/remote/socket/RemoteInspectorConnectionClient.h:
(Inspector::RemoteInspectorConnectionClient::didAccept):
* inspector/remote/socket/RemoteInspectorServer.cpp:
(Inspector::RemoteInspectorServer::connect):
(Inspector::RemoteInspectorServer::listenForTargets):
(Inspector::RemoteInspectorServer::didAccept):
(Inspector::RemoteInspectorServer::dispatchMap):
(Inspector::RemoteInspectorServer::start):
(Inspector::RemoteInspectorServer::addServerConnection): Deleted.
* inspector/remote/socket/RemoteInspectorServer.h:
(Inspector::RemoteInspectorServer::RemoteInspectorServer):
* inspector/remote/socket/RemoteInspectorSocket.cpp:
(Inspector::RemoteInspector::RemoteInspector):
(Inspector::RemoteInspector::dispatchMap):
(Inspector::RemoteInspector::start):
(Inspector::RemoteInspector::stopInternal):
(Inspector::RemoteInspector::setServerPort):
* inspector/remote/socket/RemoteInspectorSocket.h:
* inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp:
(Inspector::RemoteInspectorSocketEndpoint::listenInet):
(Inspector::RemoteInspectorSocketEndpoint::getPort const):
(Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled):
* inspector/remote/socket/RemoteInspectorSocketEndpoint.h:
* inspector/remote/socket/posix/RemoteInspectorSocketPOSIX.cpp:
(Inspector::Socket::init): Added.
(Inspector::Socket::listen): Signature changed.
(Inspector::Socket::getPort): Added.
* inspector/remote/socket/win/RemoteInspectorSocketWin.cpp: Added.
(Inspector::Socket::init):
(Inspector::Socket::Socket::Socket):
(Inspector::Socket::Socket::~Socket):
(Inspector::Socket::Socket::close):
(Inspector::Socket::Socket::operator PlatformSocketType const):
(Inspector::Socket::Socket::operator bool const):
(Inspector::Socket::Socket::leak):
(Inspector::Socket::Socket::create):
(Inspector::Socket::setOpt):
(Inspector::Socket::setOptEnabled):
(Inspector::Socket::enableOpt):
(Inspector::Socket::connectTo):
(Inspector::Socket::bindAndListen):
(Inspector::Socket::connect):
(Inspector::Socket::listen):
(Inspector::Socket::accept):
(Inspector::Socket::createPair):
(Inspector::Socket::setup):
(Inspector::Socket::isValid):
(Inspector::Socket::isListening):
(Inspector::Socket::getPort):
(Inspector::Socket::read):
(Inspector::Socket::write):
(Inspector::Socket::close):
(Inspector::Socket::preparePolling):
(Inspector::Socket::poll):
(Inspector::Socket::isReadable):
(Inspector::Socket::isWritable):
(Inspector::Socket::markWaitingWritable):
(Inspector::Socket::clearWaitingWritable):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkChangeLog">trunk/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCorePlatformWincmake">trunk/Source/JavaScriptCore/PlatformWin.cmake</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremoteRemoteInspectorh">trunk/Source/JavaScriptCore/inspector/remote/RemoteInspector.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorConnectionClienth">trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorConnectionClient.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorServercpp">trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorServerh">trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorSocketcpp">trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorSocketh">trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorSocketEndpointcpp">trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorSocketEndpointh">trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocketEndpoint.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketposixRemoteInspectorSocketPOSIXcpp">trunk/Source/JavaScriptCore/inspector/remote/socket/posix/RemoteInspectorSocketPOSIX.cpp</a></li>
<li><a href="#trunkSourcecmakeOptionsPlayStationcmake">trunk/Source/cmake/OptionsPlayStation.cmake</a></li>
<li><a href="#trunkSourcecmakeOptionsWincmake">trunk/Source/cmake/OptionsWin.cmake</a></li>
<li><a href="#trunkSourcecmakeOptionsWinCairocmake">trunk/Source/cmake/OptionsWinCairo.cmake</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/Source/JavaScriptCore/inspector/remote/socket/win/</li>
<li><a href="#trunkSourceJavaScriptCoreinspectorremotesocketwinRemoteInspectorSocketWincpp">trunk/Source/JavaScriptCore/inspector/remote/socket/win/RemoteInspectorSocketWin.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/ChangeLog (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/ChangeLog  2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/ChangeLog     2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2019-05-03  Basuke Suzuki  <Basuke.Suzuki@sony.com>
+
+        [WinCairo] Implement and enable RemoteInspector Server.
+        https://bugs.webkit.org/show_bug.cgi?id=197432
+
+        Reviewed by Ross Kirsling.
+
+        Add new build flag USE_INSPECTOR_SOCKET_SERVER to indicate using Socket implementation for RemoteInspector
+        protocol. Currently PlayStation is the only platform which uses this. WinCairo is the second one.
+
+        * Source/cmake/OptionsPlayStation.cmake:
+        * Source/cmake/OptionsWin.cmake:
+        * Source/cmake/OptionsWinCairo.cmake:
+
</ins><span class="cx"> 2019-05-03  Commit Queue  <commit-queue@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r244881.
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog    2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/ChangeLog       2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -1,3 +1,77 @@
</span><ins>+2019-05-03  Basuke Suzuki  <Basuke.Suzuki@sony.com>
+
+        [WinCairo] Implement and enable RemoteInspector Server.
+        https://bugs.webkit.org/show_bug.cgi?id=197432
+
+        Reviewed by Ross Kirsling.
+
+        Implement Windows implementation for Socket Backend of RemoteInspector and enable it on WinCairo
+        for experimental feature.
+
+        Also add listener interface for connection between RemoteInspector and RemoteInspectorServer
+        for flexible configuration.
+
+        * PlatformWin.cmake:
+        * inspector/remote/RemoteInspector.h:
+        * inspector/remote/socket/RemoteInspectorConnectionClient.h:
+        (Inspector::RemoteInspectorConnectionClient::didAccept):
+        * inspector/remote/socket/RemoteInspectorServer.cpp:
+        (Inspector::RemoteInspectorServer::connect):
+        (Inspector::RemoteInspectorServer::listenForTargets):
+        (Inspector::RemoteInspectorServer::didAccept):
+        (Inspector::RemoteInspectorServer::dispatchMap):
+        (Inspector::RemoteInspectorServer::start):
+        (Inspector::RemoteInspectorServer::addServerConnection): Deleted.
+        * inspector/remote/socket/RemoteInspectorServer.h:
+        (Inspector::RemoteInspectorServer::RemoteInspectorServer):
+        * inspector/remote/socket/RemoteInspectorSocket.cpp:
+        (Inspector::RemoteInspector::RemoteInspector):
+        (Inspector::RemoteInspector::dispatchMap):
+        (Inspector::RemoteInspector::start):
+        (Inspector::RemoteInspector::stopInternal):
+        (Inspector::RemoteInspector::setServerPort):
+        * inspector/remote/socket/RemoteInspectorSocket.h:
+        * inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp:
+        (Inspector::RemoteInspectorSocketEndpoint::listenInet):
+        (Inspector::RemoteInspectorSocketEndpoint::getPort const):
+        (Inspector::RemoteInspectorSocketEndpoint::acceptInetSocketIfEnabled):
+        * inspector/remote/socket/RemoteInspectorSocketEndpoint.h:
+        * inspector/remote/socket/posix/RemoteInspectorSocketPOSIX.cpp:
+        (Inspector::Socket::init): Added.
+        (Inspector::Socket::listen): Signature changed.
+        (Inspector::Socket::getPort): Added.
+        * inspector/remote/socket/win/RemoteInspectorSocketWin.cpp: Added.
+        (Inspector::Socket::init):
+        (Inspector::Socket::Socket::Socket):
+        (Inspector::Socket::Socket::~Socket):
+        (Inspector::Socket::Socket::close):
+        (Inspector::Socket::Socket::operator PlatformSocketType const):
+        (Inspector::Socket::Socket::operator bool const):
+        (Inspector::Socket::Socket::leak):
+        (Inspector::Socket::Socket::create):
+        (Inspector::Socket::setOpt):
+        (Inspector::Socket::setOptEnabled):
+        (Inspector::Socket::enableOpt):
+        (Inspector::Socket::connectTo):
+        (Inspector::Socket::bindAndListen):
+        (Inspector::Socket::connect):
+        (Inspector::Socket::listen):
+        (Inspector::Socket::accept):
+        (Inspector::Socket::createPair):
+        (Inspector::Socket::setup):
+        (Inspector::Socket::isValid):
+        (Inspector::Socket::isListening):
+        (Inspector::Socket::getPort):
+        (Inspector::Socket::read):
+        (Inspector::Socket::write):
+        (Inspector::Socket::close):
+        (Inspector::Socket::preparePolling):
+        (Inspector::Socket::poll):
+        (Inspector::Socket::isReadable):
+        (Inspector::Socket::isWritable):
+        (Inspector::Socket::markWaitingWritable):
+        (Inspector::Socket::clearWaitingWritable):
+
</ins><span class="cx"> 2019-05-03  Yusuke Suzuki  <ysuzuki@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [JSC] Generator CodeBlock generation should be idempotent
</span></span></pre></div>
<a id="trunkSourceJavaScriptCorePlatformWincmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/PlatformWin.cmake (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/PlatformWin.cmake    2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/PlatformWin.cmake       2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -32,10 +32,52 @@
</span><span class="cx">     )
</span><span class="cx"> endif ()
</span><span class="cx"> 
</span><del>-list(REMOVE_ITEM JavaScriptCore_SOURCES
-    inspector/JSGlobalObjectInspectorController.cpp
-)
</del><ins>+if (ENABLE_REMOTE_INSPECTOR)
+    list(APPEND JavaScriptCore_PRIVATE_INCLUDE_DIRECTORIES
+        "${JAVASCRIPTCORE_DIR}/inspector/remote/socket"
+    )
</ins><span class="cx"> 
</span><ins>+    list(APPEND JavaScriptCore_PRIVATE_FRAMEWORK_HEADERS
+        inspector/remote/RemoteAutomationTarget.h
+        inspector/remote/RemoteConnectionToTarget.h
+        inspector/remote/RemoteControllableTarget.h
+        inspector/remote/RemoteInspectionTarget.h
+        inspector/remote/RemoteInspector.h
+
+        inspector/remote/socket/RemoteInspectorConnectionClient.h
+        inspector/remote/socket/RemoteInspectorMessageParser.h
+        inspector/remote/socket/RemoteInspectorServer.h
+        inspector/remote/socket/RemoteInspectorSocket.h
+        inspector/remote/socket/RemoteInspectorSocketEndpoint.h
+    )
+
+    list(APPEND JavaScriptCore_SOURCES
+        API/JSRemoteInspector.cpp
+
+        inspector/remote/RemoteAutomationTarget.cpp
+        inspector/remote/RemoteConnectionToTarget.cpp
+        inspector/remote/RemoteControllableTarget.cpp
+        inspector/remote/RemoteInspectionTarget.cpp
+        inspector/remote/RemoteInspector.cpp
+
+        inspector/remote/socket/RemoteInspectorConnectionClient.cpp
+        inspector/remote/socket/RemoteInspectorMessageParser.cpp
+        inspector/remote/socket/RemoteInspectorServer.cpp
+        inspector/remote/socket/RemoteInspectorSocket.cpp
+        inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp
+
+        inspector/remote/socket/win/RemoteInspectorSocketWin.cpp
+    )
+
+    list(APPEND JavaScriptCore_LIBRARIES
+        wsock32 ws2_32
+    )
+else ()
+    list(REMOVE_ITEM JavaScriptCore_SOURCES
+        inspector/JSGlobalObjectInspectorController.cpp
+    )
+endif ()
+
</ins><span class="cx"> file(COPY
</span><span class="cx">     "${JAVASCRIPTCORE_DIR}/JavaScriptCore.vcxproj/JavaScriptCore.resources"
</span><span class="cx">     DESTINATION
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremoteRemoteInspectorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/RemoteInspector.h (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/RemoteInspector.h   2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/RemoteInspector.h      2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -53,7 +53,7 @@
</span><span class="cx"> typedef struct _GDBusInterfaceVTable GDBusInterfaceVTable;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if PLATFORM(PLAYSTATION)
</del><ins>+#if USE(INSPECTOR_SOCKET_SERVER)
</ins><span class="cx"> #include "RemoteConnectionToTarget.h"
</span><span class="cx"> #include "RemoteInspectorConnectionClient.h"
</span><span class="cx"> #include "RemoteInspectorSocketEndpoint.h"
</span><span class="lines">@@ -77,7 +77,7 @@
</span><span class="cx"> class JS_EXPORT_PRIVATE RemoteInspector final
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx">     : public RemoteInspectorXPCConnection::Client
</span><del>-#elif PLATFORM(PLAYSTATION)
</del><ins>+#elif USE(INSPECTOR_SOCKET_SERVER)
</ins><span class="cx">     : public RemoteInspectorConnectionClient
</span><span class="cx"> #endif
</span><span class="cx"> {
</span><span class="lines">@@ -146,12 +146,13 @@
</span><span class="cx"> #if USE(GLIB)
</span><span class="cx">     void requestAutomationSession(const char* sessionID, const Client::SessionCapabilities&);
</span><span class="cx"> #endif
</span><del>-#if USE(GLIB) || PLATFORM(PLAYSTATION)
</del><ins>+#if USE(GLIB) || USE(INSPECTOR_SOCKET_SERVER)
</ins><span class="cx">     void setup(TargetID);
</span><span class="cx">     void sendMessageToTarget(TargetID, const char* message);
</span><span class="cx"> #endif
</span><del>-#if PLATFORM(PLAYSTATION)
</del><ins>+#if USE(INSPECTOR_SOCKET_SERVER)
</ins><span class="cx">     static void setConnectionIdentifier(PlatformSocketType);
</span><ins>+    static void setServerPort(uint16_t);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="lines">@@ -208,7 +209,7 @@
</span><span class="cx">     void receivedAutomaticInspectionRejectMessage(NSDictionary *userInfo);
</span><span class="cx">     void receivedAutomationSessionRequestMessage(NSDictionary *userInfo);
</span><span class="cx"> #endif
</span><del>-#if PLATFORM(PLAYSTATION)
</del><ins>+#if USE(INSPECTOR_SOCKET_SERVER)
</ins><span class="cx">     HashMap<String, CallHandler>& dispatchMap() override;
</span><span class="cx">     void didClose(ConnectionID) override;
</span><span class="cx"> 
</span><span class="lines">@@ -239,9 +240,10 @@
</span><span class="cx">     GRefPtr<GCancellable> m_cancellable;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-#if PLATFORM(PLAYSTATION)
</del><ins>+#if USE(INSPECTOR_SOCKET_SERVER)
</ins><span class="cx">     std::unique_ptr<RemoteInspectorSocketEndpoint> m_socketConnection;
</span><span class="cx">     static PlatformSocketType s_connectionIdentifier;
</span><ins>+    static uint16_t s_serverPort;
</ins><span class="cx">     Optional<ConnectionID> m_clientID;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorConnectionClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorConnectionClient.h (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorConnectionClient.h    2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorConnectionClient.h       2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><span class="cx"> 
</span><ins>+#include "RemoteControllableTarget.h"
</ins><span class="cx"> #include "RemoteInspectorSocketEndpoint.h"
</span><span class="cx"> #include <wtf/WeakPtr.h>
</span><span class="cx"> #include <wtf/text/WTFString.h>
</span><span class="lines">@@ -36,7 +37,7 @@
</span><span class="cx"> class RemoteInspectorConnectionClient : public CanMakeWeakPtr<RemoteInspectorConnectionClient> {
</span><span class="cx"> public:
</span><span class="cx">     void didReceiveWebInspectorEvent(ConnectionID, Vector<uint8_t>&&);
</span><del>-    virtual void didAccept(ConnectionID, Socket::Domain) { };
</del><ins>+    virtual void didAccept(ConnectionID acceptedID, ConnectionID listenerID, Socket::Domain) { };
</ins><span class="cx">     virtual void didClose(ConnectionID) = 0;
</span><span class="cx"> 
</span><span class="cx">     struct Event {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp    2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.cpp       2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -33,30 +33,58 @@
</span><span class="cx"> 
</span><span class="cx"> namespace Inspector {
</span><span class="cx"> 
</span><del>-void RemoteInspectorServer::addServerConnection(PlatformSocketType identifier)
</del><ins>+Optional<PlatformSocketType> RemoteInspectorServer::connect()
</ins><span class="cx"> {
</span><del>-    if (!m_server)
-        return;
</del><ins>+    if (!m_server) {
+        LOG_ERROR("Inspector server is not running");
+        return WTF::nullopt;
+    }
</ins><span class="cx"> 
</span><del>-    if (auto id = m_server->createClient(identifier)) {
-        LockHolder lock(m_connectionsLock);
-        m_inspectorConnections.append(id.value());
</del><ins>+    if (auto sockets = Socket::createPair()) {
+        if (auto id = m_server->createClient(sockets->at(0))) {
+            LockHolder lock(m_connectionsLock);
+            m_inspectorConnections.append(id.value());
+
+            return sockets->at(1);
+        }
</ins><span class="cx">     }
</span><ins>+
+    return WTF::nullopt;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RemoteInspectorServer::didAccept(ConnectionID id, Socket::Domain type)
</del><ins>+Optional<uint16_t> RemoteInspectorServer::listenForTargets()
</ins><span class="cx"> {
</span><ins>+    if (!m_server) {
+        LOG_ERROR("Inspector server is not running");
+        return WTF::nullopt;
+    }
+
+    if (m_inspectorListener) {
+        LOG_ERROR("Inspector server is already listening for targets.");
+        return WTF::nullopt;
+    }
+
+    if (auto connection = m_server->listenInet("127.0.0.1", 0)) {
+        m_inspectorListener = connection;
+        return m_server->getPort(*connection);
+    }
+
+    return WTF::nullopt;
+}
+
+void RemoteInspectorServer::didAccept(ConnectionID acceptedID, ConnectionID listenerID, Socket::Domain type)
+{
</ins><span class="cx">     ASSERT(!isMainThread());
</span><span class="cx"> 
</span><del>-    if (type == Socket::Domain::Network) {
</del><ins>+    if (type == Socket::Domain::Local || (m_inspectorListener && listenerID == *m_inspectorListener)) {
+        LockHolder lock(m_connectionsLock);
+        m_inspectorConnections.append(acceptedID);
+    } else if (type == Socket::Domain::Network) {
</ins><span class="cx">         if (m_clientConnection) {
</span><span class="cx">             LOG_ERROR("Inspector server can accept only 1 client");
</span><span class="cx">             return;
</span><span class="cx">         }
</span><del>-        m_clientConnection = id;
-    } else if (type == Socket::Domain::Local) {
-        LockHolder lock(m_connectionsLock);
-        m_inspectorConnections.append(id);
</del><ins>+        m_clientConnection = acceptedID;
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -81,12 +109,12 @@
</span><span class="cx"> HashMap<String, RemoteInspectorConnectionClient::CallHandler>& RemoteInspectorServer::dispatchMap()
</span><span class="cx"> {
</span><span class="cx">     static NeverDestroyed<HashMap<String, CallHandler>> dispatchMap = HashMap<String, CallHandler>({
</span><del>-        {"SetTargetList"_s, &RemoteInspectorServer::setTargetList},
-        {"SetupInspectorClient"_s, &RemoteInspectorServer::setupInspectorClient},
-        {"Setup"_s, &RemoteInspectorServer::setup},
-        {"FrontendDidClose"_s, &RemoteInspectorServer::close},
-        {"SendMessageToFrontend"_s, &RemoteInspectorServer::sendMessageToFrontend},
-        {"SendMessageToBackend"_s, &RemoteInspectorServer::sendMessageToBackend},
</del><ins>+        { "SetTargetList"_s, reinterpret_cast<CallHandler>(&RemoteInspectorServer::setTargetList) },
+        { "SetupInspectorClient"_s, reinterpret_cast<CallHandler>(&RemoteInspectorServer::setupInspectorClient) },
+        { "Setup"_s, reinterpret_cast<CallHandler>(&RemoteInspectorServer::setup) },
+        { "FrontendDidClose"_s, reinterpret_cast<CallHandler>(&RemoteInspectorServer::close) },
+        { "SendMessageToFrontend"_s, reinterpret_cast<CallHandler>(&RemoteInspectorServer::sendMessageToFrontend) },
+        { "SendMessageToBackend"_s, reinterpret_cast<CallHandler>(&RemoteInspectorServer::sendMessageToBackend) },
</ins><span class="cx">     });
</span><span class="cx"> 
</span><span class="cx">     return dispatchMap;
</span><span class="lines">@@ -108,7 +136,7 @@
</span><span class="cx"> {
</span><span class="cx">     m_server = RemoteInspectorSocketEndpoint::create(this, "RemoteInspectorServer");
</span><span class="cx"> 
</span><del>-    if (!m_server->listenInet(port)) {
</del><ins>+    if (!m_server->listenInet(nullptr, port)) {
</ins><span class="cx">         m_server = nullptr;
</span><span class="cx">         return false;
</span><span class="cx">     }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.h (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.h      2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorServer.h 2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -43,9 +43,13 @@
</span><span class="cx">     JS_EXPORT_PRIVATE bool start(uint16_t);
</span><span class="cx">     bool isRunning() const { return !!m_server; }
</span><span class="cx"> 
</span><del>-    JS_EXPORT_PRIVATE void addServerConnection(PlatformSocketType);
</del><ins>+    JS_EXPORT_PRIVATE Optional<uint16_t> listenForTargets();
+    JS_EXPORT_PRIVATE Optional<PlatformSocketType> connect();
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    friend class NeverDestroyed<RemoteInspectorServer>;
+    RemoteInspectorServer() { Socket::init(); }
+
</ins><span class="cx">     void connectionClosed(ConnectionID);
</span><span class="cx"> 
</span><span class="cx">     void setTargetList(const Event&);
</span><span class="lines">@@ -58,7 +62,7 @@
</span><span class="cx">     void sendCloseEvent(ConnectionID, TargetID);
</span><span class="cx">     void clientConnectionClosed();
</span><span class="cx"> 
</span><del>-    void didAccept(ConnectionID, Socket::Domain) override;
</del><ins>+    void didAccept(ConnectionID acceptedID, ConnectionID listenerID, Socket::Domain) override;
</ins><span class="cx">     void didClose(ConnectionID) override;
</span><span class="cx"> 
</span><span class="cx">     void sendWebInspectorEvent(ConnectionID, const String&);
</span><span class="lines">@@ -72,6 +76,9 @@
</span><span class="cx">     Vector<ConnectionID> m_inspectorConnections;
</span><span class="cx">     Lock m_connectionsLock;
</span><span class="cx"> 
</span><ins>+    // Listener for targets.
+    Optional<ConnectionID> m_inspectorListener;
+
</ins><span class="cx">     // Connections from RemoteInspectorClient.
</span><span class="cx">     Optional<ConnectionID> m_clientConnection;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorSocketcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp    2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.cpp       2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> namespace Inspector {
</span><span class="cx"> 
</span><span class="cx"> PlatformSocketType RemoteInspector::s_connectionIdentifier = INVALID_SOCKET_VALUE;
</span><ins>+uint16_t RemoteInspector::s_serverPort = 0;
</ins><span class="cx"> 
</span><span class="cx"> RemoteInspector& RemoteInspector::singleton()
</span><span class="cx"> {
</span><span class="lines">@@ -48,7 +49,7 @@
</span><span class="cx"> 
</span><span class="cx"> RemoteInspector::RemoteInspector()
</span><span class="cx"> {
</span><del>-    start();
</del><ins>+    Socket::init();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void RemoteInspector::didClose(ConnectionID id)
</span><span class="lines">@@ -65,10 +66,10 @@
</span><span class="cx"> HashMap<String, RemoteInspector::CallHandler>& RemoteInspector::dispatchMap()
</span><span class="cx"> {
</span><span class="cx">     static NeverDestroyed<HashMap<String, CallHandler>> methods = HashMap<String, CallHandler>({
</span><del>-        {"GetTargetList"_s, static_cast<CallHandler>(&RemoteInspector::receivedGetTargetListMessage)},
-        {"Setup"_s, static_cast<CallHandler>(&RemoteInspector::receivedSetupMessage)},
-        {"SendMessageToTarget"_s, static_cast<CallHandler>(&RemoteInspector::receivedDataMessage)},
-        {"FrontendDidClose"_s, static_cast<CallHandler>(&RemoteInspector::receivedCloseMessage)},
</del><ins>+        { "GetTargetList"_s, static_cast<CallHandler>(&RemoteInspector::receivedGetTargetListMessage) },
+        { "Setup"_s, static_cast<CallHandler>(&RemoteInspector::receivedSetupMessage) },
+        { "SendMessageToTarget"_s, static_cast<CallHandler>(&RemoteInspector::receivedDataMessage) },
+        { "FrontendDidClose"_s, static_cast<CallHandler>(&RemoteInspector::receivedCloseMessage) },
</ins><span class="cx">     });
</span><span class="cx"> 
</span><span class="cx">     return methods;
</span><span class="lines">@@ -87,7 +88,7 @@
</span><span class="cx"> {
</span><span class="cx">     LockHolder lock(m_mutex);
</span><span class="cx"> 
</span><del>-    if (m_enabled || s_connectionIdentifier == INVALID_SOCKET_VALUE)
</del><ins>+    if (m_enabled || (s_connectionIdentifier == INVALID_SOCKET_VALUE && !s_serverPort))
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_enabled = true;
</span><span class="lines">@@ -94,7 +95,11 @@
</span><span class="cx"> 
</span><span class="cx">     m_socketConnection = RemoteInspectorSocketEndpoint::create(this, "RemoteInspector");
</span><span class="cx"> 
</span><del>-    m_clientID = m_socketConnection->createClient(s_connectionIdentifier);
</del><ins>+    if (s_connectionIdentifier) {
+        m_clientID = m_socketConnection->createClient(s_connectionIdentifier);
+        s_connectionIdentifier = INVALID_SOCKET_VALUE;
+    } else
+        m_clientID = m_socketConnection->connectInet("127.0.0.1", s_serverPort);
</ins><span class="cx"> 
</span><span class="cx">     if (!m_targetMap.isEmpty())
</span><span class="cx">         pushListingsSoon();
</span><span class="lines">@@ -117,7 +122,6 @@
</span><span class="cx">     m_automaticInspectionPaused = false;
</span><span class="cx">     m_socketConnection = nullptr;
</span><span class="cx">     m_clientID = WTF::nullopt;
</span><del>-    s_connectionIdentifier = INVALID_SOCKET_VALUE;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TargetListing RemoteInspector::listingForInspectionTarget(const RemoteInspectionTarget& target) const
</span><span class="lines">@@ -291,6 +295,11 @@
</span><span class="cx">     RemoteInspector::s_connectionIdentifier = connectionIdentifier;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void RemoteInspector::setServerPort(uint16_t port)
+{
+    RemoteInspector::s_serverPort = port;
+}
+
</ins><span class="cx"> } // namespace Inspector
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(REMOTE_INSPECTOR)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorSocketh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.h (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.h      2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocket.h 2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -66,8 +66,10 @@
</span><span class="cx">     Network,
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+void init();
+
</ins><span class="cx"> Optional<PlatformSocketType> connect(const char* serverAddress, uint16_t serverPort);
</span><del>-Optional<PlatformSocketType> listen(uint16_t port);
</del><ins>+Optional<PlatformSocketType> listen(const char* address, uint16_t port);
</ins><span class="cx"> Optional<PlatformSocketType> accept(PlatformSocketType);
</span><span class="cx"> Optional<std::array<PlatformSocketType, 2>> createPair();
</span><span class="cx"> 
</span><span class="lines">@@ -74,6 +76,7 @@
</span><span class="cx"> void setup(PlatformSocketType);
</span><span class="cx"> bool isValid(PlatformSocketType);
</span><span class="cx"> bool isListening(PlatformSocketType);
</span><ins>+uint16_t getPort(PlatformSocketType);
</ins><span class="cx"> 
</span><span class="cx"> Optional<size_t> read(PlatformSocketType, void* buffer, int bufferSize);
</span><span class="cx"> Optional<size_t> write(PlatformSocketType, const void* data, int size);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorSocketEndpointcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp    2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocketEndpoint.cpp       2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -76,14 +76,12 @@
</span><span class="cx">     return WTF::nullopt;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-bool RemoteInspectorSocketEndpoint::listenInet(uint16_t port)
</del><ins>+Optional<ConnectionID> RemoteInspectorSocketEndpoint::listenInet(const char* address, uint16_t port)
</ins><span class="cx"> {
</span><del>-    if (auto socket = Socket::listen(port)) {
-        if (createClient(*socket))
-            return true;
-    }
</del><ins>+    if (auto socket = Socket::listen(address, port))
+        return createClient(*socket);
</ins><span class="cx"> 
</span><del>-    return false;
</del><ins>+    return WTF::nullopt;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool RemoteInspectorSocketEndpoint::isListening(ConnectionID id)
</span><span class="lines">@@ -161,6 +159,15 @@
</span><span class="cx">     return id;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Optional<uint16_t> RemoteInspectorSocketEndpoint::getPort(ConnectionID id) const
+{
+    LockHolder lock(m_connectionsLock);
+    if (const auto& connection = m_connections.get(id))
+        return Socket::getPort(connection->socket);
+
+    return WTF::nullopt;
+}
+
</ins><span class="cx"> void RemoteInspectorSocketEndpoint::recvIfEnabled(ConnectionID id)
</span><span class="cx"> {
</span><span class="cx">     LockHolder lock(m_connectionsLock);
</span><span class="lines">@@ -246,7 +253,7 @@
</span><span class="cx">             lock.unlockEarly();
</span><span class="cx">             if (auto newID = createClient(*socket)) {
</span><span class="cx">                 if (m_inspectorClient) {
</span><del>-                    m_inspectorClient->didAccept(newID.value(), Socket::Domain::Network);
</del><ins>+                    m_inspectorClient->didAccept(newID.value(), id, Socket::Domain::Network);
</ins><span class="cx">                     return;
</span><span class="cx">                 }
</span><span class="cx">             }
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketRemoteInspectorSocketEndpointh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocketEndpoint.h (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocketEndpoint.h      2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/RemoteInspectorSocketEndpoint.h 2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -53,12 +53,14 @@
</span><span class="cx">     ~RemoteInspectorSocketEndpoint();
</span><span class="cx"> 
</span><span class="cx">     Optional<ConnectionID> connectInet(const char* serverAddr, uint16_t serverPort);
</span><del>-    bool listenInet(uint16_t port);
</del><ins>+    Optional<ConnectionID> listenInet(const char* address, uint16_t port);
</ins><span class="cx"> 
</span><span class="cx">     void send(ConnectionID, const uint8_t* data, size_t);
</span><span class="cx"> 
</span><span class="cx">     Optional<ConnectionID> createClient(PlatformSocketType fd);
</span><span class="cx"> 
</span><ins>+    Optional<uint16_t> getPort(ConnectionID) const;
+
</ins><span class="cx"> protected:
</span><span class="cx">     void recvIfEnabled(ConnectionID);
</span><span class="cx">     void sendIfEnabled(ConnectionID);
</span><span class="lines">@@ -67,7 +69,7 @@
</span><span class="cx">     void acceptInetSocketIfEnabled(ConnectionID);
</span><span class="cx">     bool isListening(ConnectionID);
</span><span class="cx"> 
</span><del>-    Lock m_connectionsLock;
</del><ins>+    mutable Lock m_connectionsLock;
</ins><span class="cx">     HashMap<ConnectionID, std::unique_ptr<Socket::Connection>> m_connections;
</span><span class="cx"> 
</span><span class="cx">     PlatformSocketType m_wakeupSendSocket { INVALID_SOCKET_VALUE };
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketposixRemoteInspectorSocketPOSIXcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/remote/socket/posix/RemoteInspectorSocketPOSIX.cpp (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/posix/RemoteInspectorSocketPOSIX.cpp 2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/posix/RemoteInspectorSocketPOSIX.cpp    2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -39,6 +39,10 @@
</span><span class="cx"> 
</span><span class="cx"> namespace Socket {
</span><span class="cx"> 
</span><ins>+void init()
+{
+}
+
</ins><span class="cx"> Optional<PlatformSocketType> connect(const char* serverAddress, uint16_t serverPort)
</span><span class="cx"> {
</span><span class="cx">     struct sockaddr_in address = { };
</span><span class="lines">@@ -63,7 +67,7 @@
</span><span class="cx">     return fd;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-Optional<PlatformSocketType> listen(uint16_t port)
</del><ins>+Optional<PlatformSocketType> listen(const char* addressStr, uint16_t port)
</ins><span class="cx"> {
</span><span class="cx">     struct sockaddr_in address = { };
</span><span class="cx"> 
</span><span class="lines">@@ -87,7 +91,10 @@
</span><span class="cx"> 
</span><span class="cx">     // FIXME: Support AF_INET6 connections.
</span><span class="cx">     address.sin_family = AF_INET;
</span><del>-    address.sin_addr.s_addr = htonl(INADDR_ANY);
</del><ins>+    if (addressStr)
+        inet_aton(addressStr, &address.sin_addr);
+    else
+        address.sin_addr.s_addr = htonl(INADDR_ANY);
</ins><span class="cx">     address.sin_port = htons(port);
</span><span class="cx">     error = ::bind(fdListen, (struct sockaddr*)&address, sizeof(address));
</span><span class="cx">     if (error < 0) {
</span><span class="lines">@@ -155,6 +162,16 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+uint16_t getPort(PlatformSocketType socket)
+{
+    ASSERT(isValid(socket));
+
+    struct sockaddr_in address = { };
+    int len = sizeof(address);
+    getsockname(socket, reinterpret_cast<struct sockaddr*>(&address), &len);
+    return address.sin_port;
+}
+
</ins><span class="cx"> Optional<size_t> read(PlatformSocketType socket, void* buffer, int bufferSize)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(isValid(socket));
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorremotesocketwinRemoteInspectorSocketWincpp"></a>
<div class="addfile"><h4>Added: trunk/Source/JavaScriptCore/inspector/remote/socket/win/RemoteInspectorSocketWin.cpp (0 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/remote/socket/win/RemoteInspectorSocketWin.cpp                             (rev 0)
+++ trunk/Source/JavaScriptCore/inspector/remote/socket/win/RemoteInspectorSocketWin.cpp        2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -0,0 +1,333 @@
</span><ins>+/*
+ * Copyright (C) 2019 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "RemoteInspectorSocket.h"
+
+#if ENABLE(REMOTE_INSPECTOR)
+
+#include <mutex>
+#include <ws2tcpip.h>
+
+namespace Inspector {
+
+namespace Socket {
+
+void init()
+{
+    static std::once_flag flag;
+    std::call_once(flag, [] {
+        WSADATA data;
+        WORD versionRequested = MAKEWORD(2, 0);
+
+        WSAStartup(versionRequested, &data);
+    });
+}
+
+class Socket {
+public:
+    Socket()
+        : m_socket(create())
+    {
+    }
+
+    explicit Socket(PlatformSocketType socket)
+        : m_socket(socket)
+    {
+    }
+
+    explicit Socket(const Socket&) = delete;
+    ~Socket()
+    {
+        close();
+    }
+
+    void close()
+    {
+        if (isValid(m_socket)) {
+            ::closesocket(m_socket);
+            m_socket = INVALID_SOCKET_VALUE;
+        }
+    }
+
+    operator PlatformSocketType() const { return m_socket; }
+    operator bool() const { return isValid(m_socket); }
+
+    PlatformSocketType leak()
+    {
+        auto socket = m_socket;
+        m_socket = INVALID_SOCKET_VALUE;
+        return socket;
+    }
+
+private:
+    static PlatformSocketType create()
+    {
+        PlatformSocketType socket = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+        if (socket == INVALID_SOCKET) {
+            LOG_ERROR("socket() failed, errno = %d", WSAGetLastError());
+            return INVALID_SOCKET_VALUE;
+        }
+        return socket;
+    }
+
+    PlatformSocketType m_socket { INVALID_SOCKET_VALUE };
+};
+
+static bool setOpt(PlatformSocketType socket, int optname, const void* optval, int optlen, const char* debug)
+{
+    int error = ::setsockopt(socket, SOL_SOCKET, optname, static_cast<const char*>(optval), optlen);
+    if (error < 0) {
+        LOG_ERROR("setsockopt() %s, errno = %d", debug, WSAGetLastError());
+        return false;
+    }
+    return true;
+}
+
+static bool setOptEnabled(PlatformSocketType socket, int optname, bool flag, const char* debug)
+{
+    const int val = flag;
+    return setOpt(socket, optname, &val, sizeof(val), debug);
+}
+
+static bool enableOpt(PlatformSocketType socket, int optname, const char* debug)
+{
+    return setOptEnabled(socket, optname, true, debug);
+}
+
+static PlatformSocketType connectTo(struct sockaddr_in& address)
+{
+    Socket socket;
+    if (!socket)
+        return INVALID_SOCKET_VALUE;
+
+    int error = ::connect(socket, (struct sockaddr*)&address, sizeof(address));
+    if (error < 0)
+        return INVALID_SOCKET_VALUE;
+
+    return socket.leak();
+}
+
+static PlatformSocketType bindAndListen(struct sockaddr_in& address)
+{
+    Socket socket;
+    if (!socket)
+        return INVALID_SOCKET_VALUE;
+
+    if (!enableOpt(socket, SO_REUSEADDR, "SO_REUSEADDR"))
+        return INVALID_SOCKET_VALUE;
+
+    // WinSock doesn't have `SO_REUSEPORT`.
+
+    int error = ::bind(socket, (struct sockaddr*)&address, sizeof(address));
+    if (error < 0) {
+        LOG_ERROR("bind() failed, errno = %d", WSAGetLastError());
+        return INVALID_SOCKET_VALUE;
+    }
+
+    error = ::listen(socket, 1);
+    if (error < 0) {
+        LOG_ERROR("listen() failed, errno = %d", WSAGetLastError());
+        return INVALID_SOCKET_VALUE;
+    }
+
+    return socket.leak();
+}
+
+Optional<PlatformSocketType> connect(const char* serverAddress, uint16_t serverPort)
+{
+    struct sockaddr_in address = { };
+
+    address.sin_family = AF_INET;
+    ::inet_pton(AF_INET, serverAddress, &address.sin_addr);
+    address.sin_port = htons(serverPort);
+
+    auto socket = connectTo(address);
+    if (!isValid(socket)) {
+        LOG_ERROR("Failed to connect to %s:%u, errno = %d", serverAddress, serverPort, WSAGetLastError());
+        return WTF::nullopt;
+    }
+
+    return socket;
+}
+
+Optional<PlatformSocketType> listen(const char* addressStr, uint16_t port)
+{
+    // FIXME: Support AF_INET6 connections.
+    struct sockaddr_in address = { };
+    address.sin_family = AF_INET;
+    if (addressStr)
+        ::inet_pton(AF_INET, addressStr, &address.sin_addr);
+    else
+        address.sin_addr.s_addr = htonl(INADDR_ANY);
+    address.sin_port = htons(port);
+
+    auto socket = bindAndListen(address);
+    if (!isValid(socket))
+        return WTF::nullopt;
+
+    return socket;
+}
+
+Optional<PlatformSocketType> accept(PlatformSocketType socket)
+{
+    struct sockaddr_in address = { };
+
+    socklen_t len = sizeof(struct sockaddr_in);
+    int fd = ::accept(socket, (struct sockaddr*) &address, &len);
+    if (fd >= 0)
+        return fd;
+
+    LOG_ERROR("accept(inet) error (errno = %d)", WSAGetLastError());
+    return WTF::nullopt;
+}
+
+Optional<std::array<PlatformSocketType, 2>> createPair()
+{
+    struct sockaddr_in address;
+    address.sin_family = AF_INET;
+    address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+    address.sin_port = 0;
+
+    Socket server(bindAndListen(address));
+    if (!server)
+        return WTF::nullopt;
+
+    address.sin_port = getPort(server);
+
+    std::array<PlatformSocketType, 2> sockets;
+    sockets[0] = connectTo(address);
+    if (!isValid(sockets[0]))
+        return WTF::nullopt;
+
+    if (auto socket = accept(server)) {
+        sockets[1] = *socket;
+        return sockets;
+    }
+
+    return WTF::nullopt;
+}
+
+void setup(PlatformSocketType socket)
+{
+    setOpt(socket, SO_RCVBUF, &BufferSize, sizeof(BufferSize), "SO_RCVBUF");
+    setOpt(socket, SO_SNDBUF, &BufferSize, sizeof(BufferSize), "SO_SNDBUF");
+}
+
+bool isValid(PlatformSocketType socket)
+{
+    return socket != INVALID_SOCKET_VALUE;
+}
+
+bool isListening(PlatformSocketType socket)
+{
+    int out;
+    socklen_t outSize = sizeof(out);
+    if (getsockopt(socket, SOL_SOCKET, SO_ACCEPTCONN, reinterpret_cast<char*>(&out), &outSize) != -1)
+        return out;
+
+    LOG_ERROR("getsockopt errno = %d", WSAGetLastError());
+    return false;
+}
+
+uint16_t getPort(PlatformSocketType socket)
+{
+    ASSERT(isValid(socket));
+
+    struct sockaddr_in address = { };
+    int len = sizeof(address);
+    getsockname(socket, reinterpret_cast<struct sockaddr*>(&address), &len);
+    return address.sin_port;
+}
+
+Optional<size_t> read(PlatformSocketType socket, void* buffer, int bufferSize)
+{
+    ASSERT(isValid(socket));
+
+    auto readSize = ::recv(socket, reinterpret_cast<char*>(buffer), bufferSize, 0);
+    if (readSize != SOCKET_ERROR)
+        return static_cast<size_t>(readSize);
+
+    LOG_ERROR("read error (errno = %d)", WSAGetLastError());
+    return WTF::nullopt;
+}
+
+Optional<size_t> write(PlatformSocketType socket, const void* data, int size)
+{
+    ASSERT(isValid(socket));
+
+    auto writeSize = ::send(socket, reinterpret_cast<const char*>(data), size, 0);
+    if (writeSize != SOCKET_ERROR)
+        return static_cast<size_t>(writeSize);
+
+    LOG_ERROR("write error (errno = %d)", WSAGetLastError());
+    return WTF::nullopt;
+}
+
+void close(PlatformSocketType& socket)
+{
+    Socket(socket).close();
+    socket = INVALID_SOCKET_VALUE;
+}
+
+PollingDescriptor preparePolling(PlatformSocketType socket)
+{
+    PollingDescriptor poll;
+    poll.fd = socket;
+    poll.events = POLLIN;
+    return poll;
+}
+
+bool poll(Vector<PollingDescriptor>& pollDescriptors, int timeout)
+{
+    int ret = ::WSAPoll(pollDescriptors.data(), pollDescriptors.size(), timeout);
+    return ret > 0;
+}
+
+bool isReadable(const PollingDescriptor& poll)
+{
+    return poll.revents & POLLIN;
+}
+
+bool isWritable(const PollingDescriptor& poll)
+{
+    return poll.revents & POLLOUT;
+}
+
+void markWaitingWritable(PollingDescriptor& poll)
+{
+    poll.events |= POLLOUT;
+}
+
+void clearWaitingWritable(PollingDescriptor& poll)
+{
+    poll.events &= ~POLLOUT;
+}
+
+} // namespace Socket
+
+} // namespace Inspector
+
+#endif // ENABLE(REMOTE_INSPECTOR)
</ins></span></pre></div>
<a id="trunkSourcecmakeOptionsPlayStationcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/cmake/OptionsPlayStation.cmake (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/cmake/OptionsPlayStation.cmake      2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/cmake/OptionsPlayStation.cmake 2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -108,6 +108,7 @@
</span><span class="cx"> SET_AND_EXPOSE_TO_BUILD(USE_FREETYPE ON)
</span><span class="cx"> SET_AND_EXPOSE_TO_BUILD(USE_HARFBUZZ ON)
</span><span class="cx"> SET_AND_EXPOSE_TO_BUILD(USE_LIBWPE ON)
</span><ins>+SET_AND_EXPOSE_TO_BUILD(USE_INSPECTOR_SOCKET_SERVER ENABLE_REMOTE_INSPECTOR)
</ins><span class="cx"> 
</span><span class="cx"> # Rendering options
</span><span class="cx"> SET_AND_EXPOSE_TO_BUILD(ENABLE_GRAPHICS_CONTEXT_3D ON)
</span></span></pre></div>
<a id="trunkSourcecmakeOptionsWincmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/cmake/OptionsWin.cmake (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/cmake/OptionsWin.cmake      2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/cmake/OptionsWin.cmake 2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -67,7 +67,6 @@
</span><span class="cx"> WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEB_AUDIO PUBLIC OFF)
</span><span class="cx"> WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_XSLT PUBLIC ON)
</span><span class="cx"> 
</span><del>-WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_REMOTE_INSPECTOR PRIVATE OFF)
</del><span class="cx"> WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SMOOTH_SCROLLING PRIVATE OFF)
</span><span class="cx"> WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_USER_MESSAGE_HANDLERS PRIVATE OFF)
</span><span class="cx"> WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_USERSELECT_ALL PRIVATE OFF)
</span><span class="lines">@@ -92,6 +91,7 @@
</span><span class="cx">     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_RESOURCE_LOAD_STATISTICS PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
</span><span class="cx">     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SERVICE_WORKER PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
</span><span class="cx">     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_VARIATION_FONTS PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
</span><ins>+    WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_REMOTE_INSPECTOR PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
</ins><span class="cx"> 
</span><span class="cx">     # FIXME: Implement plugin process on Modern WebKit. https://bugs.webkit.org/show_bug.cgi?id=185313
</span><span class="cx">     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETSCAPE_PLUGIN_API PRIVATE OFF)
</span><span class="lines">@@ -100,6 +100,7 @@
</span><span class="cx">     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_INTL PUBLIC OFF)
</span><span class="cx">     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_PUBLIC_SUFFIX_LIST PRIVATE OFF)
</span><span class="cx">     WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEBGL PUBLIC OFF)
</span><ins>+    WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_REMOTE_INSPECTOR PRIVATE OFF)
</ins><span class="cx">     WEBKIT_OPTION_DEFAULT_PORT_VALUE(USE_VERSION_STAMPER PRIVATE ON)
</span><span class="cx"> endif ()
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourcecmakeOptionsWinCairocmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/cmake/OptionsWinCairo.cmake (244918 => 244919)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/cmake/OptionsWinCairo.cmake 2019-05-03 20:36:39 UTC (rev 244918)
+++ trunk/Source/cmake/OptionsWinCairo.cmake    2019-05-03 21:03:34 UTC (rev 244919)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> SET_AND_EXPOSE_TO_BUILD(USE_TEXTURE_MAPPER ON)
</span><span class="cx"> SET_AND_EXPOSE_TO_BUILD(USE_TEXTURE_MAPPER_GL ON)
</span><span class="cx"> SET_AND_EXPOSE_TO_BUILD(USE_MEDIA_FOUNDATION ON)
</span><ins>+SET_AND_EXPOSE_TO_BUILD(USE_INSPECTOR_SOCKET_SERVER ENABLE_REMOTE_INSPECTOR)
</ins><span class="cx"> 
</span><span class="cx"> set(ENABLE_GRAPHICS_CONTEXT_3D ON)
</span><span class="cx"> set(ENABLE_WEBKIT ON)
</span></span></pre>
</div>
</div>

</body>
</html>