- if (aeWait(fd,AE_READABLE,wait) & AE_READABLE) {
- nread = read(fd,ptr,size);
- if (nread <= 0) return -1;
+ /* 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 {