MCPcopy Create free account
hub / github.com/ElementsProject/lightning / lightningd_to_websocket

Function lightningd_to_websocket

connectd/websocketd.c:208–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206}
207
208static void lightningd_to_websocket(int lightningfd, int wsfd)
209{
210 /* We prepend ws header */
211 u8 buf[4 + 65535];
212 int len;
213 /* Not continued frame (0x80), opcode = 2 (binary) */
214 const u8 firstbyte = 0x82;
215 size_t off;
216
217 len = read(lightningfd, 4 + buf, sizeof(buf) - 4);
218 if (len <= 0)
219 exit(0);
220
221 if (len > 125) {
222 buf[0] = firstbyte;
223 buf[1] = 126;
224 buf[2] = (len >> 8);
225 buf[3] = len;
226 off = 0;
227 len += 4;
228 } else {
229 buf[2] = firstbyte;
230 buf[3] = len;
231 off = 2;
232 len += 2;
233 }
234 if (!write_all(wsfd, buf + off, len))
235 exit(0);
236}
237
238/* Returns payload size, sets inmask, is_binframe */
239static size_t read_payload_header(int fd, u8 inmask[4], bool *is_binframe)

Callers 1

mainFunction · 0.85

Calls 1

write_allFunction · 0.50

Tested by

no test coverage detected