diff --git a/lib/net.js b/lib/net.js index 6d0566418a..035272781d 100644 --- a/lib/net.js +++ b/lib/net.js @@ -109,7 +109,6 @@ Socket.prototype._allocateNewRecvBuf = function () { var newBufferSize = 1024; // TODO make this adjustable from user API if (toRead) { - // Note: only Linux supports toRead(). // Is the extra system call even worth it? var bytesToRead = toRead(self.fd); if (bytesToRead > 1024) { diff --git a/src/node_net2.cc b/src/node_net2.cc index 2d7c6c2afb..4056fc28d8 100644 --- a/src/node_net2.cc +++ b/src/node_net2.cc @@ -18,8 +18,14 @@ #include #include -#include +#ifdef __linux__ +# include /* For the SIOCINQ / FIONREAD ioctl */ +#endif +/* Non-linux platforms like OS X define this ioctl elsewhere */ +#ifndef FIONREAD +#include +#endif #include @@ -530,7 +536,7 @@ static Handle ToRead(const Arguments& args) { FD_ARG(args[0]) int value; - int r = ioctl(fd, SIOCINQ, &value); + int r = ioctl(fd, FIONREAD, &value); if (r < 0) { return ThrowException(ErrnoException(errno, "ioctl"));