Treat a negative number of bytes to read as the kernel saying "I don't know."

svn:r1426
This commit is contained in:
Nick Mathewson 2009-09-11 18:21:37 +00:00
parent f65b8b0964
commit 3b461a6d03
2 changed files with 3 additions and 3 deletions

View File

@ -17,7 +17,7 @@ Changes in 2.0.3-alpha:
o Support sendfile on Solaris: patch from Caitlin Mercer.
o New functions to explicitly reference a socket used by an evhttp object. Patches from David Reiss.
o When we send a BEV_EVENT_CONNECTED to indicate connected status, we no longer invoke the write callback as well unless we actually wrote data too.
o If the kernel tells us that there are a negative number of bytes to read from a socket, do not believe it. Fixes bug 2841177; found by Alexander Pronchenkov.
Changes in 2.0.2-alpha:
o Add a new flag to bufferevents to make all callbacks automatically deferred.

View File

@ -1607,9 +1607,9 @@ evbuffer_read(struct evbuffer *buf, evutil_socket_t fd, int howmuch)
#if defined(FIONREAD)
#ifdef WIN32
if (ioctlsocket(fd, FIONREAD, &lng) == -1 || (n=lng) == 0) {
if (ioctlsocket(fd, FIONREAD, &lng) == -1 || (n=lng) <= 0) {
#else
if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) {
if (ioctl(fd, FIONREAD, &n) == -1 || n <= 0) {
#endif
n = EVBUFFER_MAX_READ;
} else if (n > EVBUFFER_MAX_READ && n > howmuch) {