cool.io 1.2.3-x86-mingw32 → 1.4.1-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.travis.yml +3 -3
- data/CHANGES.md +35 -0
- data/README.md +1 -3
- data/Rakefile +11 -13
- data/cool.io.gemspec +3 -2
- data/examples/callbacked_echo_server.rb +24 -0
- data/ext/cool.io/extconf.rb +8 -24
- data/ext/cool.io/loop.c +1 -1
- data/ext/iobuffer/iobuffer.c +2 -0
- data/ext/libev/Changes +123 -4
- data/ext/libev/LICENSE +2 -1
- data/ext/libev/README +8 -8
- data/ext/libev/ev.c +313 -144
- data/ext/libev/ev.h +18 -10
- data/ext/libev/ev_epoll.c +4 -1
- data/ext/libev/ev_kqueue.c +1 -1
- data/ext/libev/ev_select.c +3 -4
- data/ext/libev/ev_vars.h +3 -2
- data/ext/libev/ev_win32.c +1 -1
- data/ext/libev/win_select.patch +115 -0
- data/lib/cool.io.rb +6 -4
- data/lib/cool.io/dns_resolver.rb +4 -10
- data/lib/cool.io/dsl.rb +6 -2
- data/lib/cool.io/io.rb +36 -16
- data/lib/cool.io/loop.rb +3 -11
- data/lib/cool.io/meta.rb +2 -2
- data/lib/cool.io/version.rb +4 -2
- data/spec/async_watcher_spec.rb +5 -5
- data/spec/dns_spec.rb +11 -7
- data/spec/iobuffer_spec.rb +147 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/stat_watcher_spec.rb +3 -3
- data/spec/tcp_server_spec.rb +98 -5
- data/spec/tcp_socket_spec.rb +185 -0
- data/spec/timer_watcher_spec.rb +23 -19
- data/spec/udp_socket_spec.rb +58 -0
- data/spec/unix_listener_spec.rb +7 -7
- data/spec/unix_server_spec.rb +7 -7
- metadata +83 -103
- data/examples/httpclient.rb +0 -38
- data/ext/http11_client/.gitignore +0 -5
- data/ext/http11_client/LICENSE +0 -31
- data/ext/http11_client/ext_help.h +0 -14
- data/ext/http11_client/extconf.rb +0 -6
- data/ext/http11_client/http11_client.c +0 -300
- data/ext/http11_client/http11_parser.c +0 -403
- data/ext/http11_client/http11_parser.h +0 -48
- data/ext/http11_client/http11_parser.rl +0 -173
- data/lib/cool.io/eventmachine.rb +0 -234
- data/lib/cool.io/http_client.rb +0 -427
data/ext/libev/ev.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* libev native API header
|
3
3
|
*
|
4
|
-
* Copyright (c) 2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann <libev@schmorp.de>
|
4
|
+
* Copyright (c) 2007,2008,2009,2010,2011,2012,2015 Marc Alexander Lehmann <libev@schmorp.de>
|
5
5
|
* All rights reserved.
|
6
6
|
*
|
7
7
|
* Redistribution and use in source and binary forms, with or without modifica-
|
@@ -42,12 +42,16 @@
|
|
42
42
|
|
43
43
|
#ifdef __cplusplus
|
44
44
|
# define EV_CPP(x) x
|
45
|
+
# if __cplusplus >= 201103L
|
46
|
+
# define EV_THROW noexcept
|
47
|
+
# else
|
48
|
+
# define EV_THROW throw ()
|
49
|
+
# endif
|
45
50
|
#else
|
46
51
|
# define EV_CPP(x)
|
52
|
+
# define EV_THROW
|
47
53
|
#endif
|
48
54
|
|
49
|
-
#define EV_THROW EV_CPP(throw())
|
50
|
-
|
51
55
|
EV_CPP(extern "C" {)
|
52
56
|
|
53
57
|
/*****************************************************************************/
|
@@ -148,6 +152,8 @@ EV_CPP(extern "C" {)
|
|
148
152
|
|
149
153
|
typedef double ev_tstamp;
|
150
154
|
|
155
|
+
#include <string.h> /* for memmove */
|
156
|
+
|
151
157
|
#ifndef EV_ATOMIC_T
|
152
158
|
# include <signal.h>
|
153
159
|
# define EV_ATOMIC_T sig_atomic_t volatile
|
@@ -205,7 +211,7 @@ struct ev_loop;
|
|
205
211
|
/*****************************************************************************/
|
206
212
|
|
207
213
|
#define EV_VERSION_MAJOR 4
|
208
|
-
#define EV_VERSION_MINOR
|
214
|
+
#define EV_VERSION_MINOR 20
|
209
215
|
|
210
216
|
/* eventmask, revents, events... */
|
211
217
|
enum {
|
@@ -658,8 +664,10 @@ EV_API_DECL void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_T
|
|
658
664
|
/* advanced stuff for threading etc. support, see docs */
|
659
665
|
EV_API_DECL void ev_set_userdata (EV_P_ void *data) EV_THROW;
|
660
666
|
EV_API_DECL void *ev_userdata (EV_P) EV_THROW;
|
661
|
-
|
662
|
-
EV_API_DECL void
|
667
|
+
typedef void (*ev_loop_callback)(EV_P);
|
668
|
+
EV_API_DECL void ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW;
|
669
|
+
/* C++ doesn't allow the use of the ev_loop_callback typedef here, so we need to spell it out */
|
670
|
+
EV_API_DECL void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW;
|
663
671
|
|
664
672
|
EV_API_DECL unsigned int ev_pending_count (EV_P) EV_THROW; /* number of pending events, if any */
|
665
673
|
EV_API_DECL void ev_invoke_pending (EV_P); /* invoke all pending watchers */
|
@@ -713,7 +721,8 @@ EV_API_DECL void ev_resume (EV_P) EV_THROW;
|
|
713
721
|
#define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */
|
714
722
|
#define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */
|
715
723
|
|
716
|
-
#define
|
724
|
+
#define ev_cb_(ev) (ev)->cb /* rw */
|
725
|
+
#define ev_cb(ev) (memmove (&ev_cb_ (ev), &((ev_watcher *)(ev))->cb, sizeof (ev_cb_ (ev))), (ev)->cb)
|
717
726
|
|
718
727
|
#if EV_MINPRI == EV_MAXPRI
|
719
728
|
# define ev_priority(ev) ((ev), EV_MINPRI)
|
@@ -726,11 +735,11 @@ EV_API_DECL void ev_resume (EV_P) EV_THROW;
|
|
726
735
|
#define ev_periodic_at(ev) (+((ev_watcher_time *)(ev))->at)
|
727
736
|
|
728
737
|
#ifndef ev_set_cb
|
729
|
-
# define ev_set_cb(ev,cb_)
|
738
|
+
# define ev_set_cb(ev,cb_) (ev_cb_ (ev) = (cb_), memmove (&((ev_watcher *)(ev))->cb, &ev_cb_ (ev), sizeof (ev_cb_ (ev))))
|
730
739
|
#endif
|
731
740
|
|
732
741
|
/* stopping (enabling, adding) a watcher does nothing if it is already running */
|
733
|
-
/* stopping (disabling, deleting) a watcher does nothing unless
|
742
|
+
/* stopping (disabling, deleting) a watcher does nothing unless it's already running */
|
734
743
|
#if EV_PROTOTYPES
|
735
744
|
|
736
745
|
/* feeds an event into a watcher as if the event actually occurred */
|
@@ -842,4 +851,3 @@ EV_API_DECL void ev_async_send (EV_P_ ev_async *w) EV_THROW;
|
|
842
851
|
EV_CPP(})
|
843
852
|
|
844
853
|
#endif
|
845
|
-
|
data/ext/libev/ev_epoll.c
CHANGED
@@ -228,7 +228,10 @@ epoll_poll (EV_P_ ev_tstamp timeout)
|
|
228
228
|
if (anfds [fd].emask & EV_EMASK_EPERM && events)
|
229
229
|
fd_event (EV_A_ fd, events);
|
230
230
|
else
|
231
|
-
|
231
|
+
{
|
232
|
+
epoll_eperms [i] = epoll_eperms [--epoll_epermcnt];
|
233
|
+
anfds [fd].emask = 0;
|
234
|
+
}
|
232
235
|
}
|
233
236
|
}
|
234
237
|
|
data/ext/libev/ev_kqueue.c
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* libev kqueue backend
|
3
3
|
*
|
4
|
-
* Copyright (c) 2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann <libev@schmorp.de>
|
4
|
+
* Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de>
|
5
5
|
* All rights reserved.
|
6
6
|
*
|
7
7
|
* Redistribution and use in source and binary forms, with or without modifica-
|
data/ext/libev/ev_select.c
CHANGED
@@ -106,6 +106,7 @@ if (__i == ((fd_set *)(set))->fd_count) {\
|
|
106
106
|
} while(0)
|
107
107
|
#define EV_WIN_FD_ZERO(set) (((fd_set *)(set))->fd_count=0)
|
108
108
|
#define EV_WIN_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set))
|
109
|
+
#define EV_WIN_FD_COUNT(set) (((fd_set *)(set))->fd_count)
|
109
110
|
/* ######################################## */
|
110
111
|
#else
|
111
112
|
#define EV_WIN_FD_CLR FD_CLR
|
@@ -183,8 +184,6 @@ select_modify (EV_P_ int fd, int oev, int nev)
|
|
183
184
|
}
|
184
185
|
}
|
185
186
|
|
186
|
-
#undef socket
|
187
|
-
|
188
187
|
static void
|
189
188
|
select_poll (EV_P_ ev_tstamp timeout)
|
190
189
|
{
|
@@ -246,8 +245,8 @@ select_poll (EV_P_ ev_tstamp timeout)
|
|
246
245
|
{
|
247
246
|
if (timeout)
|
248
247
|
{
|
249
|
-
unsigned long ms = timeout * 1e3;
|
250
|
-
|
248
|
+
unsigned long ms = (unsigned long)(timeout * 1e3);
|
249
|
+
SleepEx (ms ? ms : 1, TRUE);
|
251
250
|
}
|
252
251
|
|
253
252
|
return;
|
data/ext/libev/ev_vars.h
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
/*
|
2
2
|
* loop member variable declarations
|
3
3
|
*
|
4
|
-
* Copyright (c) 2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann <libev@schmorp.de>
|
4
|
+
* Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de>
|
5
5
|
* All rights reserved.
|
6
6
|
*
|
7
7
|
* Redistribution and use in source and binary forms, with or without modifica-
|
@@ -194,9 +194,10 @@ VARx(unsigned int, loop_count) /* total number of loop iterations/blocks */
|
|
194
194
|
VARx(unsigned int, loop_depth) /* #ev_run enters - #ev_run leaves */
|
195
195
|
|
196
196
|
VARx(void *, userdata)
|
197
|
+
/* C++ doesn't support the ev_loop_callback typedef here. stinks. */
|
197
198
|
VAR (release_cb, void (*release_cb)(EV_P) EV_THROW)
|
198
199
|
VAR (acquire_cb, void (*acquire_cb)(EV_P) EV_THROW)
|
199
|
-
VAR (invoke_cb ,
|
200
|
+
VAR (invoke_cb , ev_loop_callback invoke_cb)
|
200
201
|
#endif
|
201
202
|
|
202
203
|
#undef VARx
|
data/ext/libev/ev_win32.c
CHANGED
@@ -0,0 +1,115 @@
|
|
1
|
+
diff --git a/ext/libev/ev_select.c b/ext/libev/ev_select.c
|
2
|
+
index f38d6ca..3a32642 100644
|
3
|
+
--- a/ext/libev/ev_select.c
|
4
|
+
+++ b/ext/libev/ev_select.c
|
5
|
+
@@ -67,6 +67,53 @@
|
6
|
+
|
7
|
+
#include <string.h>
|
8
|
+
|
9
|
+
+#ifdef _WIN32
|
10
|
+
+/*
|
11
|
+
+########## COOLIO PATCHERY HO! ##########
|
12
|
+
+
|
13
|
+
+Ruby undefs FD_* utilities for own implementation.
|
14
|
+
+It converts fd argument into socket handle internally on Windows,
|
15
|
+
+so libev should not use Ruby's FD_* utilities.
|
16
|
+
+
|
17
|
+
+Following FD_* utilities come from MinGW.
|
18
|
+
+RubyInstaller is built by MinGW so this should work.
|
19
|
+
+*/
|
20
|
+
+int PASCAL __WSAFDIsSet(SOCKET,fd_set*);
|
21
|
+
+#define EV_WIN_FD_CLR(fd,set) do { u_int __i;\
|
22
|
+
+for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) {\
|
23
|
+
+ if (((fd_set *)(set))->fd_array[__i] == (fd)) {\
|
24
|
+
+ while (__i < ((fd_set *)(set))->fd_count-1) {\
|
25
|
+
+ ((fd_set*)(set))->fd_array[__i] = ((fd_set*)(set))->fd_array[__i+1];\
|
26
|
+
+ __i++;\
|
27
|
+
+ }\
|
28
|
+
+ ((fd_set*)(set))->fd_count--;\
|
29
|
+
+ break;\
|
30
|
+
+ }\
|
31
|
+
+}\
|
32
|
+
+} while (0)
|
33
|
+
+#define EV_WIN_FD_SET(fd, set) do { u_int __i;\
|
34
|
+
+for (__i = 0; __i < ((fd_set *)(set))->fd_count ; __i++) {\
|
35
|
+
+ if (((fd_set *)(set))->fd_array[__i] == (fd)) {\
|
36
|
+
+ break;\
|
37
|
+
+ }\
|
38
|
+
+}\
|
39
|
+
+if (__i == ((fd_set *)(set))->fd_count) {\
|
40
|
+
+ if (((fd_set *)(set))->fd_count < FD_SETSIZE) {\
|
41
|
+
+ ((fd_set *)(set))->fd_array[__i] = (fd);\
|
42
|
+
+ ((fd_set *)(set))->fd_count++;\
|
43
|
+
+ }\
|
44
|
+
+}\
|
45
|
+
+} while(0)
|
46
|
+
+#define EV_WIN_FD_ZERO(set) (((fd_set *)(set))->fd_count=0)
|
47
|
+
+#define EV_WIN_FD_ISSET(fd, set) __WSAFDIsSet((SOCKET)(fd), (fd_set *)(set))
|
48
|
+
+/* ######################################## */
|
49
|
+
+#else
|
50
|
+
+#define EV_WIN_FD_CLR FD_CLR
|
51
|
+
+#define EV_WIN_FD_SET FD_SET
|
52
|
+
+#define EV_WIN_FD_ZERO FD_ZERO
|
53
|
+
+#define EV_WIN_FD_ISSET FD_ISSET
|
54
|
+
+#endif
|
55
|
+
+
|
56
|
+
static void
|
57
|
+
select_modify (EV_P_ int fd, int oev, int nev)
|
58
|
+
{
|
59
|
+
@@ -91,17 +138,17 @@ select_modify (EV_P_ int fd, int oev, int nev)
|
60
|
+
if ((oev ^ nev) & EV_READ)
|
61
|
+
#endif
|
62
|
+
if (nev & EV_READ)
|
63
|
+
- FD_SET (handle, (fd_set *)vec_ri);
|
64
|
+
+ EV_WIN_FD_SET (handle, (fd_set *)vec_ri);
|
65
|
+
else
|
66
|
+
- FD_CLR (handle, (fd_set *)vec_ri);
|
67
|
+
+ EV_WIN_FD_CLR (handle, (fd_set *)vec_ri);
|
68
|
+
|
69
|
+
#if EV_SELECT_IS_WINSOCKET
|
70
|
+
if ((oev ^ nev) & EV_WRITE)
|
71
|
+
#endif
|
72
|
+
if (nev & EV_WRITE)
|
73
|
+
- FD_SET (handle, (fd_set *)vec_wi);
|
74
|
+
+ EV_WIN_FD_SET (handle, (fd_set *)vec_wi);
|
75
|
+
else
|
76
|
+
- FD_CLR (handle, (fd_set *)vec_wi);
|
77
|
+
+ EV_WIN_FD_CLR (handle, (fd_set *)vec_wi);
|
78
|
+
|
79
|
+
#else
|
80
|
+
|
81
|
+
@@ -136,6 +183,8 @@ select_modify (EV_P_ int fd, int oev, int nev)
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
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)
|
91
|
+
int handle = fd;
|
92
|
+
#endif
|
93
|
+
|
94
|
+
- if (FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ;
|
95
|
+
- if (FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE;
|
96
|
+
+ if (EV_WIN_FD_ISSET (handle, (fd_set *)vec_ro)) events |= EV_READ;
|
97
|
+
+ if (EV_WIN_FD_ISSET (handle, (fd_set *)vec_wo)) events |= EV_WRITE;
|
98
|
+
#ifdef _WIN32
|
99
|
+
- if (FD_ISSET (handle, (fd_set *)vec_eo)) events |= EV_WRITE;
|
100
|
+
+ if (EV_WIN_FD_ISSET (handle, (fd_set *)vec_eo)) events |= EV_WRITE;
|
101
|
+
#endif
|
102
|
+
|
103
|
+
if (expect_true (events))
|
104
|
+
@@ -279,9 +328,9 @@ select_init (EV_P_ int flags)
|
105
|
+
backend_poll = select_poll;
|
106
|
+
|
107
|
+
#if EV_SELECT_USE_FD_SET
|
108
|
+
- vec_ri = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_ri);
|
109
|
+
+ vec_ri = ev_malloc (sizeof (fd_set)); EV_WIN_FD_ZERO ((fd_set *)vec_ri);
|
110
|
+
vec_ro = ev_malloc (sizeof (fd_set));
|
111
|
+
- vec_wi = ev_malloc (sizeof (fd_set)); FD_ZERO ((fd_set *)vec_wi);
|
112
|
+
+ vec_wi = ev_malloc (sizeof (fd_set)); EV_WIN_FD_ZERO ((fd_set *)vec_wi);
|
113
|
+
vec_wo = ev_malloc (sizeof (fd_set));
|
114
|
+
#ifdef _WIN32
|
115
|
+
vec_eo = ev_malloc (sizeof (fd_set));
|
data/lib/cool.io.rb
CHANGED
@@ -19,14 +19,16 @@ require "cool.io/listener"
|
|
19
19
|
require "cool.io/dns_resolver"
|
20
20
|
require "cool.io/socket"
|
21
21
|
require "cool.io/server"
|
22
|
-
require "cool.io/http_client"
|
23
|
-
require "cool.io/dsl"
|
24
22
|
|
25
23
|
module Coolio
|
26
|
-
def self.inspect
|
24
|
+
def self.inspect
|
25
|
+
"Cool.io"
|
26
|
+
end
|
27
27
|
end
|
28
28
|
|
29
29
|
module Cool
|
30
30
|
# Allow Coolio module to be referenced as Cool.io
|
31
|
-
def self.io
|
31
|
+
def self.io
|
32
|
+
Coolio
|
33
|
+
end
|
32
34
|
end
|
data/lib/cool.io/dns_resolver.rb
CHANGED
@@ -17,6 +17,8 @@
|
|
17
17
|
#
|
18
18
|
#++
|
19
19
|
|
20
|
+
require 'resolv'
|
21
|
+
|
20
22
|
module Coolio
|
21
23
|
# A non-blocking DNS resolver. It provides interfaces for querying both
|
22
24
|
# /etc/hosts and nameserves listed in /etc/resolv.conf, or nameservers of
|
@@ -31,12 +33,6 @@ module Coolio
|
|
31
33
|
# again.
|
32
34
|
class DNSResolver < IOWatcher
|
33
35
|
#--
|
34
|
-
# TODO check if it's caching right
|
35
|
-
if RUBY_PLATFORM =~ /mingw|win32/
|
36
|
-
HOSTS = 'c:\WINDOWS\system32\drivers\etc\hosts'
|
37
|
-
else
|
38
|
-
HOSTS = '/etc/hosts'
|
39
|
-
end
|
40
36
|
DNS_PORT = 53
|
41
37
|
DATAGRAM_SIZE = 512
|
42
38
|
TIMEOUT = 3 # Retry timeout for each datagram sent
|
@@ -44,7 +40,7 @@ module Coolio
|
|
44
40
|
# so currently total is 12s before it will err due to timeouts
|
45
41
|
# if it errs due to inability to reach the DNS server [Errno::EHOSTUNREACH], same
|
46
42
|
# Query /etc/hosts (or the specified hostfile) for the given host
|
47
|
-
def self.hosts(host, hostfile =
|
43
|
+
def self.hosts(host, hostfile = Resolv::Hosts::DefaultFileName)
|
48
44
|
hosts = {}
|
49
45
|
File.open(hostfile) do |f|
|
50
46
|
f.each_line do |host_entry|
|
@@ -63,7 +59,6 @@ module Coolio
|
|
63
59
|
# use nameservers listed in /etc/resolv.conf
|
64
60
|
def initialize(hostname, *nameservers)
|
65
61
|
if nameservers.empty?
|
66
|
-
require 'resolv'
|
67
62
|
nameservers = Resolv::DNS::Config.default_config_hash[:nameserver]
|
68
63
|
raise RuntimeError, "no nameservers found" if nameservers.empty? # TODO just call resolve_failed, not raise [also handle Errno::ENOENT)]
|
69
64
|
end
|
@@ -111,9 +106,8 @@ module Coolio
|
|
111
106
|
def send_request
|
112
107
|
nameserver = @nameservers.shift
|
113
108
|
@nameservers << nameserver # rotate them
|
114
|
-
@socket.connect @nameservers.first, DNS_PORT
|
115
109
|
begin
|
116
|
-
@socket.send request_message, 0
|
110
|
+
@socket.send request_message, 0, @nameservers.first, DNS_PORT
|
117
111
|
rescue Errno::EHOSTUNREACH # TODO figure out why it has to be wrapper here, when the other wrapper should be wrapping this one!
|
118
112
|
end
|
119
113
|
end
|
data/lib/cool.io/dsl.rb
CHANGED
@@ -124,11 +124,15 @@ end
|
|
124
124
|
# The Cool module containing all our coolness
|
125
125
|
module Cool
|
126
126
|
module Coolness
|
127
|
-
def cool
|
127
|
+
def cool
|
128
|
+
Cool::IOThunk
|
129
|
+
end
|
128
130
|
end
|
129
131
|
|
130
132
|
module IOThunk
|
131
|
-
def self.io
|
133
|
+
def self.io
|
134
|
+
Coolio::DSL
|
135
|
+
end
|
132
136
|
end
|
133
137
|
end
|
134
138
|
|
data/lib/cool.io/io.rb
CHANGED
@@ -31,25 +31,45 @@ module Coolio
|
|
31
31
|
#
|
32
32
|
|
33
33
|
# Attach to the event loop
|
34
|
-
def attach(loop)
|
34
|
+
def attach(loop)
|
35
|
+
@_read_watcher.attach(loop)
|
36
|
+
schedule_write if !@_write_buffer.empty?
|
37
|
+
self
|
38
|
+
end
|
35
39
|
|
36
40
|
# Detach from the event loop
|
37
|
-
def detach
|
41
|
+
def detach
|
42
|
+
# TODO should these detect write buffers, as well?
|
43
|
+
@_read_watcher.detach
|
44
|
+
self
|
45
|
+
end
|
38
46
|
|
39
47
|
# Enable the watcher
|
40
|
-
def enable
|
48
|
+
def enable
|
49
|
+
@_read_watcher.enable
|
50
|
+
self
|
51
|
+
end
|
41
52
|
|
42
53
|
# Disable the watcher
|
43
|
-
def disable
|
54
|
+
def disable
|
55
|
+
@_read_watcher.disable
|
56
|
+
self
|
57
|
+
end
|
44
58
|
|
45
59
|
# Is the watcher attached?
|
46
|
-
def attached
|
60
|
+
def attached?
|
61
|
+
@_read_watcher.attached?
|
62
|
+
end
|
47
63
|
|
48
64
|
# Is the watcher enabled?
|
49
|
-
def enabled
|
65
|
+
def enabled?
|
66
|
+
@_read_watcher.enabled?
|
67
|
+
end
|
50
68
|
|
51
69
|
# Obtain the event loop associated with this object
|
52
|
-
def evloop
|
70
|
+
def evloop
|
71
|
+
@_read_watcher.evloop
|
72
|
+
end
|
53
73
|
|
54
74
|
#
|
55
75
|
# Callbacks for asynchronous events
|
@@ -78,16 +98,11 @@ module Coolio
|
|
78
98
|
data.size
|
79
99
|
end
|
80
100
|
|
81
|
-
# Number of bytes are currently in the output buffer
|
82
|
-
def output_buffer_size
|
83
|
-
@_write_buffer.size
|
84
|
-
end
|
85
|
-
|
86
101
|
# Close the IO stream
|
87
102
|
def close
|
88
103
|
detach if attached?
|
89
104
|
detach_write_watcher
|
90
|
-
@_io.close unless
|
105
|
+
@_io.close unless closed?
|
91
106
|
|
92
107
|
on_close
|
93
108
|
nil
|
@@ -136,7 +151,7 @@ module Coolio
|
|
136
151
|
# Schedule a write to be performed when the IO object becomes writable
|
137
152
|
def schedule_write
|
138
153
|
return unless @_io # this would mean 'we are still pre DNS here'
|
139
|
-
return unless attached? # this would mean 'currently unattached' -- ie still pre DNS, or just plain not attached, which is ok
|
154
|
+
return unless @_read_watcher.attached? # this would mean 'currently unattached' -- ie still pre DNS, or just plain not attached, which is ok
|
140
155
|
begin
|
141
156
|
enable_write_watcher
|
142
157
|
rescue IOError
|
@@ -167,8 +182,13 @@ module Coolio
|
|
167
182
|
end
|
168
183
|
|
169
184
|
# Configure IOWatcher event callbacks to call the method passed to #initialize
|
170
|
-
def on_readable
|
171
|
-
|
185
|
+
def on_readable
|
186
|
+
@coolio_io.__send__(:on_readable)
|
187
|
+
end
|
188
|
+
|
189
|
+
def on_writable
|
190
|
+
@coolio_io.__send__(:on_writable)
|
191
|
+
end
|
172
192
|
end
|
173
193
|
end
|
174
194
|
end
|