- timeout++;
- while(size) {
- if (aeWait(fd,AE_READABLE,1000) & AE_READABLE) {
- nread = read(fd,ptr,size);
- if (nread <= 0) return -1;
+ if (size == 0) return 0;
+ while(1) {
+ long long wait = (remaining > REDIS_SYNCIO_RESOLUTION) ?
+ remaining : REDIS_SYNCIO_RESOLUTION;
+ long long elapsed;
+
+ /* Optimistically try to read before checking if the file descriptor
+ * is actually readable. At worst we get EAGAIN. */
+ nread = read(fd,ptr,size);
+ if (nread == 0) return -1; /* short read. */
+ if (nread == -1) {
+ if (errno != EAGAIN) return -1;
+ } else {