MCPcopy Create free account
hub / github.com/acl-dev/acl / ws_msg

Function ws_msg

app/wizard/tmpl/http/websocket.cpp:73–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73static bool ws_msg(acl::websocket& in, acl::websocket& out)
74{
75 acl::string tbuf((size_t) in.get_frame_payload_len() + 1);
76
77 char buf[4096];
78 while (true) {
79 int ret = in.read_frame_data(buf, sizeof(buf) - 1);
80 if (ret == 0) {
81 break;
82 }
83
84 if (ret < 0) {
85 printf("read_frame_data error\r\n");
86 return false;
87 }
88
89 tbuf.append(buf, ret);
90 }
91
92 printf(">>>%s\r\n", tbuf.c_str());
93
94 // Just echo the received data to client.
95 unsigned mask = ~0;
96 out.reset() // Must reset the websocket before each writing.
97 .set_frame_fin(true)
98 .set_frame_opcode(acl::FRAME_BINARY)
99 .set_frame_payload_len(tbuf.size())
100 .set_frame_masking_key(mask);
101
102 if (out.send_frame_data(tbuf.c_str(), tbuf.size())) {
103 printf("send_frame_data ok\r\n");
104 return true;
105 }
106
107 tbuf += "\0";
108 printf("send_frame_data error, data size=%zd\r\n", tbuf.size());
109 return false;
110}
111
112bool websocket_run(HttpRequest& req, HttpResponse&)
113{

Callers 1

websocket_runFunction · 0.85

Calls 6

read_frame_dataMethod · 0.80
send_frame_dataMethod · 0.80
appendMethod · 0.45
c_strMethod · 0.45
resetMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…