MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / duk_trans_socket_peek_cb

Function duk_trans_socket_peek_cb

Source/Utils/duk_trans_socket_windows.cpp:337–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335}
336
337duk_size_t duk_trans_socket_peek_cb(void *udata) {
338 u_long avail;
339 int rc;
340
341 (void) udata; /* not needed by the example */
342
343#if defined(DEBUG_PRINTS)
344 fprintf(stderr, "%s: udata=%p\n", __FUNCTION__, (void *) udata);
345 fflush(stderr);
346#endif
347
348 if (client_sock == INVALID_SOCKET) {
349 return 0;
350 }
351
352 avail = 0;
353 rc = ioctlsocket(client_sock, FIONREAD, &avail);
354 if (rc != 0) {
355 fprintf(stderr, "%s: ioctlsocket() returned %d, closing connection\n",
356 __FILE__, rc);
357 fflush(stderr);
358 goto fail; /* also returns 0, which is correct */
359 } else {
360 if (avail == 0) {
361 return 0; /* nothing to read */
362 } else {
363 return 1; /* something to read */
364 }
365 }
366 /* never here */
367
368 fail:
369 if (client_sock != INVALID_SOCKET) {
370 (void) closesocket(client_sock);
371 client_sock = INVALID_SOCKET;
372 }
373 return 0;
374}
375
376void duk_trans_socket_read_flush_cb(void *udata) {
377 (void) udata; /* not needed by the example */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected