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

Function xs_tcp_write

modules/io/socket/win/tcp.c:307–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

sendFunction · 0.85
tcpTriggerFunction · 0.70

Tested by

no test coverage detected