rev 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/CHANGES +11 -0
  2. data/README +10 -3
  3. data/Rakefile +2 -2
  4. data/examples/echo_client.rb +35 -0
  5. data/examples/google.rb +8 -0
  6. data/examples/httpclient.rb +35 -0
  7. data/ext/http11_client/Makefile +149 -0
  8. data/ext/http11_client/http11_client.bundle +0 -0
  9. data/ext/http11_client/http11_client.o +0 -0
  10. data/ext/http11_client/http11_parser.o +0 -0
  11. data/ext/http11_client/mkmf.log +12 -0
  12. data/ext/libev/Changes +114 -1
  13. data/ext/libev/ev.c +212 -97
  14. data/ext/libev/ev.h +13 -7
  15. data/ext/libev/ev_epoll.c +44 -11
  16. data/ext/libev/ev_kqueue.c +2 -2
  17. data/ext/libev/ev_poll.c +3 -1
  18. data/ext/libev/ev_port.c +4 -4
  19. data/ext/libev/ev_select.c +58 -19
  20. data/ext/libev/ev_vars.h +5 -1
  21. data/ext/libev/ev_win32.c +32 -3
  22. data/ext/libev/ev_wrap.h +4 -0
  23. data/ext/libev/test_libev_win32.c +123 -0
  24. data/ext/libev/update_ev_wrap +0 -0
  25. data/ext/rev/Makefile +149 -0
  26. data/ext/rev/ev_wrap.h +8 -0
  27. data/ext/rev/extconf.rb +17 -0
  28. data/ext/rev/libev.c +8 -0
  29. data/ext/rev/libev.o +0 -0
  30. data/ext/rev/mkmf.log +221 -0
  31. data/ext/rev/rev.h +8 -2
  32. data/ext/rev/rev_buffer.c +2 -3
  33. data/ext/rev/rev_buffer.o +0 -0
  34. data/ext/rev/rev_ext.bundle +0 -0
  35. data/ext/rev/rev_ext.c +4 -3
  36. data/ext/rev/rev_ext.o +0 -0
  37. data/ext/rev/rev_io_watcher.c +1 -2
  38. data/ext/rev/rev_io_watcher.o +0 -0
  39. data/ext/rev/rev_loop.c +4 -4
  40. data/ext/rev/rev_loop.o +0 -0
  41. data/ext/rev/rev_ssl.o +0 -0
  42. data/ext/rev/rev_timer_watcher.c +1 -2
  43. data/ext/rev/rev_timer_watcher.o +0 -0
  44. data/ext/rev/rev_utils.c +14 -0
  45. data/ext/rev/rev_utils.o +0 -0
  46. data/ext/rev/rev_watcher.c +7 -6
  47. data/ext/rev/rev_watcher.o +0 -0
  48. data/lib/http11_client.bundle +0 -0
  49. data/lib/rev.rb +1 -1
  50. data/lib/rev/dns_resolver.rb +29 -9
  51. data/lib/rev/io.rb +6 -4
  52. data/lib/rev/listener.rb +5 -1
  53. data/lib/rev/loop.rb +8 -4
  54. data/lib/rev/server.rb +3 -2
  55. data/lib/rev/socket.rb +14 -5
  56. data/lib/rev_ext.bundle +0 -0
  57. data/lib/revem.rb +210 -0
  58. data/rev.gemspec +2 -2
  59. metadata +29 -3
data/CHANGES CHANGED
@@ -1,3 +1,14 @@
1
+ 0.2.3:
2
+
3
+ * Initial Windows support
4
+
5
+ * Initial Ruby 1.8.7 and 1.9.1 support
6
+
7
+ * Upgrade to libev 3.52
8
+
9
+ * Add checks for sys/resource.h and don't allow getting/setting maxfds if it
10
+ isn't present
11
+
1
12
  0.2.2:
2
13
 
3
14
  * Correct a pointer arithmetic error in the buffering code that could result
data/README CHANGED
@@ -18,10 +18,16 @@ For more information, consult the RubyForge page:
18
18
 
19
19
  http://rev.rubyforge.org
20
20
 
21
+ http://rubyforge.org/projects/rev
22
+
21
23
  Questions? Sign up for the mailing list at:
22
24
 
23
25
  http://rubyforge.org/mailman/listinfo/rev-talk
24
26
 
27
+ The latest development code is available via github at:
28
+
29
+ git://github.com/tarcieri/rev.git
30
+
25
31
  == Anatomy
26
32
 
