MCPcopy Create free account
hub / github.com/Tencent/UnLua / socket_read

Function socket_read

Plugins/UnLuaExtensions/LuaSocket/Source/src/usocket.cpp:343–360  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Read with timeout * See note for socket_write \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

341* See note for socket_write
342\*-------------------------------------------------------------------------*/
343int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm) {
344 int err;
345 *got = 0;
346 if (*ps == SOCKET_INVALID) return IO_CLOSED;
347 for ( ;; ) {
348 long taken = (long) read(*ps, data, count);
349 if (taken > 0) {
350 *got = taken;
351 return IO_DONE;
352 }
353 err = errno;
354 if (taken == 0) return IO_CLOSED;
355 if (err == EINTR) continue;
356 if (err != EAGAIN) return err;
357 if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
358 }
359 return IO_UNKNOWN;
360}
361
362/*-------------------------------------------------------------------------*\
363* Put socket into blocking mode

Callers

nothing calls this directly

Calls 1

socket_waitfdFunction · 0.70

Tested by

no test coverage detected