diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-15 15:37:20 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-15 15:37:20 +0000 |
commit | 6227816910c2d125193bb4c6bb044e7bca91bec6 (patch) | |
tree | 77d6c2857cc730406aa240a49fd62553fe4a53fc /win32 | |
parent | d5251e8d25eb0d86d3eab3f6deceb11896f73e59 (diff) |
merges r21487 from trunk into ruby_1_9_1.
* include/ruby/intern.h, thread.c, win32/Makefile.sub (rb_fdset_t,
rb_fd_init, rb_fd_term, rb_fd_zero, rb_fd_set, rb_fd_clr, rb_fd_isset,
rb_fd_select, rb_fd_ptr, rb_fd_max, HAVE_RB_FD_INIT): new type,
functions, and macros for Windows.
* win32/win32.c (extract_fd, rb_w32_select): use rb_fdset_t to expand
fd_array if needed. [ruby-core:19946]
* win32/win32.c (copy_fd): new funcion for rb_w32_select().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21549 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r-- | win32/Makefile.sub | 5 | ||||
-rw-r--r-- | win32/win32.c | 97 |
2 files changed, 63 insertions, 39 deletions
diff --git a/win32/Makefile.sub b/win32/Makefile.sub index e25a150e20..a3eef90bb3 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -223,7 +223,11 @@ RUBY = ruby !endif !if !defined(STACK) +!if "$(ARCH)" == "x64" || "$(ARCH)" == "ia64" +STACK = 0x400000 +!else STACK = 0x200000 +!endif !if defined(STACK_COMMIT) STACK = $(STACK),$(STACK_COMMIT) !endif @@ -454,6 +458,7 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub #define RSHIFT(x,y) ((x)>>(int)y) #define FILE_COUNT _cnt #define FILE_READPTR _ptr +#define HAVE_RB_FD_INIT 1 #define RUBY_SETJMP(env) _setjmp(env) #define RUBY_LONGJMP(env,val) longjmp(env,val) #define RUBY_JMP_BUF jmp_buf diff --git a/win32/win32.c b/win32/win32.c index 24d457a85b..b948fe0d77 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -1990,11 +1990,8 @@ rb_w32_fdclr(int fd, fd_set *set) for (i = 0; i < set->fd_count; i++) { if (set->fd_array[i] == s) { - while (i < set->fd_count - 1) { - set->fd_array[i] = set->fd_array[i + 1]; - i++; - } - set->fd_count--; + memmove(&set->fd_array[i], &set->fd_array[i+1], + sizeof(set->fd_array[0]) * (--set->fd_count - i)); break; } } @@ -2022,7 +2019,7 @@ rb_w32_fdisset(int fd, fd_set *set) #undef select static int -extract_fd(fd_set *dst, fd_set *src, int (*func)(SOCKET)) +extract_fd(rb_fdset_t *dst, fd_set *src, int (*func)(SOCKET)) { int s = 0; if (!src || !dst) return 0; @@ -2033,11 +2030,16 @@ extract_fd(fd_set *dst, fd_set *src, int (*func)(SOCKET)) if (!func || (*func)(fd)) { /* move it to dst */ int d; - for (d = 0; d < dst->fd_count; d++) { - if (dst->fd_array[d] == fd) break; + for (d = 0; d < dst->fdset->fd_count; d++) { + if (dst->fdset->fd_array[d] == fd) + break; } - if (d == dst->fd_count && dst->fd_count < FD_SETSIZE) { - dst->fd_array[dst->fd_count++] = fd; + if (d == dst->fdset->fd_count) { + if (dst->fdset->fd_count >= dst->capa) { + dst->capa = (dst->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE; + dst->fdset = xrealloc(dst->fdset, sizeof(unsigned int) + sizeof(SOCKET) * dst->capa); + } + dst->fdset->fd_array[dst->fdset->fd_count++] = fd; } memmove( &src->fd_array[s], @@ -2047,6 +2049,27 @@ extract_fd(fd_set *dst, fd_set *src, int (*func)(SOCKET)) else s++; } + return dst->fdset->fd_count; +} + +static int +copy_fd(fd_set *dst, fd_set *src) +{ + int s; + if (!src || !dst) return 0; + + for (s = 0; s < src->fd_count; ++s) { + SOCKET fd = src->fd_array[s]; + int d; + for (d = 0; d < dst->fd_count; ++d) { + if (dst->fd_array[d] == fd) + break; + } + if (d == dst->fd_count && d < FD_SETSIZE) { + dst->fd_array[dst->fd_count++] = fd; + } + } + return dst->fd_count; } @@ -2187,11 +2210,11 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *timeout) { int r; - fd_set pipe_rd; - fd_set cons_rd; - fd_set else_rd; - fd_set else_wr; - fd_set except; + rb_fdset_t pipe_rd; + rb_fdset_t cons_rd; + rb_fdset_t else_rd; + rb_fdset_t else_wr; + rb_fdset_t except; int nonsock = 0; struct timeval limit; @@ -2226,19 +2249,19 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, // until some data is read from pipe. but ruby is single threaded system, // so whole system will be blocked forever. - else_rd.fd_count = 0; + rb_fd_init(&else_rd); nonsock += extract_fd(&else_rd, rd, is_not_socket); - pipe_rd.fd_count = 0; - extract_fd(&pipe_rd, &else_rd, is_pipe); // should not call is_pipe for socket + rb_fd_init(&pipe_rd); + extract_fd(&pipe_rd, else_rd.fdset, is_pipe); // should not call is_pipe for socket - cons_rd.fd_count = 0; - extract_fd(&cons_rd, &else_rd, is_console); // ditto + rb_fd_init(&cons_rd); + extract_fd(&cons_rd, else_rd.fdset, is_console); // ditto - else_wr.fd_count = 0; + rb_fd_init(&else_wr); nonsock += extract_fd(&else_wr, wr, is_not_socket); - except.fd_count = 0; + rb_fd_init(&except); extract_fd(&except, ex, is_not_socket); // drop only r = 0; @@ -2257,15 +2280,17 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, if (nonsock) { // modifying {else,pipe,cons}_rd is safe because // if they are modified, function returns immediately. - extract_fd(&else_rd, &pipe_rd, is_readable_pipe); - extract_fd(&else_rd, &cons_rd, is_readable_console); + extract_fd(&else_rd, pipe_rd.fdset, is_readable_pipe); + extract_fd(&else_rd, cons_rd.fdset, is_readable_console); } - if (else_rd.fd_count || else_wr.fd_count) { + if (else_rd.fdset->fd_count || else_wr.fdset->fd_count) { r = do_select(nfds, rd, wr, ex, &zero); // polling if (r < 0) break; // XXX: should I ignore error and return signaled handles? - r += extract_fd(rd, &else_rd, NULL); // move all - r += extract_fd(wr, &else_wr, NULL); // move all + r = copy_fd(rd, else_rd.fdset); + r += copy_fd(wr, else_wr.fdset); + if (ex) + r += ex->fd_count; break; } else { @@ -2295,6 +2320,12 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex, } } + rb_fd_term(&except); + rb_fd_term(&else_wr); + rb_fd_term(&cons_rd); + rb_fd_term(&pipe_rd); + rb_fd_term(&else_rd); + return r; } @@ -4345,10 +4376,6 @@ rb_w32_read(int fd, void *buf, size_t size) if (_get_osfhandle(fd) == -1) { return -1; } - if (!(_osfile(fd) & FOPEN)) { - errno = EBADF; - return -1; - } if (_osfile(fd) & FTEXT) { return _read(fd, buf, size); @@ -4467,10 +4494,6 @@ rb_w32_write(int fd, const void *buf, size_t size) if (_get_osfhandle(fd) == -1) { return -1; } - if (!(_osfile(fd) & FOPEN)) { - errno = EBADF; - return -1; - } if (_osfile(fd) & FTEXT) { return _write(fd, buf, size); @@ -4703,10 +4726,6 @@ rb_w32_isatty(int fd) if (_get_osfhandle(fd) == -1) { return 0; } - if (!(_osfile(fd) & FOPEN)) { - errno = EBADF; - return 0; - } if (!(_osfile(fd) & FDEV)) { errno = ENOTTY; return 0; |