-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathwebsocket.h
More file actions
42 lines (34 loc) · 859 Bytes
/
websocket.h
File metadata and controls
42 lines (34 loc) · 859 Bytes
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
/*
handle websocket connections
*/
#pragma once
#include <stdint.h>
#include <unistd.h>
#include <string>
#include <openssl/ssl.h>
class WebSocket {
public:
WebSocket(int fd);
static bool detect(int fd);
ssize_t send(const void *buf, size_t n);
ssize_t recv(void *buf, size_t n);
bool is_SSL(void) const {
return _is_SSL;
}
private:
int fd = -1;
bool _is_SSL = false;
bool SSL_handshake_complete = false;
uint8_t pending[1024] {};
uint32_t npending = 0;
SSL *ssl = nullptr;
SSL_CTX *ctx = nullptr;
bool done_headers = false;
char handshake_buf[512] {};
size_t handshake_len = 0;
size_t handshake_sent = 0;
void fill_pending(void);
bool send_handshake(const std::string &key);
void check_headers(void);
ssize_t decode(uint8_t *buf, size_t n, size_t &used);
};