summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-13 07:52:22 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-13 07:52:22 +0000
commit50258b19fd449048eaf22e88eec873d86c8719bf (patch)
treea0e228314395d920d53314d4d0724bab017c753a /thread.c
parente41bd61822076275c337258ef53566ea18b70f87 (diff)
* 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/trunk@21487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/thread.c b/thread.c
index f27c4d6a65..522be77ac2 100644
--- a/thread.c
+++ b/thread.c
@@ -2244,6 +2244,52 @@ rb_fd_select(int n, rb_fdset_t *readfds, rb_fdset_t *writefds, rb_fdset_t *excep
#define FD_CLR(i, f) rb_fd_clr(i, f)
#define FD_ISSET(i, f) rb_fd_isset(i, f)
+#elif defined(_WIN32)
+
+void
+rb_fd_init(volatile rb_fdset_t *set)
+{
+ set->capa = FD_SETSIZE;
+ set->fdset = ALLOC(fd_set);
+ FD_ZERO(set->fdset);
+}
+
+void
+rb_fd_term(rb_fdset_t *set)
+{
+ xfree(set->fdset);
+ set->fdset = NULL;
+ set->capa = 0;
+}
+
+void
+rb_fd_set(int fd, rb_fdset_t *set)
+{
+ unsigned int i;
+ SOCKET s = rb_w32_get_osfhandle(fd);
+
+ for (i = 0; i < set->fdset->fd_count; i++) {
+ if (set->fdset->fd_array[i] == s) {
+ return;
+ }
+ }
+ if (set->fdset->fd_count >= set->capa) {
+ set->capa = (set->fdset->fd_count / FD_SETSIZE + 1) * FD_SETSIZE;
+ set->fdset = xrealloc(set->fdset, sizeof(unsigned int) + sizeof(SOCKET) * set->capa);
+ }
+ set->fdset->fd_array[set->fdset->fd_count++] = s;
+}
+
+#undef FD_ZERO
+#undef FD_SET
+#undef FD_CLR
+#undef FD_ISSET
+
+#define FD_ZERO(f) rb_fd_zero(f)
+#define FD_SET(i, f) rb_fd_set(i, f)
+#define FD_CLR(i, f) rb_fd_clr(i, f)
+#define FD_ISSET(i, f) rb_fd_isset(i, f)
+
#endif
#if defined(__CYGWIN__) || defined(_WIN32)