cool.io 1.4.6-x64-mingw32 → 1.5.3-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -211,7 +211,7 @@ struct ev_loop;
211
211
  /*****************************************************************************/
212
212
 
213
213
  #define EV_VERSION_MAJOR 4
214
- #define EV_VERSION_MINOR 20
214
+ #define EV_VERSION_MINOR 24
215
215
 
216
216
  /* eventmask, revents, events... */
217
217
  enum {
@@ -515,10 +515,10 @@ enum {
515
515
 
516
516
  /* method bits to be ored together */
517
517
  enum {
518
- EVBACKEND_SELECT = 0x00000001U, /* about anywhere */
519
- EVBACKEND_POLL = 0x00000002U, /* !win */
518
+ EVBACKEND_SELECT = 0x00000001U, /* available just about anywhere */
519
+ EVBACKEND_POLL = 0x00000002U, /* !win, !aix, broken on osx */
520
520
  EVBACKEND_EPOLL = 0x00000004U, /* linux */
521
- EVBACKEND_KQUEUE = 0x00000008U, /* bsd */
521
+ EVBACKEND_KQUEUE = 0x00000008U, /* bsd, broken on osx */
522
522
  EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */
523
523
  EVBACKEND_PORT = 0x00000020U, /* solaris 10 */
524
524
  EVBACKEND_ALL = 0x0000003FU, /* all known backends */
@@ -851,3 +851,4 @@ EV_API_DECL void ev_async_send (EV_P_ ev_async *w) EV_THROW;
851
851
  EV_CPP(})
852
852
 
853
853
  #endif
854
+
@@ -179,7 +179,7 @@ epoll_poll (EV_P_ ev_tstamp timeout)
179
179
  if (expect_false ((uint32_t)anfds [fd].egen != (uint32_t)(ev->data.u64 >> 32)))
180
180
  {
181
181
  /* recreate kernel state */
182
- postfork = 1;
182
+ postfork |= 2;
183
183
  continue;
184
184
  }
185
185
 
@@ -203,7 +203,7 @@ epoll_poll (EV_P_ ev_tstamp timeout)
203
203
  /* which is fortunately easy to do for us. */
204
204
  if (epoll_ctl (backend_fd, want ? EPOLL_CTL_MOD : EPOLL_CTL_DEL, fd, ev))
205
205
  {
206
- postfork = 1; /* an error occurred, recreate kernel state */
206
+ postfork |= 2; /* an error occurred, recreate kernel state */
207
207
  continue;
208
208
  }
209
209
  }
@@ -235,7 +235,8 @@ epoll_poll (EV_P_ ev_tstamp timeout)
235
235
  }
236
236
  }
237
237
 
238
- int inline_size
238
+ inline_size
239
+ int
239
240
  epoll_init (EV_P_ int flags)
240
241
  {
241
242
  #ifdef EPOLL_CLOEXEC
@@ -260,14 +261,16 @@ epoll_init (EV_P_ int flags)
260
261
  return EVBACKEND_EPOLL;
261
262
  }
262
263
 
263
- void inline_size
264
+ inline_size
265
+ void
264
266
  epoll_destroy (EV_P)
265
267
  {
266
268
  ev_free (epoll_events);
267
269
  array_free (epoll_eperm, EMPTY);
268
270
  }
269
271
 
270
- void inline_size
272
+ inline_size
273
+ void
271
274
  epoll_fork (EV_P)
272
275
  {
273
276
  close (backend_fd);
@@ -43,7 +43,8 @@
43
43
  #include <string.h>
44
44
  #include <errno.h>
45
45
 
46
- void inline_speed
46
+ inline_speed
47
+ void
47
48
  kqueue_change (EV_P_ int fd, int filter, int flags, int fflags)
48
49
  {
49
50
  ++kqueue_changecnt;
@@ -152,7 +153,8 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
152
153
  }
153
154
  }
154
155
 
155
- int inline_size
156
+ inline_size
157
+ int
156
158
  kqueue_init (EV_P_ int flags)
157
159
  {
158
160
  /* initialize the kernel queue */
@@ -176,14 +178,16 @@ kqueue_init (EV_P_ int flags)
176
178
  return EVBACKEND_KQUEUE;
177
179
  }
178
180
 
179
- void inline_size
181
+ inline_size
182
+ void
180
183
  kqueue_destroy (EV_P)
181
184
  {
182
185
  ev_free (kqueue_events);
183
186
  ev_free (kqueue_changes);
184
187
  }
185
188
 
186
- void inline_size
189
+ inline_size
190
+ void
187
191
  kqueue_fork (EV_P)
188
192
  {
189
193
  /* some BSD kernels don't just destroy the kqueue itself,
@@ -39,7 +39,8 @@
39
39
 
40
40
  #include <poll.h>
41
41
 
42
- void inline_size
42
+ inline_size
43
+ void
43
44
  pollidx_init (int *base, int count)
44
45
  {
45
46
  /* consider using memset (.., -1, ...), which is practically guaranteed
@@ -126,7 +127,8 @@ poll_poll (EV_P_ ev_tstamp timeout)
126
127
  }
127
128
  }
128
129
 
129
- int inline_size
130
+ inline_size
131
+ int
130
132
  poll_init (EV_P_ int flags)
131
133
  {
132
134
  backend_mintime = 1e-3;
@@ -139,7 +141,8 @@ poll_init (EV_P_ int flags)
139
141
  return EVBACKEND_POLL;
140
142
  }
141
143
 
142
- void inline_size
144
+ inline_size
145
+ void
143
146
  poll_destroy (EV_P)
144
147
  {
145
148
  ev_free (pollidxs);
@@ -55,7 +55,8 @@
55
55
  #include <string.h>
56
56
  #include <errno.h>
57
57
 
58
- void inline_speed
58
+ inline_speed
59
+ void
59
60
  port_associate_and_check (EV_P_ int fd, int ev)
60
61
  {
61
62
  if (0 >
@@ -136,7 +137,8 @@ port_poll (EV_P_ ev_tstamp timeout)
136
137
  }
137
138
  }
138
139
 
139
- int inline_size
140
+ inline_size
141
+ int
140
142
  port_init (EV_P_ int flags)
141
143
  {
142
144
  /* Initialize the kernel queue */
@@ -163,13 +165,15 @@ port_init (EV_P_ int flags)
163
165
  return EVBACKEND_PORT;
164
166
  }
165
167
 
166
- void inline_size
168
+ inline_size
169
+ void
167
170
  port_destroy (EV_P)
168
171
  {
169
172
  ev_free (port_events);
170
173
  }
171
174
 
172
- void inline_size
175
+ inline_size
176
+ void
173
177
  port_fork (EV_P)
174
178
  {
175
179
  close (backend_fd);
@@ -319,7 +319,8 @@ select_poll (EV_P_ ev_tstamp timeout)
319
319
  #endif
320
320
  }
321
321
 
322
- int inline_size
322
+ inline_size
323
+ int
323
324
  select_init (EV_P_ int flags)
324
325
  {
325
326
  backend_mintime = 1e-6;
@@ -348,7 +349,8 @@ select_init (EV_P_ int flags)
348
349
  return EVBACKEND_SELECT;
349
350
  }
350
351
 
351
- void inline_size
352
+ inline_size
353
+ void
352
354
  select_destroy (EV_P)
