| 373 | } |
| 374 | |
| 375 | void 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 | |
| 412 | void xs_tcp_get_remoteAddress(xsMachine *the) |
| 413 | { |
nothing calls this directly
no test coverage detected