summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-05-21 01:22:20 -0700
committerRyan Dahl <ry@tinyclouds.org>2010-05-21 01:22:20 -0700
commit0de138acb59e620e0a542ace665abce7df49439f (patch)
tree7caf42217cf44600c6e9a521ad6c013f3e6aaa82
parentf73b6e219046bf66505c1fa1cd07d82b8644329d (diff)
downloadnode-new-0de138acb59e620e0a542ace665abce7df49439f.tar.gz
improve test for stdio non-blockingness
-rw-r--r--src/node_stdio.cc30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/node_stdio.cc b/src/node_stdio.cc
index a68d302fd1..94ee73a961 100644
--- a/src/node_stdio.cc
+++ b/src/node_stdio.cc
@@ -65,19 +65,27 @@ static Handle<Value> OpenStdin(const Arguments& args) {
return scope.Close(Integer::New(STDIN_FILENO));
}
-static Handle<Value>
-IsStdinBlocking (const Arguments& args)
-{
- HandleScope scope;
- return scope.Close(Boolean::New(!isatty(STDIN_FILENO)));
+
+static bool IsBlocking(int fd) {
+ if (isatty(fd)) return false;
+ struct stat s;
+ if (fstat(fd, &s)) {
+ perror("fstat");
+ return true;
+ }
+ if (s.st_mode & S_IFSOCK == S_IFSOCK) return false;
+ if (s.st_mode & S_IFIFO == S_IFIFO) return false;
+ return true;
}
-static Handle<Value>
-IsStdoutBlocking (const Arguments& args)
-{
- HandleScope scope;
- bool tty = isatty(STDOUT_FILENO);
- return scope.Close(Boolean::New(!tty));
+
+static Handle<Value> IsStdinBlocking(const Arguments& arg) {
+ return IsBlocking(STDIN_FILENO) ? True() : False();
+}
+
+
+static Handle<Value> IsStdoutBlocking(const Arguments& args) {
+ return IsBlocking(STDOUT_FILENO) ? True() : False();
}