make timed kgio_wait_* implementation safer
[kgio.git] / ext / kgio / nonblock.h
blob43de8cd98f7fb58b05e5ac67186f48f3fdf4773c
1 #include <ruby.h>
2 #include <unistd.h>
3 #include <fcntl.h>
4 static void set_nonblocking(int fd)
6 int flags = fcntl(fd, F_GETFL);
8 if (flags == -1)
9 rb_sys_fail("fcntl(F_GETFL)");
10 if ((flags & O_NONBLOCK) == O_NONBLOCK)
11 return;
12 flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
13 if (flags == -1)
14 rb_sys_fail("fcntl(F_SETFL)");