mirror of
https://github.com/nodejs/node.git
synced 2026-12-06 01:58:50 -05:00
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>
57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#ifndef SRC_INSPECTOR_SOCKET_H_
|
|
#define SRC_INSPECTOR_SOCKET_H_
|
|
|
|
#include "util-inl.h"
|
|
#include "uv.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace node {
|
|
namespace inspector {
|
|
|
|
class ProtocolHandler;
|
|
|
|
// HTTP Wrapper around a uv_tcp_t
|
|
class InspectorSocket {
|
|
public:
|
|
class Delegate {
|
|
public:
|
|
virtual void OnHttpGet(const std::string& host,
|
|
const std::string& path) = 0;
|
|
virtual void OnSocketUpgrade(const std::string& host,
|
|
const std::string& path,
|
|
const std::string& accept_key) = 0;
|
|
virtual void OnWsFrame(const std::vector<char>& frame) = 0;
|
|
virtual ~Delegate() {}
|
|
};
|
|
|
|
using DelegatePointer = std::unique_ptr<Delegate>;
|
|
using Pointer = std::unique_ptr<InspectorSocket>;
|
|
|
|
static Pointer Accept(uv_stream_t* server, DelegatePointer delegate);
|
|
|
|
~InspectorSocket();
|
|
|
|
void AcceptUpgrade(const std::string& accept_key);
|
|
void CancelHandshake();
|
|
void Write(const char* data, size_t len);
|
|
void SwitchProtocol(ProtocolHandler* handler);
|
|
std::string GetHost();
|
|
|
|
private:
|
|
static void Shutdown(ProtocolHandler*);
|
|
InspectorSocket() = default;
|
|
|
|
DeleteFnPtr<ProtocolHandler, Shutdown> protocol_handler_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(InspectorSocket);
|
|
};
|
|
|
|
|
|
} // namespace inspector
|
|
} // namespace node
|
|
|
|
|
|
#endif // SRC_INSPECTOR_SOCKET_H_
|