GCC Code Coverage Report
Directory: ../src/ Exec Total Coverage
File: /home/node-core-coverage/node-core-coverage/workdir/node/out/../src/inspector_socket.h Lines: 0 6 0.0 %
Date: 2017-01-02 Branches: 0 0 0.0 %

Line Branch Exec Source
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
15
enum inspector_handshake_event {
16
  kInspectorHandshakeUpgrading,
17
  kInspectorHandshakeUpgraded,
18
  kInspectorHandshakeHttpGet,
19
  kInspectorHandshakeFailed
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
32
struct http_parsing_state_s {
33
  http_parser parser;
34
  http_parser_settings parser_settings;
35
  handshake_cb callback;
36
  bool done;
37
  bool parsing_value;
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;
46
  inspector_cb close_cb;
47
  bool close_sent;
48
  bool received_close;
49
};
50
51
class InspectorSocket {
52
 public:
53
  InspectorSocket() : data(nullptr), http_parsing_state(nullptr),
54
                      ws_state(nullptr), buffer(0), ws_mode(false),
55
                      shutting_down(false), connection_eof(false) { }
56
  void reinit();
57
  void* data;
58
  struct http_parsing_state_s* http_parsing_state;
59
  struct ws_state_s* ws_state;
60
  std::vector<char> buffer;
61
  uv_tcp_t client;
62
  bool ws_mode;
63
  bool shutting_down;
64
  bool connection_eof;
65
 private:
66
  DISALLOW_COPY_AND_ASSIGN(InspectorSocket);
67
};
68
69
int inspector_accept(uv_stream_t* server, InspectorSocket* inspector,
70
                     handshake_cb callback);
71
72
void inspector_close(InspectorSocket* inspector,
73
                     inspector_cb callback);
74
75
// Callbacks will receive stream handles. Use inspector_from_stream to get
76
// InspectorSocket* from the stream handle.
77
int inspector_read_start(InspectorSocket* inspector, uv_alloc_cb,
78
                          uv_read_cb);
79
void inspector_read_stop(InspectorSocket* inspector);
80
void inspector_write(InspectorSocket* inspector,
81
    const char* data, size_t len);
82
bool inspector_is_active(const InspectorSocket* inspector);
83
84
inline InspectorSocket* inspector_from_stream(uv_tcp_t* stream) {
85
  return node::ContainerOf(&InspectorSocket::client, stream);
86
}
87
88
inline InspectorSocket* inspector_from_stream(uv_stream_t* stream) {
89
  return inspector_from_stream(reinterpret_cast<uv_tcp_t*>(stream));
90
}
91
92
inline InspectorSocket* inspector_from_stream(uv_handle_t* stream) {
93
  return inspector_from_stream(reinterpret_cast<uv_tcp_t*>(stream));
94
}
95
96
}  // namespace inspector
97
}  // namespace node
98
99
100
#endif  // SRC_INSPECTOR_SOCKET_H_