353
355
  {
354
356
  ev_free (vec_ri);
@@ -39,9 +39,6 @@
39
39
 
40
40
  #ifdef _WIN32
41
41
 
42
- /* timeb.h is actually xsi legacy functionality */
43
- #include <sys/timeb.h>
44
-
45
42
  /* note: the comment below could not be substantiated, but what would I care */
46
43
  /* MSDN says this is required to handle SIGFPE */
47
44
  /* my wild guess would be that using something floating-pointy is required */
@@ -91,6 +88,8 @@ ev_pipe (int filedes [2])
91
88
  if (connect (sock [0], (struct sockaddr *)&addr, addr_size))
92
89
  goto fail;
93
90
 
91
+ /* TODO: returns INVALID_SOCKET on winsock accept, not < 0. fix it */
92
+ /* when convenient, probably by just removing error checking altogether? */
94
93
  if ((sock [1] = accept (listener, 0, 0)) < 0)
95
94
  goto fail;
96
95
 
@@ -137,6 +137,8 @@ module Coolio
137
137
 
138
138
  private :preinitialize
139
139
 
140
+ PEERADDR_FAILED = ["?", 0, "name resolusion failed", "?"]
141
+
140
142
  def initialize(socket)
141
143
  unless socket.is_a?(::TCPSocket) or socket.is_a?(TCPConnectSocket)
142
144
  raise TypeError, "socket must be a TCPSocket"
@@ -144,7 +146,7 @@ module Coolio
144
146
 
145
147
  super
146
148
 
147
- @address_family, @remote_port, @remote_host, @remote_addr = socket.peeraddr
149
+ @address_family, @remote_port, @remote_host, @remote_addr = (socket.peeraddr rescue PEERADDR_FAILED)
148
150
  end
149
151
 
150
152
  def peeraddr
@@ -1,5 +1,5 @@
1
1
  module Coolio
2
- VERSION = "1.4.6"
2
+ VERSION = "1.5.3"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -0,0 +1,175 @@
1
+ diff --git a/ext/libev/ev.c b/ext/libev/ev.c
2
+ index 39b9faf..dae87f1 100644
3
+ --- a/ext/libev/ev.c
4
+ +++ b/ext/libev/ev.c
5
+ @@ -37,6 +37,10 @@
6
+ * either the BSD or the GPL.
7
+ */
8
+
9
+ +/* ########## COOLIO PATCHERY HO! ########## */
10
+ +#include "ruby.h"
11
+ +/* ######################################## */
12
+ +
13
+ /* this big block deduces configuration from config.h */
14
+ #ifndef EV_STANDALONE
15
+ # ifdef EV_CONFIG_H
16
+ @@ -107,7 +111,7 @@
17
+ # undef EV_USE_POLL
18
+ # define EV_USE_POLL 0
19
+ # endif
20
+ -
21
+ +
22
+ # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H
23
+ # ifndef EV_USE_EPOLL
24
+ # define EV_USE_EPOLL EV_FEATURE_BACKENDS
25
+ @@ -116,7 +120,7 @@
26
+ # undef EV_USE_EPOLL
27
+ # define EV_USE_EPOLL 0
28
+ # endif
29
+ -
30
+ +
31
+ # if HAVE_KQUEUE && HAVE_SYS_EVENT_H
32
+ # ifndef EV_USE_KQUEUE
33
+ # define EV_USE_KQUEUE EV_FEATURE_BACKENDS
34
+ @@ -125,7 +129,7 @@
35
+ # undef EV_USE_KQUEUE
36
+ # define EV_USE_KQUEUE 0
37
+ # endif
38
+ -
39
+ +
40
+ # if HAVE_PORT_H && HAVE_PORT_CREATE
41
+ # ifndef EV_USE_PORT
42
+ # define EV_USE_PORT EV_FEATURE_BACKENDS
43
+ @@ -161,7 +165,7 @@
44
+ # undef EV_USE_EVENTFD
45
+ # define EV_USE_EVENTFD 0
46
+ # endif
47
+ -
48
+ +
49
+ #endif
50
+
51
+ #include <stdlib.h>
52
+ @@ -2174,7 +2178,7 @@ downheap (ANHE *heap, int N, int k)
53
+
54
+ heap [k] = heap [c];
55
+ ev_active (ANHE_w (heap [k])) = k;
56
+ -
57
+ +
58
+ k = c;
59
+ }
60
+
61
+ @@ -2594,7 +2598,7 @@ ev_supported_backends (void) EV_THROW
62
+ if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
63
+ if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
64
+ if (EV_USE_SELECT) flags |= EVBACKEND_SELECT;
65
+ -
66
+ +
67
+ return flags;
68
+ }
69
+
70
+ @@ -3398,9 +3402,33 @@ time_update (EV_P_ ev_tstamp max_block)
71
+ }
72
+ }
73
+
74
+ +/* ########## COOLIO PATCHERY HO! ########## */
75
+ +#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
76
+ +struct ev_poll_args {
77
+ + struct ev_loop *loop;
78
+ + ev_tstamp waittime;
79
+ +};
80
+ +
81
+ +static
82
+ +VALUE ev_backend_poll(void *ptr)
83
+ +{
84
+ + struct ev_poll_args *args = (struct ev_poll_args *)ptr;
85
+ + struct ev_loop *loop = args->loop;
86
+ + backend_poll (EV_A_ args->waittime);
87
+ + return Qnil;
88
+ +}
89
+ +#endif
90
+ +/* ######################################## */
91
+ +
92
+ int
93
+ ev_run (EV_P_ int flags)
94
+ {
95
+ +/* ########## COOLIO PATCHERY HO! ########## */
96
+ +#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
97
+ + struct ev_poll_args poll_args;
98
+ +#endif
99
+ +/* ######################################## */
100
+ +
101
+ #if EV_FEATURE_API
102
+ ++loop_depth;
103
+ #endif
104
+ @@ -3518,7 +3546,70 @@ ev_run (EV_P_ int flags)
105
+ ++loop_count;
106
+ #endif
107
+ assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */
108
+ - backend_poll (EV_A_ waittime);
109
+ +
110
+ +/*
111
+ +########################## COOLIO PATCHERY HO! ##########################
112
+ +
113
+ +According to the grandwizards of Ruby, locking and unlocking of the global
114
+ +interpreter lock are apparently too powerful a concept for a mere mortal to
115
+ +wield (although redefining what + and - do to numbers is totally cool).
116
+ +And so it came to pass that the only acceptable way to release the global
117
+ +interpreter lock is through a convoluted callback system that thakes a
118
+ +function pointer. While the grandwizard of libev foresaw this sort of scenario,
119
+ +he too attempted to place an API with callbacks on it, one that runs before
120
+ +the system call, and one that runs immediately after.
121
+ +
122
+ +And so it came to pass that trying to wrap everything up in callbacks created
123
+ +two incompatible APIs, Ruby's which releases the global interpreter lock and
124
+ +reacquires it when the callback returns, and libev's, which wants two
125
+ +callbacks, one which runs before the polling operation starts, and one which
126
+ +runs after it finishes.
127
+ +
128
+ +These two systems are incompatible as they both want to use callbacks to
129
+ +solve the same problem, however libev wants to use before/after callbacks,
130
+ +and Ruby wants to use an "around" callback. This presents a significant
131
+ +problem as these two patterns of callbacks are diametrical opposites of each
132
+ +other and thus cannot be composed.
133
+ +
134
+ +And thus we are left with no choice but to patch the internals of libev in
135
+ +order to release a mutex at just the precise moment.
136
+ +
137
+ +This is a great example of a situation where granular locking and unlocking
138
+ +of the GVL is practically required. The goal is to get as close to the
139
+ +system call as possible, and to keep the GVL unlocked for the shortest
140
+ +amount of time possible.
141
+ +
142
+ +Perhaps Ruby could benefit from such an API, e.g:
143
+ +
144
+ +rb_thread_unsafe_dangerous_crazy_blocking_region_begin(...);
145
+ +rb_thread_unsafe_dangerous_crazy_blocking_region_end(...);
146
+ +
147
+ +#######################################################################
148
+ +*/
149
+ +
150
+ +/*
151
+ + simulate to rb_thread_call_without_gvl using rb_theread_blocking_region.
152
+ + https://github.com/brianmario/mysql2/blob/master/ext/mysql2/client.h#L8
153
+ +*/
154
+ +
155
+ +#ifndef HAVE_RB_THREAD_CALL_WITHOUT_GVL
156
+ +#ifdef HAVE_RB_THREAD_BLOCKING_REGION
157
+ +#define rb_thread_call_without_gvl(func, data1, ubf, data2) \
158
+ + rb_thread_blocking_region((rb_blocking_function_t *)func, data1, ubf, data2)
159
+ +#endif
160
+ +#endif
161
+ +
162
+ +#if defined(HAVE_RB_THREAD_BLOCKING_REGION) || defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
163
+ + poll_args.loop = loop;
164
+ + poll_args.waittime = waittime;
165
+ + rb_thread_call_without_gvl(ev_backend_poll, (void *)&poll_args, RUBY_UBF_IO, 0);
166
+ +#else
167
+ + backend_poll (EV_A_ waittime);
168
+ +#endif
169
+ +/*
170
+ +############################# END PATCHERY ############################
171
+ +*/
172
+ +
173
+ assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
174
+
175
+ pipe_write_wanted = 0; /* just an optimisation, no fence needed */
@@ -1,8 +1,20 @@
1
+ diff --git a/ext/libev/ev.c b/ext/libev/ev.c
2
+ index dae87f1..d15f6bd 100644
3
+ --- a/ext/libev/ev.c
4
+ +++ b/ext/libev/ev.c
5
+ @@ -207,6 +207,7 @@
6
+ #else
7
+ # include <io.h>
8
+ # define WIN32_LEAN_AND_MEAN
9
+ +# define FD_SETSIZE 1024
10
+ # include <winsock2.h>
11
+ # include <windows.h>
12
+ # ifndef EV_SELECT_IS_WINSOCKET
1
13
  diff --git a/ext/libev/ev_select.c b/ext/libev/ev_select.c
2
- index f38d6ca..3a32642 100644
14
+ index f38d6ca..7050778 100644
3
15
  --- a/ext/libev/ev_select.c
4
16
  +++ b/ext/libev/ev_select.c
5
- @@ -67,6 +67,53 @@
17
+ @@ -67,6 +67,54 @@
6
18
 
7
19
  #include <string.h>
8
20
 
@@ -45,6 +57,7 @@ index f38d6ca..3a32642 100644
45
57
  +} while(0)
