summaryrefslogtreecommitdiff
path: root/src/inspector_socket_server.h
diff options
context:
space:
mode:
authorEugene Ostroukhov <eostroukhov@chromium.org>2017-11-10 16:01:00 -0800
committerEugene Ostroukhov <eostroukhov@google.com>2017-12-11 15:53:21 -0800
commit73ad3f9bea3993b486621aaf9e61484dc37741d4 (patch)
tree259b21142e6c4ceedde66deb1eb37a110e317d9e /src/inspector_socket_server.h
parente51fb90a6db53588ab2b884e4309d4eea9e37bbd (diff)
downloadandroid-node-v8-73ad3f9bea3993b486621aaf9e61484dc37741d4.tar.gz
android-node-v8-73ad3f9bea3993b486621aaf9e61484dc37741d4.tar.bz2
android-node-v8-73ad3f9bea3993b486621aaf9e61484dc37741d4.zip
inspector: Fix crash for WS connection
Attaching WS session will now include a roundtrip onto the main thread to make sure there is no other session (e.g. JS bindings) This change also required refactoring WS socket implementation to better support scenarios like this. Fixes: https://github.com/nodejs/node/issues/16852 PR-URL: https://github.com/nodejs/node/pull/17085 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/inspector_socket_server.h')
-rw-r--r--src/inspector_socket_server.h28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/inspector_socket_server.h b/src/inspector_socket_server.h
index 16b047da33..b193e33a46 100644
--- a/src/inspector_socket_server.h
+++ b/src/inspector_socket_server.h
@@ -22,7 +22,7 @@ class ServerSocket;
class SocketServerDelegate {
public:
- virtual bool StartSession(int session_id, const std::string& target_id) = 0;
+ virtual void StartSession(int session_id, const std::string& target_id) = 0;
virtual void EndSession(int session_id) = 0;
virtual void MessageReceived(int session_id, const std::string& message) = 0;
virtual std::vector<std::string> GetTargetIds() = 0;
@@ -34,8 +34,6 @@ class SocketServerDelegate {
// HTTP Server, writes messages requested as TransportActions, and responds
// to HTTP requests and WS upgrades.
-
-
class InspectorSocketServer {
public:
using ServerCallback = void (*)(InspectorSocketServer*);
@@ -44,6 +42,8 @@ class InspectorSocketServer {
const std::string& host,
int port,
FILE* out = stderr);
+ ~InspectorSocketServer();
+
// Start listening on host/port
bool Start();
@@ -54,6 +54,10 @@ class InspectorSocketServer {
void Send(int session_id, const std::string& message);
// kKill
void TerminateConnections();
+ // kAcceptSession
+ void AcceptSession(int session_id);
+ // kDeclineSession
+ void DeclineSession(int session_id);
int Port() const;
@@ -62,19 +66,18 @@ class InspectorSocketServer {
void ServerSocketClosed(ServerSocket* server_socket);
// Session connection lifecycle
- bool HandleGetRequest(InspectorSocket* socket, const std::string& path);
- bool SessionStarted(SocketSession* session, const std::string& id);
- void SessionTerminated(SocketSession* session);
+ void Accept(int server_port, uv_stream_t* server_socket);
+ bool HandleGetRequest(int session_id, const std::string& path);
+ void SessionStarted(int session_id, const std::string& target_id,
+ const std::string& ws_id);
+ void SessionTerminated(int session_id);
void MessageReceived(int session_id, const std::string& message) {
delegate_->MessageReceived(session_id, message);
}
-
- int GenerateSessionId() {
- return next_session_id_++;
- }
+ SocketSession* Session(int session_id);
private:
- void SendListResponse(InspectorSocket* socket);
+ void SendListResponse(InspectorSocket* socket, SocketSession* session);
bool TargetExists(const std::string& id);
enum class ServerState {kNew, kRunning, kStopping, kStopped};
@@ -85,7 +88,8 @@ class InspectorSocketServer {
std::string path_;
std::vector<ServerSocket*> server_sockets_;
Closer* closer_;
- std::map<int, SocketSession*> connected_sessions_;
+ std::map<int, std::pair<std::string, std::unique_ptr<SocketSession>>>
+ connected_sessions_;
int next_session_id_;
FILE* out_;
ServerState state_;