[net2] toRead() for non-linux (SIOCINQ -> FIONREAD)

This commit is contained in:
David Sklar 2009-12-30 10:06:40 -08:00 committed by Ryan Dahl
parent 402755b14a
commit de9bfdea8e
2 changed files with 8 additions and 3 deletions

View File

@ -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) {

View File

@ -18,8 +18,14 @@
#include <netinet/tcp.h>
#include <sys/ioctl.h>
#include <linux/sockios.h>
#ifdef __linux__
# include <linux/sockios.h> /* For the SIOCINQ / FIONREAD ioctl */
#endif
/* Non-linux platforms like OS X define this ioctl elsewhere */
#ifndef FIONREAD
#include <sys/filio.h>
#endif
#include <errno.h>
@ -530,7 +536,7 @@ static Handle<Value> 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"));