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

Function xs_tcp_write

modules/io/socket/lwip/tcp.c:375–410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373}
374
375void xs_tcp_write(xsMachine *the)
376{
377 TCP tcp = xsmcGetHostDataValidate(xsThis, (void *)&xsTCPHooks);
378 xsUnsignedValue needed;
379 void *buffer;
380 uint8_t value;
381
382 if (!tcp->ready)
383 xsUnknownError("not ready");
384
385 if (tcp->error || !tcp->skt)
386 return;
387
388 if (kIOFormatBuffer == tcp->format)
389 xsmcGetBufferReadable(xsArg(0), &buffer, &needed);
390 else {
391 needed = 1;
392 value = (uint8_t)xsmcToInteger(xsArg(0));
393 buffer = &value;
394 }
395
396 if (needed > tcp_sndbuf(tcp->skt))
397 xsUnknownError("would block");
398
399 if (ERR_OK != tcp_write_safe(tcp->skt, buffer, needed, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE)) {
400 xsTrace("tcp write failed\n");
401 tcpTrigger(tcp, kTCPError);
402 return;
403 }
404
405 tcpTrigger(tcp, kTCPOutput);
406
407 modInstrumentationAdjust(NetworkBytesWritten, needed);
408
409 xsmcSetInteger(xsResult, tcp_sndbuf(tcp->skt));
410}
411
412void xs_tcp_get_remoteAddress(xsMachine *the)
413{

Callers

nothing calls this directly

Calls 2

tcp_write_safeFunction · 0.85
tcpTriggerFunction · 0.70

Tested by

no test coverage detected