X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/d1d9452a687184ac6b992fadc77e89c8a308e388..7df336e60c959c440b2c330f7a7ca9b0251db2a1:/stglibs/common.lib/common.cpp diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index c7c1bf05..5bd66c87 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -1015,3 +1015,35 @@ if (res == 0) // Timeout return true; } + +bool ReadAll(int sd, void * dest, size_t size) +{ +size_t done = 0; +char * ptr = static_cast(dest); +while (done < size) + { + if (!WaitPackets(sd)) + return false; + ssize_t res = read(sd, ptr + done, size - done); + if (res < 0) + return false; + if (res == 0) + return true; + done += res; + } +return true; +} + +bool WriteAll(int sd, const void * source, size_t size) +{ +size_t done = 0; +const char * ptr = static_cast(source); +while (done < size) + { + ssize_t res = write(sd, ptr + done, size - done); + if (res <= 0) + return false; + done += res; + } +return true; +}