27
33
  Rev builds on two core classes which bind to the libev API:
@@ -88,6 +94,7 @@ core socket classes are also provided. Among these are:
88
94
 
89
95
  Below is an example of how to write an echo server:
90
96
 
97
+ require 'rev'
91
98
  HOST = 'localhost'
92
99
  PORT = 4321
93
100
 
@@ -105,7 +112,7 @@ Below is an example of how to write an echo server:
105
112
  end
106
113
  end
107
114
 
108
- server = Rev::TCPServer.new('localhost', PORT, EchoServerConnection)
115
+ server = Rev::TCPServer.new(HOST, PORT, EchoServerConnection)
109
116
  server.attach(Rev::Loop.default)
110
117
 
111
118
  puts "Echo server listening on #{HOST}:#{PORT}"
@@ -129,7 +136,7 @@ haven't overridden them in a subclass). This is especially useful for small
129
136
  one off programs or just experimenting with the API.
130
137
 
131
138
  Any callback (methods prefixed with on_*) can be set on the fly by passing it
132
- a block. (NOTE: Ruby 1.9 only)
139
+ a block. (NOTE: Ruby 1.9/1.8.7 only)
133
140
 
134
141
  Below is an example of using this syntax. It implements an echo server
135
142
  identical to the one above:
@@ -137,7 +144,7 @@ identical to the one above:
137
144
  HOST = '127.0.0.1'
138
145
  PORT = 4321
139
146
 
140
- server = Rev::TCPServer.new(ADDR, PORT) do |c|
147
+ server = Rev::TCPServer.new(HOST, PORT) do |c|
141
148
  c.on_connect { puts "#{remote_addr}:#{remote_port} connected" }
142
149
  c.on_close { puts "#{remote_addr}:#{remote_port} disconnected" }
143
150
  c.on_read { |data| write data }
data/Rakefile CHANGED
@@ -76,5 +76,5 @@ setup_extension("http11_client", "http11_client")
76
76
 
77
77
  task :compile => [:rev_ext, :http11_client]
78
78
 
