diff options
author | Sam Roberts <vieuxtech@gmail.com> | 2017-05-31 02:34:59 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2017-06-02 01:54:34 +0300 |
commit | 26ab769940e59646386bd15bbafb9378b8b56aed (patch) | |
tree | b2f6ff05c598326b065bc46cea59d71aca21dcd9 /src/inspector_socket_server.cc | |
parent | ce5745bf92f586c58366e9f738441d69118f2c18 (diff) |
inspector: refactor to rename and comment methods
Pure refactor, makes no functional changes but the renaming helped me
see more clearly what the relationship was between methods and
variables.
* Renamed methods to reduce number of slightly different names for the
same thing ("thread" vs "io thread", etc.).
* Added comments where it was useful to me.
PR-URL: https://github.com/nodejs/node/pull/13321
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/inspector_socket_server.cc')
-rw-r--r-- | src/inspector_socket_server.cc | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/inspector_socket_server.cc b/src/inspector_socket_server.cc index 1e1d0ff5676..f3e56b6ceb5 100644 --- a/src/inspector_socket_server.cc +++ b/src/inspector_socket_server.cc @@ -230,9 +230,9 @@ class SocketSession { private: enum class State { kHttp, kWebSocket, kClosing, kEOF, kDeclined }; - static void CloseCallback_(InspectorSocket* socket, int code); - static void ReadCallback_(uv_stream_t* stream, ssize_t read, - const uv_buf_t* buf); + static void CloseCallback(InspectorSocket* socket, int code); + static void ReadCallback(uv_stream_t* stream, ssize_t read, + const uv_buf_t* buf); void OnRemoteDataIO(ssize_t read, const uv_buf_t* buf); const int id_; InspectorSocket socket_; @@ -242,9 +242,10 @@ class SocketSession { }; InspectorSocketServer::InspectorSocketServer(SocketServerDelegate* delegate, + uv_loop_t* loop, const std::string& host, int port, - FILE* out) : loop_(nullptr), + FILE* out) : loop_(loop), delegate_(delegate), host_(host), port_(port), @@ -255,7 +256,6 @@ InspectorSocketServer::InspectorSocketServer(SocketServerDelegate* delegate, state_ = ServerState::kNew; } - // static bool InspectorSocketServer::HandshakeCallback(InspectorSocket* socket, inspector_handshake_event event, @@ -361,7 +361,7 @@ void InspectorSocketServer::SendListResponse(InspectorSocket* socket) { } if (!connected) { std::string host; - GetSocketHost(&socket->client, &host); + GetSocketHost(&socket->tcp, &host); std::string address = GetWsUrl(host, port_, id); std::ostringstream frontend_url; frontend_url << "chrome-devtools://devtools/bundled"; @@ -374,9 +374,8 @@ void InspectorSocketServer::SendListResponse(InspectorSocket* socket) { SendHttpResponse(socket, MapsToString(response)); } -bool InspectorSocketServer::Start(uv_loop_t* loop) { +bool InspectorSocketServer::Start() { CHECK_EQ(state_, ServerState::kNew); - loop_ = loop; sockaddr_in addr; uv_tcp_init(loop_, &server_); uv_ip4_addr(host_.c_str(), port_, &addr); @@ -470,11 +469,11 @@ SocketSession::SocketSession(InspectorSocketServer* server, int id) void SocketSession::Close() { CHECK_NE(state_, State::kClosing); state_ = State::kClosing; - inspector_close(&socket_, CloseCallback_); + inspector_close(&socket_, CloseCallback); } // static -void SocketSession::CloseCallback_(InspectorSocket* socket, int code) { +void SocketSession::CloseCallback(InspectorSocket* socket, int code) { SocketSession* session = SocketSession::From(socket); CHECK_EQ(State::kClosing, session->state_); session->server_->SessionTerminated(session); @@ -483,12 +482,12 @@ void SocketSession::CloseCallback_(InspectorSocket* socket, int code) { void SocketSession::FrontendConnected() { CHECK_EQ(State::kHttp, state_); state_ = State::kWebSocket; - inspector_read_start(&socket_, OnBufferAlloc, ReadCallback_); + inspector_read_start(&socket_, OnBufferAlloc, ReadCallback); } // static -void SocketSession::ReadCallback_(uv_stream_t* stream, ssize_t read, - const uv_buf_t* buf) { +void SocketSession::ReadCallback(uv_stream_t* stream, ssize_t read, + const uv_buf_t* buf) { InspectorSocket* socket = inspector_from_stream(stream); SocketSession::From(socket)->OnRemoteDataIO(read, buf); } |