MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / xs_tcp_write

Function xs_tcp_write

modules/io/socket/lin/tcp.c:314–349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312}
313
314void xs_tcp_write(xsMachine *the)
315{
316 TCP tcp = xsmcGetHostDataValidate(xsThis, (void *)&xsTCPHooks);
317 xsUnsignedValue needed;
318 void *buffer;
319 uint8_t value;
320
321 if (!tcp->skt) {
322 xsTrace("write to closed socket\n");
323 return;
324 }
325
326 if (kIOFormatBuffer == tcp->format)
327 xsmcGetBufferReadable(xsArg(0), &buffer, &needed);
328 else {
329 needed = 1;
330 value = (uint8_t)xsmcToInteger(xsArg(0));
331 buffer = &value;
332 }
333
334 if (needed > tcp->bytesWritable)
335 xsUnknownError("would block");
336
337 tcp->bytesWritable -= needed;
338
339 int ret = write(tcp->skt, buffer, needed);
340 if (ret < 0) {
341 xsTrace("write failed");
342 tcpTrigger(tcp, kTCPError);
343 return;
344 }
345
346 modInstrumentationAdjust(NetworkBytesWritten, needed);
347
348 xsmcSetInteger(xsResult, tcp->bytesWritable);
349}
350
351void xs_tcp_get_remoteAddress(xsMachine *the)
352{

Callers

nothing calls this directly

Calls 2

tcpTriggerFunction · 0.70
writeFunction · 0.50

Tested by

no test coverage detected