• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef SRC_INSPECTOR_SOCKET_H_
2 #define SRC_INSPECTOR_SOCKET_H_
3 
4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5 
6 #include "util.h"
7 #include "uv.h"
8 
9 #include <string>
10 #include <vector>
11 
12 namespace node {
13 namespace inspector {
14 
15 class ProtocolHandler;
16 
17 // HTTP Wrapper around a uv_tcp_t
18 class InspectorSocket {
19  public:
20   class Delegate {
21    public:
22     virtual void OnHttpGet(const std::string& host,
23                            const std::string& path) = 0;
24     virtual void OnSocketUpgrade(const std::string& host,
25                                  const std::string& path,
26                                  const std::string& accept_key) = 0;
27     virtual void OnWsFrame(const std::vector<char>& frame) = 0;
28     virtual ~Delegate() = default;
29   };
30 
31   using DelegatePointer = std::unique_ptr<Delegate>;
32   using Pointer = std::unique_ptr<InspectorSocket>;
33 
34   static Pointer Accept(uv_stream_t* server, DelegatePointer delegate);
35 
36   ~InspectorSocket();
37 
38   void AcceptUpgrade(const std::string& accept_key);
39   void CancelHandshake();
40   void Write(const char* data, size_t len);
41   void SwitchProtocol(ProtocolHandler* handler);
42   std::string GetHost();
43 
44   InspectorSocket(const InspectorSocket&) = delete;
45   InspectorSocket& operator=(const InspectorSocket&) = delete;
46 
47  private:
48   static void Shutdown(ProtocolHandler*);
49   InspectorSocket() = default;
50 
51   DeleteFnPtr<ProtocolHandler, Shutdown> protocol_handler_;
52 };
53 
54 
55 }  // namespace inspector
56 }  // namespace node
57 
58 #endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
59 
60 #endif  // SRC_INSPECTOR_SOCKET_H_
61