9 #include "../framework/socketconnection.h"
15 unsigned int httpVersion() {
19 void sendWsMessage(
const std::string &msg);
20 void sendWsBinary(
const char *buf,
size_t len);
24 void startWsBinStream(
size_t len) {
25 startWsStream(len,
true);
27 void startWsTxtStream(
size_t len) {
28 startWsStream(len,
false);
30 void abortWsStream() {
33 void sendWsClose(uint16_t code, std::string msg);
42 void streamWsResponse() {
43 stream_incoming =
true;
47 const unsigned char *responseMask()
const {
48 if (incoming_is_masked)
54 size_t wsIncomingBytesLeft()
const {
55 return bytes_to_receive;
57 size_t wsBytesReceived()
const {
58 return tot_to_receive-bytes_to_receive;
60 size_t wsOutgoingBytesLeft()
const {
63 size_t wsBytesSent()
const {
64 return tot_to_send-bytes_to_send;
66 bool isWebsocket()
const {
72 uint16_t iptype = 0,
struct addrinfo *local_addr =
nullptr) :
76 const char *ip, uint16_t
port) :
80 void set_http_version(
unsigned int major,
unsigned int minor) {
81 http_version = 10U*major + minor;
84 void send_ws_handshake(
const std::string &key);
85 void send_ws_bin_header(
size_t len);
86 void send_ws_txt_header(
size_t len);
88 PollState incoming_ws_data(
const char *buf,
size_t len);
89 PollState incoming_ws_header(
const char *buf,
size_t len);
90 PollState wsReadData(
const char *buf,
size_t len);
97 bool is_websocket =
false;
99 void startWsStream(
size_t len,
bool is_binary =
true);
101 unsigned char current_opcode = 0;
102 bool receiving_message =
false;
103 bool sending_message =
false;
104 bool output_is_binary =
false;
105 bool stream_incoming =
false;
106 bool incoming_is_masked =
false;
107 bool incoming_is_binary =
false;
108 size_t bytes_to_send, tot_to_send;
109 size_t bytes_to_receive, tot_to_receive;
110 unsigned char incoming_mask[4];
111 unsigned int http_version = 11;
Definition: httpconnection.h:11
void setOwner(Task *new_owner) override
Set the given task as owner of the socket.
Definition: httpconnection.cpp:358
std::string label() const
Return the object's log label.
Definition: logger.h:251
This class implements low-level socket connection operations. Inherit from it to implement protocols ...
Definition: socketconnection.h:47
SocketConnection(const std::string &label, Task *owner, const std::string &hostname, uint16_t port, uint16_t iptype=0, struct addrinfo *local_addr=nullptr)
Definition: socketconnection.cpp:25
Task * owner() const
Return task owning the socket.
Definition: socket.h:27
std::string hostname() const
Return name of the host to which the socket is supposed to connect.
Definition: socket.h:32
uint16_t port() const
Return port number to which the socket is supposed to connect.
Definition: socket.h:37
void closeMe()
Tell the network engine that the connection should be closed.
Definition: socket.h:178
The purpose of a task is to manage socket connections, and/or to execute timers.
Definition: task.h:39
PollState
Definition: pollstate.h:11