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-inl.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;
~Delegate()28     virtual ~Delegate() {}
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  private:
45   static void Shutdown(ProtocolHandler*);
46   InspectorSocket() = default;
47 
48   DeleteFnPtr<ProtocolHandler, Shutdown> protocol_handler_;
49 
50   DISALLOW_COPY_AND_ASSIGN(InspectorSocket);
51 };
52 
53 
54 }  // namespace inspector
55 }  // namespace node
56 
57 #endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
58 
59 #endif  // SRC_INSPECTOR_SOCKET_H_
60