46
58
  +#define EV_WIN_FD_ZERO(set) (((fd_set *)(set))->fd_count=0)
47
59
  +#define EV_WIN_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set))
60
+ +#define EV_WIN_FD_COUNT(set) (((fd_set *)(set))->fd_count)
48
61
  +/* ######################################## */
49
62
  +#else
50
63
  +#define EV_WIN_FD_CLR FD_CLR
@@ -56,7 +69,7 @@ index f38d6ca..3a32642 100644
56
69
  static void
57
70
  select_modify (EV_P_ int fd, int oev, int nev)
58
71
  {
59
- @@ -91,17 +138,17 @@ select_modify (EV_P_ int fd, int oev, int nev)
72
+ @@ -91,17 +139,17 @@ select_modify (EV_P_ int fd, int oev, int nev)
60
73
  if ((oev ^ nev) & EV_READ)
61
74
  #endif
62
75
  if (nev & EV_READ)
@@ -78,16 +91,18 @@ index f38d6ca..3a32642 100644
78
91
 
79
92
  #else
80
93
 
81
- @@ -136,6 +183,8 @@ select_modify (EV_P_ int fd, int oev, int nev)
82
- }
83
- }
94
+ @@ -197,8 +245,8 @@ select_poll (EV_P_ ev_tstamp timeout)
95
+ {
96
+ if (timeout)
97
+ {
98
+ - unsigned long ms = timeout * 1e3;
99
+ - Sleep (ms ? ms : 1);
100
+ + unsigned long ms = (unsigned long)(timeout * 1e3);
101
+ + SleepEx (ms ? ms : 1, TRUE);
102
+ }
84
103
 
85
- +#undef socket
86
- +
87
- static void
88
- select_poll (EV_P_ ev_tstamp timeout)
89
- {
90
- @@ -230,10 +279,10 @@ select_poll (EV_P_ ev_tstamp timeout)
104
+ return;
105
+ @@ -230,10 +278,10 @@ select_poll (EV_P_ ev_tstamp timeout)
91
106
  int handle = fd;
92
107
  #endif
93
108
 
@@ -101,7 +116,7 @@ index f38d6ca..3a32642 100644
101
116
  #endif
102
117
 
103
118
  if (expect_true (events))
104
- @@ -279,9 +328,9 @@ select_init (EV_P_ int flags)
119
+ @@ -279,9 +327,9 @@ select_init (EV_P_ int flags)
105
120
  backend_poll = select_poll;
106
121
 
107
122
  #if EV_SELECT_USE_FD_SET