diff options
Diffstat (limited to 'ext/sleepy_penguin/nonblock.h')
-rw-r--r-- | ext/sleepy_penguin/nonblock.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/ext/sleepy_penguin/nonblock.h b/ext/sleepy_penguin/nonblock.h new file mode 100644 index 0000000..7198114 --- /dev/null +++ b/ext/sleepy_penguin/nonblock.h @@ -0,0 +1,19 @@ +#ifndef SLEEPY_PENGUIN_NONBLOCK_H +#define SLEEPY_PENGUIN_NONBLOCK_H +#include <unistd.h> +#include <fcntl.h> +#include <ruby.h> +static void set_nonblock(int fd) +{ + int flags = fcntl(fd, F_GETFL); + + if (flags == -1) + rb_sys_fail("fcntl(F_GETFL)"); + if ((flags & O_NONBLOCK) == O_NONBLOCK) + return; + flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK); + if (flags == -1) + rb_sys_fail("fcntl(F_SETFL)"); +} + +#endif /* SLEEPY_PENGUIN_NONBLOCK_H */ |