* win32/win32.c (rb_w32_select): check invalid handle before doing
select operations. see [ruby-dev:43513], [ruby-dev:43535] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31543 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7ed51785df
commit
425b30bc78
@ -1,3 +1,8 @@
|
|||||||
|
Fri May 13 15:22:34 2011 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* win32/win32.c (rb_w32_select): check invalid handle before doing
|
||||||
|
select operations. see [ruby-dev:43513], [ruby-dev:43535]
|
||||||
|
|
||||||
Fri May 13 08:34:00 2011 Eric Hodel <drbrain@segment7.net>
|
Fri May 13 08:34:00 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* lib/rdoc/rdoc.rb: Output summary after documentation report.
|
* lib/rdoc/rdoc.rb: Output summary after documentation report.
|
||||||
|
@ -2391,12 +2391,14 @@ static int
|
|||||||
extract_fd(rb_fdset_t *dst, fd_set *src, int (*func)(SOCKET))
|
extract_fd(rb_fdset_t *dst, fd_set *src, int (*func)(SOCKET))
|
||||||
{
|
{
|
||||||
unsigned int s = 0;
|
unsigned int s = 0;
|
||||||
if (!src || !dst) return 0;
|
unsigned int m = 0;
|
||||||
|
if (!src) return 0;
|
||||||
|
|
||||||
while (s < src->fd_count) {
|
while (s < src->fd_count) {
|
||||||
SOCKET fd = src->fd_array[s];
|
SOCKET fd = src->fd_array[s];
|
||||||
|
|
||||||
if (!func || (*func)(fd)) { /* move it to dst */
|
if (!func || (*func)(fd)) {
|
||||||
|
if (dst) { /* move it to dst */
|
||||||
unsigned int d;
|
unsigned int d;
|
||||||
|
|
||||||
for (d = 0; d < dst->fdset->fd_count; d++) {
|
for (d = 0; d < dst->fdset->fd_count; d++) {
|
||||||
@ -2415,10 +2417,15 @@ extract_fd(rb_fdset_t *dst, fd_set *src, int (*func)(SOCKET))
|
|||||||
&src->fd_array[s+1],
|
&src->fd_array[s+1],
|
||||||
sizeof(src->fd_array[0]) * (--src->fd_count - s));
|
sizeof(src->fd_array[0]) * (--src->fd_count - s));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
m++;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
}
|
||||||
else s++;
|
else s++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return dst->fdset->fd_count;
|
return dst ? dst->fdset->fd_count : m;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2514,6 +2521,12 @@ is_readable_console(SOCKET sock) /* call this for console only */
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
is_invalid_handle(SOCKET sock)
|
||||||
|
{
|
||||||
|
return (HANDLE)sock == INVALID_HANDLE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
do_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
||||||
struct timeval *timeout)
|
struct timeval *timeout)
|
||||||
@ -2625,15 +2638,24 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
|||||||
rb_fd_init(&else_rd);
|
rb_fd_init(&else_rd);
|
||||||
nonsock += extract_fd(&else_rd, rd, is_not_socket);
|
nonsock += extract_fd(&else_rd, rd, is_not_socket);
|
||||||
|
|
||||||
|
rb_fd_init(&else_wr);
|
||||||
|
nonsock += extract_fd(&else_wr, wr, is_not_socket);
|
||||||
|
|
||||||
|
// check invalid handles
|
||||||
|
if (extract_fd(NULL, else_rd.fdset, is_invalid_handle) > 0 ||
|
||||||
|
extract_fd(NULL, else_wr.fdset, is_invalid_handle) > 0) {
|
||||||
|
rb_fd_term(&else_wr);
|
||||||
|
rb_fd_term(&else_rd);
|
||||||
|
errno = EBADF;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
rb_fd_init(&pipe_rd);
|
rb_fd_init(&pipe_rd);
|
||||||
extract_fd(&pipe_rd, else_rd.fdset, is_pipe); // should not call is_pipe for socket
|
extract_fd(&pipe_rd, else_rd.fdset, is_pipe); // should not call is_pipe for socket
|
||||||
|
|
||||||
rb_fd_init(&cons_rd);
|
rb_fd_init(&cons_rd);
|
||||||
extract_fd(&cons_rd, else_rd.fdset, is_console); // ditto
|
extract_fd(&cons_rd, else_rd.fdset, is_console); // ditto
|
||||||
|
|
||||||
rb_fd_init(&else_wr);
|
|
||||||
nonsock += extract_fd(&else_wr, wr, is_not_socket);
|
|
||||||
|
|
||||||
rb_fd_init(&except);
|
rb_fd_init(&except);
|
||||||
extract_fd(&except, ex, is_not_socket); // drop only
|
extract_fd(&except, ex, is_not_socket); // drop only
|
||||||
|
|
||||||
@ -2694,9 +2716,9 @@ rb_w32_select(int nfds, fd_set *rd, fd_set *wr, fd_set *ex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
rb_fd_term(&except);
|
rb_fd_term(&except);
|
||||||
rb_fd_term(&else_wr);
|
|
||||||
rb_fd_term(&cons_rd);
|
rb_fd_term(&cons_rd);
|
||||||
rb_fd_term(&pipe_rd);
|
rb_fd_term(&pipe_rd);
|
||||||
|
rb_fd_term(&else_wr);
|
||||||
rb_fd_term(&else_rd);
|
rb_fd_term(&else_rd);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user