79
- CLEAN.include ['build/*', '**/*.o', '**/*.so', '**/*.a', '**/*.log', 'pkg']
80
- CLEAN.include ['ext/rev/Makefile', 'lib/rev_ext.*', 'lib/http11_client.*']
79
+ CLEAN.include ["build/*", "**/*.o", "**/*.so", "**/*.a", "**/*.log", "pkg"]
80
+ CLEAN.include ["ext/**/Makefile", "lib/rev_ext.*", "lib/http11_client.*", "ext/**/*.#{Config::CONFIG["DLEXT"]}"]
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../lib/rev'
2
+
3
+ ADDR = '127.0.0.1'
4
+ PORT = 4321
5
+
6
+ class ClientConnection < Rev::TCPSocket
7
+ def on_connect
8
+ puts "#{remote_addr}:#{remote_port} connected"
9
+ write "bounce this back to me"
10
+ end
11
+
12
+ def on_close
13
+ puts "#{remote_addr}:#{remote_port} disconnected"
14
+ end
15
+
16
+ def on_read(data)
17
+ print "got #{data}"
18
+ close
19
+ end
20
+
21
+ def on_resolve_failed
22
+ print "DNS resolve failed"
23
+ end
24
+
25
+ def on_connect_failed
26
+ print "connect failed, meaning our connection to their port was rejected"
27
+ end
28
+
29
+ end
30
+
31
+ event_loop = Rev::Loop.default
32
+ client = ClientConnection.connect(ADDR, PORT)
33
+ client.attach(event_loop)
34
+ puts "Echo client connecting to #{ADDR}:#{PORT}..."
35
+ event_loop.run
@@ -0,0 +1,8 @@
1
+ #require 'rubygems'
2
+ #require 'rev'
3
+ require File.dirname(__FILE__) + '/../lib/rev'
4
+
5
+ l = Rev::Loop.default
6
+ c = Rev::HttpClient.connect("www.google.com", 80).attach(l)
7
+ c.request('GET', '/search', :query => { :q => 'feces'})
8
+ l.run
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/../lib/rev'
2
+
3
+ class MyHttpClient < Rev::HttpClient
4
+ def on_connect
5
+ super
6
+ STDERR.puts "Connected to #{remote_host}:#{remote_port}"
7
+ end
8
+
9
+ def on_connect_failed
10
+ super
11
+ STDERR.puts "Connection failed"
12
+ end
13
+
14
+ def on_response_header(header)
15
+ STDERR.puts "Response: #{header.http_version} #{header.status} #{header.http_reason}"
16
+ end
17
+
18
+ def on_body_data(data)
19
+ STDOUT.write data
20
+ STDOUT.flush
21
+ end
22
+
23
+ def on_request_complete
24
+ STDERR.puts "Request complete!"
25
+ end
26
+
27
+ def on_error(reason)
28
+ STDERR.puts "Error: #{reason}"
29
+ end
30
+ end
31
+
32
+ l = Rev::Loop.default
33
+ c = MyHttpClient.connect("www.google.com", 80).attach(l)
34
+ c.request('GET', '/search', :query => { :q => 'foobar' })
35
+ l.run
@@ -0,0 +1,149 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir):$(topdir):$(hdrdir)
10
+ prefix = $(DESTDIR)/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr
11
+ exec_prefix = $(prefix)
12
+ sitedir = $(DESTDIR)/Library/Ruby/Site
13
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
14
+ docdir = $(datarootdir)/doc/$(PACKAGE)
15
+ dvidir = $(docdir)
16
+ datarootdir = $(prefix)/share
17
+ archdir = $(rubylibdir)/$(arch)
18
+ sbindir = $(exec_prefix)/sbin
19
+ psdir = $(docdir)
20
+ localedir = $(datarootdir)/locale
21
+ htmldir = $(docdir)
22
+ datadir = $(datarootdir)
23
+ includedir = $(prefix)/include
24
+ infodir = $(DESTDIR)/usr/share/info
25
+ sysconfdir = $(prefix)/etc
26
+ mandir = $(DESTDIR)/usr/share/man
27
+ libdir = $(exec_prefix)/lib
28
+ sharedstatedir = $(prefix)/com
29
+ oldincludedir = $(DESTDIR)/usr/include
30
+ pdfdir = $(docdir)
31
+ sitearchdir = $(sitelibdir)/$(sitearch)
32
+ bindir = $(exec_prefix)/bin
33
+ localstatedir = $(prefix)/var
34
+ sitelibdir = $(sitedir)/$(ruby_version)
35
+ libexecdir = $(exec_prefix)/libexec
36
+
37
+ CC = gcc
38
+ LIBRUBY = $(LIBRUBY_SO)
39
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
40
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
41
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)
42
+
43
+ RUBY_EXTCONF_H =
44
+ CFLAGS = -fno-common -arch ppc -arch i386 -Os -pipe -fno-common
45
+ INCFLAGS = -I. -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I.
46
+ CPPFLAGS =
47
+ CXXFLAGS = $(CFLAGS)
48
+ DLDFLAGS = -L. -arch ppc -arch i386
49
+ LDSHARED = cc -arch ppc -arch i386 -pipe -bundle -undefined dynamic_lookup
50
+ AR = ar
51
+ EXEEXT =
52
+
53
+ RUBY_INSTALL_NAME = ruby
54
+ RUBY_SO_NAME = ruby
55
+ arch = universal-darwin9.0
56
+ sitearch = universal-darwin9.0
57
+ ruby_version = 1.8
58
+ ruby = /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
59
+ RUBY = $(ruby)
60
+ RM = rm -f
61
+ MAKEDIRS = mkdir -p
62
+ INSTALL = /usr/bin/install -c
63
+ INSTALL_PROG = $(INSTALL) -m 0755
64
+ INSTALL_DATA = $(INSTALL) -m 644
65
+ COPY = cp
66
+
67
+ #### End of system configuration section. ####
68
+
69
+ preload =
70
+
71
+ libpath = . $(libdir)
72
+ LIBPATH = -L"." -L"$(libdir)"
73
+ DEFFILE =
74
+
75
+ CLEANFILES = mkmf.log
76
+ DISTCLEANFILES =
77
+
78
+ extout =
79
+ extout_prefix =
80
+ target_prefix =
81
+ LOCAL_LIBS =
82
+ LIBS = $(LIBRUBYARG_SHARED) -lc -lpthread -ldl -lm
83
+ SRCS = http11_client.c http11_parser.c
84
+ OBJS = http11_client.o http11_parser.o
85
+ TARGET = http11_client
86
+ DLLIB = $(TARGET).bundle
87
+ EXTSTATIC =
88
+ STATIC_LIB =
89
+
90
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
91
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
92
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
93
+
94
+ TARGET_SO = $(DLLIB)
95
+ CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
96
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
97
+
98
+ all: $(DLLIB)
99
+ static: $(STATIC_LIB)
100
+
101
+ clean:
102
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
103
+
104
+ distclean: clean
105
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
106
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
107
+
108
+ realclean: distclean
109
+ install: install-so install-rb
110
+
111
+ install-so: $(RUBYARCHDIR)
112
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
113
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
114
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
115
+ install-rb: pre-install-rb install-rb-default
116
+ install-rb-default: pre-install-rb-default
117
+ pre-install-rb: Makefile
118
+ pre-install-rb-default: Makefile
119
+ $(RUBYARCHDIR):
120
+ $(MAKEDIRS) $@
121
+
122
+ site-install: site-install-so site-install-rb
123
+ site-install-so: install-so
124
+ site-install-rb: install-rb
125
+
126
+ .SUFFIXES: .c .m .cc .cxx .cpp .C .o
127
+
128
+ .cc.o:
129
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
130
+
131
+ .cxx.o:
132
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
133
+
134
+ .cpp.o:
135
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
136
+
137
+ .C.o:
138
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
139
+
140
+ .c.o:
141
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
142
+
143
+ $(DLLIB): $(OBJS)
144
+ @-$(RM) $@
145
+ $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
146
+
147
+
148
+
149
+ $(OBJS): ruby.h defines.h
@@ -0,0 +1,12 @@
1
+ have_library: checking for main() in -lc... -------------------- yes
2
+
3
+ "gcc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I. -arch ppc -arch i386 -Os -pipe -fno-common conftest.c -L"." -L"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib" -L. -arch ppc -arch i386 -lruby -lc -lpthread -ldl -lm "
4
+ checked program was:
5
+ /* begin */
6
+ 1: /*top*/
7
+ 2: int main() { return 0; }
8
+ 3: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
9
+ /* end */
10
+
11
+ --------------------
12
+
@@ -1,7 +1,120 @@
1
1
  Revision history for libev, a high-performance and full-featured event loop.
