diff options
author | Eugene Ostroukhov <eostroukhov@google.com> | 2018-06-01 00:24:21 +0300 |
---|---|---|
committer | Eugene Ostroukhov <eostroukhov@google.com> | 2018-06-05 19:09:06 +0300 |
commit | 327ce2dc920cad2bb51041351d6b236933ea058e (patch) | |
tree | 854b5dc7215e190a8ec733b3c36b4e35f76b9cd7 /src/inspector_socket.cc | |
parent | 0300f7c68cffa5de7f0099e3afa95093b0bbbe3c (diff) |
inspector: code cleanup
Remove some unused code from the WS server implementation and switch to
smart pointers where possible.
PR-URL: https://github.com/nodejs/node/pull/21070
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/inspector_socket.cc')
-rw-r--r-- | src/inspector_socket.cc | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/inspector_socket.cc b/src/inspector_socket.cc index 1350269cf2c..dc36359b5c9 100644 --- a/src/inspector_socket.cc +++ b/src/inspector_socket.cc @@ -22,7 +22,8 @@ namespace inspector { class TcpHolder { public: - using Pointer = std::unique_ptr<TcpHolder, void(*)(TcpHolder*)>; + static void DisconnectAndDispose(TcpHolder* holder); + using Pointer = DeleteFnPtr<TcpHolder, DisconnectAndDispose>; static Pointer Accept(uv_stream_t* server, InspectorSocket::DelegatePointer delegate); @@ -41,7 +42,6 @@ class TcpHolder { static void OnClosed(uv_handle_t* handle); static void OnDataReceivedCb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf); - static void DisconnectAndDispose(TcpHolder* holder); explicit TcpHolder(InspectorSocket::DelegatePointer delegate); ~TcpHolder() = default; void ReclaimUvBuf(const uv_buf_t* buf, ssize_t read); @@ -68,14 +68,10 @@ class ProtocolHandler { InspectorSocket* inspector() { return inspector_; } - - static void Shutdown(ProtocolHandler* handler) { - handler->Shutdown(); - } + virtual void Shutdown() = 0; protected: virtual ~ProtocolHandler() = default; - virtual void Shutdown() = 0; int WriteRaw(const std::vector<char>& buffer, uv_write_cb write_cb); InspectorSocket::Delegate* delegate(); @@ -653,10 +649,10 @@ TcpHolder::Pointer TcpHolder::Accept( err = uv_read_start(tcp, allocate_buffer, OnDataReceivedCb); } if (err == 0) { - return { result, DisconnectAndDispose }; + return TcpHolder::Pointer(result); } else { delete result; - return { nullptr, nullptr }; + return nullptr; } } @@ -721,13 +717,14 @@ void TcpHolder::ReclaimUvBuf(const uv_buf_t* buf, ssize_t read) { delete[] buf->base; } -// Public interface -InspectorSocket::InspectorSocket() - : protocol_handler_(nullptr, ProtocolHandler::Shutdown) { } - InspectorSocket::~InspectorSocket() = default; // static +void InspectorSocket::Shutdown(ProtocolHandler* handler) { + handler->Shutdown(); +} + +// static InspectorSocket::Pointer InspectorSocket::Accept(uv_stream_t* server, DelegatePointer delegate) { auto tcp = TcpHolder::Accept(server, std::move(delegate)); |