GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../src/inspector_socket.h Lines: 10 10 100.0 %
Date: 2017-06-14 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
40
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
// HTTP Wrapper around a uv_tcp_t
52
20
class InspectorSocket {
53
 public:
54
20
  InspectorSocket() : data(nullptr), http_parsing_state(nullptr),
55
                      ws_state(nullptr), buffer(0), ws_mode(false),
56
20
                      shutting_down(false), connection_eof(false) { }
57
  void reinit();
58
  void* data;
59
  struct http_parsing_state_s* http_parsing_state;
60
  struct ws_state_s* ws_state;
61
  std::vector<char> buffer;
62
  uv_tcp_t tcp;
63
  bool ws_mode;
64
  bool shutting_down;
65
  bool connection_eof;
66
 private:
67
  DISALLOW_COPY_AND_ASSIGN(InspectorSocket);
68
};
69
70
int inspector_accept(uv_stream_t* server, InspectorSocket* inspector,
71
                     handshake_cb callback);
72
73
void inspector_close(InspectorSocket* inspector,
74
                     inspector_cb callback);
75
76
// Callbacks will receive stream handles. Use inspector_from_stream to get
77
// InspectorSocket* from the stream handle.
78
int inspector_read_start(InspectorSocket* inspector, uv_alloc_cb,
79
                          uv_read_cb);
80
void inspector_read_stop(InspectorSocket* inspector);
81
void inspector_write(InspectorSocket* inspector,
82
    const char* data, size_t len);
83
bool inspector_is_active(const InspectorSocket* inspector);
84
85
137
inline InspectorSocket* inspector_from_stream(uv_tcp_t* stream) {
86
137
  return node::ContainerOf(&InspectorSocket::tcp, stream);
87
}
88
89
102
inline InspectorSocket* inspector_from_stream(uv_stream_t* stream) {
90
102
  return inspector_from_stream(reinterpret_cast<uv_tcp_t*>(stream));
91
}
92
93
35
inline InspectorSocket* inspector_from_stream(uv_handle_t* stream) {
94
35
  return inspector_from_stream(reinterpret_cast<uv_tcp_t*>(stream));
95
}
96
97
}  // namespace inspector
98
}  // namespace node
99
100
101
#endif  // SRC_INSPECTOR_SOCKET_H_