-ssize_t Deserializer::myread(void* __buf, size_t __nbytes){
- return read (filedesc, __buf, __nbytes);
+ssize_t Deserializer::myread(void *__buf, size_t bytestoread) {
+ char *out = (char * ) __buf;
+ size_t totalbytesread = 0;
+ while (bytestoread) {
+ if (bufferbytes != 0) {
+ uint bytestocopy = (bufferbytes > bytestoread) ? bytestoread : bufferbytes;
+ memcpy(out, &buffer[bufferindex], bytestocopy);
+ //update local buffer
+ bufferbytes -= bytestocopy;
+ bufferindex += bytestocopy;
+ totalbytesread += bytestocopy;
+ //update request pointers
+ out += bytestocopy;
+ bytestoread -= bytestocopy;
+ } else {
+ ssize_t bytesread = read (filedesc, buffer, buffercap);
+ bufferindex = 0;
+ bufferbytes = bytesread;
+ if (bytesread == 0) {
+ break;
+ } else if (bytesread < 0) {
+ exit(-1);
+ }
+ }
+ }
+ return totalbytesread;