MCPcopy Create free account
hub / github.com/axmolengine/axmol / sendFrame

Method sendFrame

core/network/WebSocket.cpp:167–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165struct WebSocketProtocol
166{
167 static int sendFrame(WebSocket& ws,
168 const char* buf,
169 size_t len,
170 ws::detail::opcode opcode /* = WS_OPCODE_BINARY */,
171 bool fin = true)
172 {
173 int flags = (int)opcode;
174
175 // role == WS_CLIENT
176 uint32_t key = ax::random();
177 char mask[4];
178 mask[0] = (key >> 0) & 0xff;
179 mask[1] = (key >> 8) & 0xff;
180 mask[2] = (key >> 16) & 0xff;
181 mask[3] = (key >> 24) & 0xff;
182 flags |= WS_HAS_MASK;
183
184 if (fin)
185 flags |= WS_FIN;
186 auto frame_size = websocket_calc_frame_size((websocket_flags)flags, len);
187 yasio::sbyte_buffer sb;
188 sb.resize(frame_size);
189 websocket_build_frame(sb.data(), (websocket_flags)flags, mask, buf, len);
190 return ws._service->write(ws._transport, std::move(sb)); // write(sendbuf_.base, frame_size);
191 }
192};
193
194WebSocket::WebSocket() : _isDestroyed(std::make_shared<std::atomic<bool>>(false)), _delegate(nullptr)

Callers

nothing calls this directly

Calls 6

randomFunction · 0.85
websocket_build_frameFunction · 0.85
resizeMethod · 0.45
dataMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected