Skip to content

Commit 0de138a

Browse files
committed
improve test for stdio non-blockingness
1 parent f73b6e2 commit 0de138a

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

src/node_stdio.cc

+19-11
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,27 @@ static Handle<Value> OpenStdin(const Arguments& args) {
6565
return scope.Close(Integer::New(STDIN_FILENO));
6666
}
6767

68-
static Handle<Value>
69-
IsStdinBlocking (const Arguments& args)
70-
{
71-
HandleScope scope;
72-
return scope.Close(Boolean::New(!isatty(STDIN_FILENO)));
68+
69+
static bool IsBlocking(int fd) {
70+
if (isatty(fd)) return false;
71+
struct stat s;
72+
if (fstat(fd, &s)) {
73+
perror("fstat");
74+
return true;
75+
}
76+
if (s.st_mode & S_IFSOCK == S_IFSOCK) return false;
77+
if (s.st_mode & S_IFIFO == S_IFIFO) return false;
78+
return true;
7379
}
7480

75-
static Handle<Value>
76-
IsStdoutBlocking (const Arguments& args)
77-
{
78-
HandleScope scope;
79-
bool tty = isatty(STDOUT_FILENO);
80-
return scope.Close(Boolean::New(!tty));
81+
82+
static Handle<Value> IsStdinBlocking(const Arguments& arg) {
83+
return IsBlocking(STDIN_FILENO) ? True() : False();
84+
}
85+
86+
87+
static Handle<Value> IsStdoutBlocking(const Arguments& args) {
88+
return IsBlocking(STDOUT_FILENO) ? True() : False();
8189
}
8290

8391

0 commit comments

Comments
 (0)