[net2] toRead() for non-linux (SIOCINQ -> FIONREAD)
This commit is contained in:
parent
402755b14a
commit
de9bfdea8e
@ -109,7 +109,6 @@ Socket.prototype._allocateNewRecvBuf = function () {
|
|||||||
var newBufferSize = 1024; // TODO make this adjustable from user API
|
var newBufferSize = 1024; // TODO make this adjustable from user API
|
||||||
|
|
||||||
if (toRead) {
|
if (toRead) {
|
||||||
// Note: only Linux supports toRead().
|
|
||||||
// Is the extra system call even worth it?
|
// Is the extra system call even worth it?
|
||||||
var bytesToRead = toRead(self.fd);
|
var bytesToRead = toRead(self.fd);
|
||||||
if (bytesToRead > 1024) {
|
if (bytesToRead > 1024) {
|
||||||
|
@ -18,8 +18,14 @@
|
|||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
|
|
||||||
#include <sys/ioctl.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>
|
#include <errno.h>
|
||||||
|
|
||||||
@ -530,7 +536,7 @@ static Handle<Value> ToRead(const Arguments& args) {
|
|||||||
FD_ARG(args[0])
|
FD_ARG(args[0])
|
||||||
|
|
||||||
int value;
|
int value;
|
||||||
int r = ioctl(fd, SIOCINQ, &value);
|
int r = ioctl(fd, FIONREAD, &value);
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
return ThrowException(ErrnoException(errno, "ioctl"));
|
return ThrowException(ErrnoException(errno, "ioctl"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user