2
2
 
3
+ 3.52 Wed Jan 7 21:43:02 CET 2009
4
+ - fix compilation of select backend in fd_set mode when NFDBITS is
5
+ missing (to get it to compile on QNX, reported by Rodrigo Campos).
6
+ - better select-nfds handling when select backend is in fd_set mode.
7
+ - diagnose fd_set overruns when select backend is in fd_set mode.
8
+ - due to a thinko, instead of disabling everything but
9
+ select on the borked OS X platform, everything but select was
10
+ allowed (reported by Emanuele Giaquinta).
11
+ - actually verify that local and remote port are matching in
12
+ libev's socketpair emulation, which makes denial-of-service
13
+ attacks harder (but not impossible - it's windows). Make sure
14
+ it even works under vista, which thinks that getpeer/sockname
15
+ should return fantasy port numbers.
16
+ - include "libev" all assertion messages for potentially
17
+ clearer diagnostics.
18
+ - event_get_version (libevent compatibility) returned
19
+ a useless string instead of the expected version string
20
+ (patch by W.C.A. Wijngaards).
21
+
22
+ 3.51 Wed Dec 24 23:00:11 CET 2008
23
+ - fix a bug where an inotify watcher was added twice, causing
24
+ freezes on hash collisions (reported and analysed by Graham Leggett).
25
+ - new config symbol, EV_USE_CLOCK_SYSCALL, to make libev use
26
+ a direct syscall - slower, but no dependency on librt et al.
27
+ - assume negative return values != -1 signals success of port_getn
28
+ (http://cvs.epicsol.org/cgi/viewcvs.cgi/epic5/source/newio.c?rev=1.52)
29
+ (no known failure reports, but it doesn't hurt).
30
+ - fork detection in ev_embed now stops and restarts the watcher
31
+ automatically.
32
+ - EXPERIMENTAL: default the method to operator () in ev++.h,
33
+ to make it nicer to use functors (requested by Benedek László).
34
+ - fixed const object callbacks in ev++.h.
35
+ - replaced loop_ref argument of watcher.set (loop) by a direct
36
+ ev_loop * in ev++.h, to avoid clashes with functor patch.
37
+ - do not try to watch the empty string via inotify.
38
+ - inotify watchers could be leaked under certain circumstances.
39
+ - OS X 10.5 is actually even more broken than earlier versions,
40
+ so fall back to select on that piece of garbage.
41
+ - fixed some weirdness in the ev_embed documentation.
42
+
43
+ 3.49 Wed Nov 19 11:26:53 CET 2008
44
+ - ev_stat watchers will now use inotify as a mere hint on
45
+ kernels <2.6.25, or if the filesystem is not in the
46
+ "known to be good" list.
47
+ - better mingw32 compatibility (it's not as borked as native win32)
48
+ (analysed by Roger Pack).
49
+ - include stdio.h in the example program, as too many people are
50
+ confused by the weird C language otherwise. I guess the next thing
51
+ I get told is that the "..." ellipses in the examples don't compile
52
+ with their C compiler.
53
+
54
+ 3.48 Thu Oct 30 09:02:37 CET 2008
55
+ - further optimise away the EPOLL_CTL_ADD/MOD combo in the epoll
56
+ backend by assuming the kernel event mask hasn't changed if
57
+ ADD fails with EEXIST.
58
+ - work around spurious event notification bugs in epoll by using
59
+ a 32-bit generation counter. recreate kernel state if we receive
60
+ spurious notifications or unwanted events. this is very costly,
61
+ but I didn't come up with this horrible design.
62
+ - use memset to initialise most arrays now and do away with the
63
+ init functions.
64
+ - expand time-out strategies into a "Be smart about timeouts" section.
65
+ - drop the "struct" from all ev_watcher declarations in the
66
+ documentation and did other clarifications (yeah, it was a mistake
67
+ to have a struct AND a function called ev_loop).
68
+ - fix a bug where ev_default would not initialise the default
69
+ loop again after it was destroyed with ev_default_destroy.
70
+ - rename syserr to ev_syserr to avoid name clashes when embedding,
71
+ do similar changes for event.c.
72
+
73
+ 3.45 Tue Oct 21 21:59:26 CEST 2008
74
+ - disable inotify usage on linux <2.6.25, as it is broken
75
+ (reported by Yoann Vandoorselaere).
76
+ - ev_stat errornously would try to add inotify watchers
77
+ even when inotify wasn't available (this should only
78
+ have a performance impact).
79
+ - ev_once now passes both timeout and io to the callback if both
80
+ occur concurrently, instead of giving timeouts precedence.
81
+ - disable EV_USE_INOTIFY when sys/inotify.h is too old.
82
+
83
+ 3.44 Mon Sep 29 05:18:39 CEST 2008
84
+ - embed watchers now automatically invoke ev_loop_fork on the
85
+ embedded loop when the parent loop forks.
86
+ - new function: ev_now_update (loop).
87
+ - verify_watcher was not marked static.
88
+ - improve the "associating..." manpage section.
89
+ - documentation tweaks here and there.
90
+
91
+ 3.43 Sun Jul 6 05:34:41 CEST 2008
92
+ - include more include files on windows to get struct _stati64
93
+ (reported by Chris Hulbert, but doesn't quite fix his issue).
94
+ - add missing #include <io.h> in ev.c on windows (reported by
95
+ Matt Tolton).
96
+
97
+ 3.42 Tue Jun 17 12:12:07 CEST 2008
98
+ - work around yet another windows bug: FD_SET actually adds fd's
99
+ multiple times to the fd_*SET*, despite official MSN docs claiming
100
+ otherwise. Reported and well-analysed by Matt Tolton.
101
+ - define NFDBITS to 0 when EV_SELECT_IS_WINSOCKET to make it compile
102
+ (reported any analysed by Chris Hulbert).
103
+ - fix a bug in ev_ebadf (this function is only used to catch
104
+ programming errors in the libev user). reported by Matt Tolton.
105
+ - fix a bug in fd_intern on win32 (could lead to compile errors
106
+ under some circumstances, but would work correctly if it compiles).
107
+ reported by Matt Tolton.
108
+ - (try to) work around missing lstat on windows.
109
+ - pass in the write fd set as except fd set under windows. windows
110
+ is so uncontrollably lame that it requires this. this means that
111
+ switching off oobinline is not supported (but tcp/ip doesn't
112
+ have oob, so that would be stupid anyways.
113
+ - use posix module symbol to auto-detect monotonic clock presence
114
+ and some other default values.
115
+
3
116
  3.41 Fri May 23 18:42:54 CEST 2008
4
- - work around an (undocumented) bug in winsocket select: if you
117
+ - work around an obscure bug in winsocket select: if you
5
118
  provide only empty fd sets then select returns WSAEINVAL. how sucky.
6
119
  - improve timer scheduling stability and reduce use of time_epsilon.
7
120
  - use 1-based 2-heap for EV_MINIMAL, simplifies code, reduces