Project

General

Profile

Backport #6352 » fix_em_segv.patch

h.shirosaki (Hiroshi Shirosaki), 04/25/2012 11:23 PM

View differences:

include/ruby/win32.h
#define O_NONBLOCK 1
#undef FD_SET
#define FD_SET(f, s) rb_w32_fdset(f, s)
#define FD_SET(fd, set) do {\
unsigned int i;\
SOCKET s = _get_osfhandle(fd);\
\
for (i = 0; i < (set)->fd_count; i++) {\
if ((set)->fd_array[i] == s) {\
break;\
}\
}\
if (i == (set)->fd_count) {\
if ((set)->fd_count < FD_SETSIZE) {\
(set)->fd_array[i] = s;\
(set)->fd_count++;\
}\
}\
} while(0)
#undef FD_CLR
#define FD_CLR(f, s) rb_w32_fdclr(f, s)
win32/win32.c
return -1;
}
#undef FD_SET
void
rb_w32_fdset(int fd, fd_set *set)
{
unsigned int i;
SOCKET s = TO_SOCKET(fd);
for (i = 0; i < set->fd_count; i++) {
if (set->fd_array[i] == s) {
return;
}
}
if (i == set->fd_count) {
if (set->fd_count < FD_SETSIZE) {
set->fd_array[i] = s;
set->fd_count++;
}
}
FD_SET(fd, set);
}
#undef FD_CLR
......
if (dst->fd_array[d] == fd)
break;
}
if (d == dst->fd_count && d < FD_SETSIZE) {
if (d == dst->fd_count &&
d < (sizeof(dst->fd_array) / sizeof(dst->fd_array[0]))) {
dst->fd_array[dst->fd_count++] = fd;
}
}
......
fd_set orig_rd;
fd_set orig_wr;
fd_set orig_ex;
if (rd) orig_rd = *rd;
if (wr) orig_wr = *wr;
if (ex) orig_ex = *ex;
FD_ZERO(&orig_rd);
FD_ZERO(&orig_wr);
FD_ZERO(&orig_ex);
if (rd) copy_fd(&orig_rd, rd);
if (wr) copy_fd(&orig_wr, wr);
if (ex) copy_fd(&orig_ex, ex);
r = do_select(nfds, rd, wr, ex, &zero); // polling
if (r != 0) break; // signaled or error
if (rd) *rd = orig_rd;
if (wr) *wr = orig_wr;
if (ex) *ex = orig_ex;
if (rd) copy_fd(rd, &orig_rd);
if (wr) copy_fd(wr, &orig_wr);
if (ex) copy_fd(ex, &orig_ex);
if (timeout) {
struct timeval now;
(2-2/3)