MCPcopy Create free account
hub / github.com/ClassiCube/ClassiCube / MPConnection_SendData

Function MPConnection_SendData

src/Server.c:458–480  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

456}
457
458static void MPConnection_SendData(const cc_uint8* data, cc_uint32 len) {
459 cc_uint32 wrote;
460 cc_result res;
461 int tries = 0;
462 if (Server.Disconnected) return;
463
464 while (len) {
465 res = Socket_Write(net_socket, data, len, &wrote);
466 /* If sending would block (send buffer full), retry for a bit up to 10 seconds */
467 /* TODO: Avoid doing this and manually buffer data when this happens */
468 if (res && tries < 1000 && (res == ReturnCode_SocketInProgess || res == ReturnCode_SocketWouldBlock)) {
469 Thread_Sleep(10);
470 tries++;
471 continue;
472 }
473
474 /* NOTE: Not immediately disconnecting here, as otherwise we sometimes miss out on kick messages */
475 if (res) { net_writeFailure = res; return; }
476 if (!wrote) { net_writeFailure = ERR_INVALID_ARGUMENT; return; }
477
478 data += wrote; len -= wrote;
479 }
480}
481
482static void MPConnection_Init(void) {
483 Server_ResetState();

Callers

nothing calls this directly

Calls 2

Socket_WriteFunction · 0.70
Thread_SleepFunction · 0.70

Tested by

no test coverage detected