From de9bfdea8e0aaf9eab86b5ea3d08bb52a4f625ff Mon Sep 17 00:00:00 2001 From: David Sklar Date: Wed, 30 Dec 2009 10:06:40 -0800 Subject: [PATCH] [net2] toRead() for non-linux (SIOCINQ -> FIONREAD) --- lib/net.js | 1 - src/node_net2.cc | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) 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"));