Ruby 1.9.3p327(2012-11-10revision37606)
ext/-test-/win32/fd_setsize/fd_setsize.c
Go to the documentation of this file.
00001 #undef FD_SETSIZE
00002 /* redefine smaller size then default 64 */
00003 #define FD_SETSIZE 32
00004 #include <ruby.h>
00005 
00006 static VALUE
00007 test_select(VALUE self)
00008 {
00009     int sd = socket(AF_INET, SOCK_DGRAM, 0);
00010     struct timeval zero;
00011     fd_set read;
00012     fd_set write;
00013     fd_set error;
00014 
00015     zero.tv_sec = 0;
00016     zero.tv_usec = 0;
00017 
00018     FD_ZERO(&read);
00019     FD_ZERO(&write);
00020     FD_ZERO(&error);
00021 
00022     FD_SET(sd, &read);
00023     FD_SET(sd, &write);
00024     FD_SET(sd, &error);
00025 
00026     select(sd+1, &read, &write, &error, &zero);
00027 
00028     return Qtrue;
00029 }
00030 
00031 static VALUE
00032 test_fdset(VALUE self)
00033 {
00034     int i;
00035     fd_set set;
00036 
00037     FD_ZERO(&set);
00038 
00039     for (i = 0; i < FD_SETSIZE * 2; i++) {
00040         int sd = socket(AF_INET, SOCK_DGRAM, 0);
00041         FD_SET(sd, &set);
00042         if (set.fd_count > FD_SETSIZE) {
00043             return Qfalse;
00044         }
00045     }
00046     return Qtrue;
00047 }
00048 
00049 void
00050 Init_fd_setsize(void)
00051 {
00052     VALUE m = rb_define_module_under(rb_define_module("Bug"), "Win32");
00053     rb_define_module_function(m, "test_select", test_select, 0);
00054     rb_define_module_function(m, "test_fdset", test_fdset, 0);
00055 }
00056