Backport #6352 » fd_macros.diff
include/ruby/win32.h (working copy) | ||
---|---|---|
#define O_NONBLOCK 1
|
||
#undef FD_SET
|
||
#define FD_SET(f, s) rb_w32_fdset(f, s)
|
||
#define FD_SET(f, s) rb_w32_fdset_internal(f, s)
|
||
static inline void
|
||
rb_w32_fdset_internal(int fd, fd_set *set)
|
||
{
|
||
unsigned int i;
|
||
SOCKET s = rb_w32_get_osfhandle(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++;
|
||
}
|
||
}
|
||
}
|
||
#undef FD_CLR
|
||
#define FD_CLR(f, s) rb_w32_fdclr(f, s)
|
||
#define FD_CLR(f, s) rb_w32_fdclr_internal(f, s)
|
||
static inline void
|
||
rb_w32_fdclr_internal(int fd, fd_set *set)
|
||
{
|
||
unsigned int i;
|
||
SOCKET s = rb_w32_get_osfhandle(fd);
|
||
for (i = 0; i < set->fd_count; i++) {
|
||
if (set->fd_array[i] == s) {
|
||
memmove(&set->fd_array[i], &set->fd_array[i+1],
|
||
sizeof(set->fd_array[0]) * (--set->fd_count - i));
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
#undef FD_ISSET
|
||
#define FD_ISSET(f, s) rb_w32_fdisset(f, s)
|
||
#define FD_ISSET(f, s) rb_w32_fdisset_internal(f, s)
|
||
static inline int
|
||
rb_w32_fdisset_internal(int fd, fd_set *set)
|
||
{
|
||
int ret;
|
||
SOCKET s = rb_w32_get_osfhandle(fd);
|
||
if (s == (SOCKET)INVALID_HANDLE_VALUE)
|
||
return 0;
|
||
return __WSAFDIsSet(s, set);
|
||
}
|
||
#ifdef RUBY_EXPORT
|
||
#undef inet_ntop
|
win32/win32.c (working copy) | ||
---|---|---|
return -1;
|
||
}
|
||
#undef FD_SET
|
||
/* for backward compatibility */
|
||
/* License: Ruby's */
|
||
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++;
|
||
}
|
||
}
|
||
rb_w32_fdset_internal(fd, set);
|
||
}
|
||
#undef FD_CLR
|
||
/* License: Ruby's */
|
||
void
|
||
rb_w32_fdclr(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) {
|
||
memmove(&set->fd_array[i], &set->fd_array[i+1],
|
||
sizeof(set->fd_array[0]) * (--set->fd_count - i));
|
||
break;
|
||
}
|
||
}
|
||
rb_w32_fdclr_internal(fd, set);
|
||
}
|
||
#undef FD_ISSET
|
||
/* License: Ruby's */
|
||
int
|
||
rb_w32_fdisset(int fd, fd_set *set)
|
||
{
|
||
int ret;
|
||
SOCKET s = TO_SOCKET(fd);
|
||
if (s == (SOCKET)INVALID_HANDLE_VALUE)
|
||
return 0;
|
||
RUBY_CRITICAL(ret = __WSAFDIsSet(s, set));
|
||
return ret;
|
||
return rb_w32_fdisset_internal(fd, set);
|
||
}
|
||
/* License: Ruby's */
|
||
void
|
||
rb_w32_fd_copy(rb_fdset_t *dst, const fd_set *src, int max)
|