Node.js  v8.x
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine
inspector_socket.h
Go to the documentation of this file.
1 #ifndef SRC_INSPECTOR_SOCKET_H_
2 #define SRC_INSPECTOR_SOCKET_H_
3 
4 #include "http_parser.h"
5 #include "util.h"
6 #include "util-inl.h"
7 #include "uv.h"
8 
9 #include <string>
10 #include <vector>
11 
12 namespace node {
13 namespace inspector {
14 
20 };
21 
22 class InspectorSocket;
23 
24 typedef void (*inspector_cb)(InspectorSocket*, int);
25 // Notifies as handshake is progressing. Returning false as a response to
26 // kInspectorHandshakeUpgrading or kInspectorHandshakeHttpGet event will abort
27 // the connection. inspector_write can be used from the callback.
28 typedef bool (*handshake_cb)(InspectorSocket*,
29  enum inspector_handshake_event state,
30  const std::string& path);
31 
33  http_parser parser;
34  http_parser_settings parser_settings;
36  bool done;
38  std::string ws_key;
39  std::string path;
40  std::string current_header;
41 };
42 
43 struct ws_state_s {
44  uv_alloc_cb alloc_cb;
45  uv_read_cb read_cb;
47  bool close_sent;
49 };
50 
51 // HTTP Wrapper around a uv_tcp_t
52 class InspectorSocket {
53  public:
54  InspectorSocket() : data(nullptr), http_parsing_state(nullptr),
55  ws_state(nullptr), buffer(0), ws_mode(false),
56  shutting_down(false), connection_eof(false) { }
57  void reinit();
58  void* data;
61  std::vector<char> buffer;
62  uv_tcp_t tcp;
63  bool ws_mode;
66 
67  private:
68  DISALLOW_COPY_AND_ASSIGN(InspectorSocket);
69 };
70 
71 int inspector_accept(uv_stream_t* server, InspectorSocket* inspector,
73 
74 void inspector_close(InspectorSocket* inspector,
76 
77 // Callbacks will receive stream handles. Use inspector_from_stream to get
78 // InspectorSocket* from the stream handle.
79 int inspector_read_start(InspectorSocket* inspector, uv_alloc_cb,
80  uv_read_cb);
81 void inspector_read_stop(InspectorSocket* inspector);
82 void inspector_write(InspectorSocket* inspector,
83  const char* data, size_t len);
84 bool inspector_is_active(const InspectorSocket* inspector);
85 
86 inline InspectorSocket* inspector_from_stream(uv_tcp_t* stream) {
87  return node::ContainerOf(&InspectorSocket::tcp, stream);
88 }
89 
90 inline InspectorSocket* inspector_from_stream(uv_stream_t* stream) {
91  return inspector_from_stream(reinterpret_cast<uv_tcp_t*>(stream));
92 }
93 
94 inline InspectorSocket* inspector_from_stream(uv_handle_t* stream) {
95  return inspector_from_stream(reinterpret_cast<uv_tcp_t*>(stream));
96 }
97 
98 } // namespace inspector
99 } // namespace node
100 
101 
102 #endif // SRC_INSPECTOR_SOCKET_H_
bool(* handshake_cb)(InspectorSocket *, enum inspector_handshake_event state, const std::string &path)
void inspector_close(InspectorSocket *inspector, inspector_cb callback)
void inspector_read_stop(InspectorSocket *inspector)
void(* inspector_cb)(InspectorSocket *, int)
int len
Definition: cares_wrap.cc:485
void inspector_write(InspectorSocket *inspector, const char *data, size_t len)
union node::cares_wrap::@8::CaresAsyncData::@0 data
InspectorSocket * inspector_from_stream(uv_tcp_t *stream)
int inspector_accept(uv_stream_t *server, InspectorSocket *socket, handshake_cb callback)
struct http_parsing_state_s * http_parsing_state
bool inspector_is_active(const InspectorSocket *inspector)
int inspector_read_start(InspectorSocket *inspector, uv_alloc_cb alloc_cb, uv_read_cb read_cb)