forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspector_socket.h
88 lines (72 loc) · 2.58 KB
/
inspector_socket.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#ifndef SRC_INSPECTOR_SOCKET_H_
#define SRC_INSPECTOR_SOCKET_H_
#include "http_parser.h"
#include "util.h"
#include "util-inl.h"
#include "uv.h"
#include <string>
#include <vector>
enum inspector_handshake_event {
kInspectorHandshakeUpgrading,
kInspectorHandshakeUpgraded,
kInspectorHandshakeHttpGet,
kInspectorHandshakeFailed
};
struct inspector_socket_s;
typedef void (*inspector_cb)(struct inspector_socket_s*, int);
// Notifies as handshake is progressing. Returning false as a response to
// kInspectorHandshakeUpgrading or kInspectorHandshakeHttpGet event will abort
// the connection. inspector_write can be used from the callback.
typedef bool (*handshake_cb)(struct inspector_socket_s*,
enum inspector_handshake_event state,
const std::string& path);
struct http_parsing_state_s {
http_parser parser;
http_parser_settings parser_settings;
handshake_cb callback;
bool done;
bool parsing_value;
std::string ws_key;
std::string path;
std::string current_header;
};
struct ws_state_s {
uv_alloc_cb alloc_cb;
uv_read_cb read_cb;
inspector_cb close_cb;
bool close_sent;
bool received_close;
};
struct inspector_socket_s {
void* data;
struct http_parsing_state_s* http_parsing_state;
struct ws_state_s* ws_state;
std::vector<char> buffer;
uv_tcp_t client;
bool ws_mode;
bool shutting_down;
bool connection_eof;
};
typedef struct inspector_socket_s inspector_socket_t;
int inspector_accept(uv_stream_t* server, struct inspector_socket_s* inspector,
handshake_cb callback);
void inspector_close(struct inspector_socket_s* inspector,
inspector_cb callback);
// Callbacks will receive stream handles. Use inspector_from_stream to get
// inspector_socket_t* from the stream handle.
int inspector_read_start(struct inspector_socket_s* inspector, uv_alloc_cb,
uv_read_cb);
void inspector_read_stop(struct inspector_socket_s* inspector);
void inspector_write(struct inspector_socket_s* inspector,
const char* data, size_t len);
bool inspector_is_active(const struct inspector_socket_s* inspector);
inline inspector_socket_t* inspector_from_stream(uv_tcp_t* stream) {
return node::ContainerOf(&inspector_socket_t::client, stream);
}
inline inspector_socket_t* inspector_from_stream(uv_stream_t* stream) {
return inspector_from_stream(reinterpret_cast<uv_tcp_t*>(stream));
}
inline inspector_socket_t* inspector_from_stream(uv_handle_t* stream) {
return inspector_from_stream(reinterpret_cast<uv_tcp_t*>(stream));
}
#endif // SRC_INSPECTOR_SOCKET_H_