X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/72229403aae25f742c07d07d625bdc1e313b401d..107a6a8d0b9eae3c4375a685e49dcf90bea69335:/stglibs/common.lib/common.cpp?ds=inline diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index fb6cdbb1..425c3ee6 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -1067,3 +1067,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; +}