summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-20 22:11:56 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-20 22:11:56 +0000
commitfdcac09849a7644618a202215a2615f1f029b48b (patch)
tree8f159f32393bbf032ed13c72c857587981e66568 /io.c
parentea6044ea364bbf5a89ee203182f1b093f20c51b3 (diff)
* backport r32579, r32581, r32587 by akr and r32588 by kazu.
r32579: * io.c (rb_update_max_fd): new function. * internal.h (rb_update_max_fd): declare rb_update_max_fd. * thread_pthread.c (rb_thread_create_timer_thread): update max fd when timer thread pipe is created. r32581: * io.c (UPDATE_MAXFD): removed. r32587: * include/ruby/intern.h (rb_update_max_fd): declaration moved from internal.h. * file.c: ditto. * io.c: call rb_update_max_fd for each new fds. * process.c: ditto. * random.c: ditto. * ruby.c: ditto. * ext/io/console/console.c: ditto. * ext/openssl/ossl_bio.c: ditto. * ext/pty/pty.c: ditto. * ext/socket/init.c: ditto. * ext/socket/socket.c: ditto. * ext/socket/ancdata.c: ditto. * ext/socket/unixsocket.c: ditto. r32588: * io.c (rb_update_max_fd): remove parentheses. they are not in macro. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@32591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/io.c b/io.c
index 2a161ed424..840498c94c 100644
--- a/io.c
+++ b/io.c
@@ -151,10 +151,11 @@ struct argf {
};
static int max_file_descriptor = NOFILE;
-#define UPDATE_MAXFD(fd) \
- do { \
- if (max_file_descriptor < (fd)) max_file_descriptor = (fd); \
- } while (0)
+void
+rb_update_max_fd(int fd)
+{
+ if (max_file_descriptor < fd) max_file_descriptor = fd;
+}
#define argf_of(obj) (*(struct argf *)DATA_PTR(obj))
#define ARGF argf_of(argf)
@@ -526,7 +527,7 @@ ruby_dup(int orig)
rb_sys_fail(0);
}
}
- UPDATE_MAXFD(fd);
+ rb_update_max_fd(fd);
return fd;
}
@@ -4591,7 +4592,11 @@ sysopen_func(void *ptr)
static inline int
rb_sysopen_internal(struct sysopen_struct *data)
{
- return (int)rb_thread_blocking_region(sysopen_func, data, RUBY_UBF_IO, 0);
+ int fd;
+ fd = (int)rb_thread_blocking_region(sysopen_func, data, RUBY_UBF_IO, 0);
+ if (0 <= fd)
+ rb_update_max_fd(fd);
+ return fd;
}
static int
@@ -4617,7 +4622,7 @@ rb_sysopen(VALUE fname, int oflags, mode_t perm)
rb_sys_fail(RSTRING_PTR(fname));
}
}
- UPDATE_MAXFD(fd);
+ rb_update_max_fd(fd);
return fd;
}
@@ -4910,8 +4915,8 @@ rb_pipe(int *pipes)
}
}
if (ret == 0) {
- UPDATE_MAXFD(pipes[0]);
- UPDATE_MAXFD(pipes[1]);
+ rb_update_max_fd(pipes[0]);
+ rb_update_max_fd(pipes[1]);
}
return ret;
}
@@ -5793,6 +5798,7 @@ io_reopen(VALUE io, VALUE nfile)
/* need to keep FILE objects of stdin, stdout and stderr */
if (dup2(fd2, fd) < 0)
rb_sys_fail_path(orig->pathv);
+ rb_update_max_fd(fd);
}
else {
fclose(fptr->stdio_file);
@@ -5800,6 +5806,7 @@ io_reopen(VALUE io, VALUE nfile)
fptr->fd = -1;
if (dup2(fd2, fd) < 0)
rb_sys_fail_path(orig->pathv);
+ rb_update_max_fd(fd);
fptr->fd = fd;
}
rb_thread_fd_close(fd);
@@ -6383,6 +6390,7 @@ prep_io(int fd, int fmode, VALUE klass, const char *path)
fp->mode = fmode;
io_check_tty(fp);
if (path) fp->pathv = rb_obj_freeze(rb_str_new_cstr(path));
+ rb_update_max_fd(fd);
return io;
}
@@ -6535,7 +6543,7 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
#else
if (fstat(fd, &st) == -1) rb_sys_fail(0);
#endif
- UPDATE_MAXFD(fd);
+ rb_update_max_fd(fd);
#if defined(HAVE_FCNTL) && defined(F_GETFL)
ofmode = rb_io_oflags_fmode(oflags);
if (NIL_P(vmode)) {
@@ -7690,7 +7698,7 @@ io_cntl(int fd, int cmd, long narg, int io_p)
retval = (int)rb_thread_io_blocking_region(nogvl_io_cntl, &arg, fd);
#if defined(F_DUPFD)
if (!io_p && retval != -1 && cmd == F_DUPFD) {
- UPDATE_MAXFD(retval);
+ rb_update_max_fd(retval);
}
#endif