root/trunk/lib/jeventmachine.rb

Revision 788, 3.6 kB (checked in by raggi, 8 months ago)

Merge of branches/raggi
Most notable work and patches by Aman Gupta, Roger Pack, and James Tucker.
Patches / Tickets also submitted by: Jeremy Evans, aanand, darix, mmmurf,
danielaquino, macournoyer.

  • Moved docs into docs/ dir
  • Major refactor of rakefile, added generic rakefile helpers in tasks
  • Added example CPP build rakefile in tasks/cpp.rake
  • Moved rake tests out to tasks/tests.rake
  • Added svn ignores where appropriate
  • Fixed jruby build on older java platforms
  • Gem now builds from Rakefile rather than directly via extconf
  • Gem unified for jruby, C++ and pure ruby.
  • Correction for pure C++ build, removing ruby dependency
  • Fix for CYGWIN builds on ipv6
  • Major refactor for extconf.rb
  • Working mingw builds
  • extconf optionally uses pkg_config over manual configuration
  • extconf builds for 1.9 on any system that has 1.9
  • extconf no longer links pthread explicitly
  • looks for kqueue on all *nix systems
  • better error output on std::runtime_error, now says where it came from
  • Fixed some tests on jruby
  • Added test for general send_data flaw, required for a bugfix in jruby build
  • Added timeout to epoll tests
  • Added fixes for java reactor ruby api
  • Small addition of some docs in httpclient.rb and httpcli2.rb
  • Some refactor and fixes in smtpserver.rb
  • Added parenthesis where possible to avoid excess ruby warnings
  • Refactor of $eventmachine_library logic for accuracy and maintenance, jruby
  • EM::start_server now supports unix sockets
  • EM::connect now supports unix sockets
  • EM::defer @threadqueue now handled more gracefully
  • Added better messages on exceptions raised
  • Fix edge case in timer fires
  • Explicitly require buftok.rb
  • Add protocols to autoload, rather than require them all immediately
  • Fix a bug in pr_eventmachine for outbound_q
  • Refactors to take some of the use of defer out of tests.
  • Fixes in EM.defer under start/stop conditions. Reduced scope of threads.
  • Property svn:keywords set to Id
Line 
1 # $Id$
2 #
3 # Author:: Francis Cianfrocca (gmail: blackhedd)
4 # Homepage::  http://rubyeventmachine.com
5 # Date:: 8 Apr 2006
6 #
7 # See EventMachine and EventMachine::Connection for documentation and
8 # usage examples.
9 #
10 #----------------------------------------------------------------------------
11 #
12 # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13 # Gmail: blackhedd
14 #
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of either: 1) the GNU General Public License
17 # as published by the Free Software Foundation; either version 2 of the
18 # License, or (at your option) any later version; or 2) Ruby's License.
19 #
20 # See the file COPYING for complete licensing information.
21 #
22 #---------------------------------------------------------------------------
23 #
24 #
25
26
27 # This module provides "glue" for the Java version of the EventMachine reactor core.
28 # For C++ EventMachines, the analogous functionality is found in ext/rubymain.cpp,
29 # which is a garden-variety Ruby-extension glue module.
30
31 require 'java'
32 require 'em_reactor'
33
34 module EventMachine
35         # TODO: These event numbers are defined in way too many places.
36         # DRY them up.
37         TimerFired = 100
38         ConnectionData = 101
39         ConnectionUnbound = 102
40         ConnectionAccepted = 103
41         ConnectionCompleted = 104
42         LoopbreakSignalled = 105
43
44         # This thunk class used to be called EM, but that caused conflicts with
45         # the alias "EM" for module EventMachine. (FC, 20Jun08)
46         class JEM < com.rubyeventmachine.EmReactor
47                 def eventCallback a1, a2, a3
48                         s = String.from_java_bytes(a3.array[a3.position...a3.limit])
49                         EventMachine::event_callback a1, a2, s
50                 end
51         end
52         class Connection < com.rubyeventmachine.Connection
53                 def associate_callback_target sig
54                         # No-op for the time being.
55                 end
56         end
57         def self.initialize_event_machine
58                 @em = JEM.new
59         end
60         def self.release_machine
61                 @em = nil
62         end
63         def self.add_oneshot_timer interval
64                 @em.installOneshotTimer interval
65         end
66         def self.run_machine
67                 @em.run
68         end
69         def self.stop
70                 @em.stop
71         end
72         def self.start_tcp_server server, port
73                 @em.startTcpServer server, port
74         end
75         def self.stop_tcp_server sig
76                 @em.stopTcpServer sig
77         end
78         def self.start_unix_server filename
79                 # TEMPORARILY unsupported until someone figures out how to do it.
80                 raise "unsupported on this platform"
81         end
82         def self.send_data sig, data, length
83                 @em.sendData sig, data.to_java_bytes
84         end
85         def self.send_datagram sig, data, length, address, port
86                 @em.sendDatagram sig, data, length, address, port
87         end
88         def self.connect_server server, port
89                 @em.connectTcpServer server, port
90         end
91         def self.close_connection sig, after_writing
92                 @em.closeConnection sig, after_writing
93         end
94         def self.set_comm_inactivity_timeout sig, interval
95                 @em.setCommInactivityTimeout sig, interval
96         end
97         def self.start_tls sig
98                 @em.startTls sig
99         end
100         def self.signal_loopbreak
101                 @em.signalLoopbreak
102         end
103         def self.set_timer_quantum q
104                 @em.setTimerQuantum q
105         end
106         def self.epoll
107                 # Epoll is a no-op for Java.
108                 # The latest Java versions run epoll when possible in NIO.
109         end
110         def self.set_rlimit_nofile n_descriptors
111                 # Currently a no-op for Java.
112         end
113         def self.open_udp_socket server, port
114                 @em.openUdpSocket server, port
115         end
116         def self.invoke_popen cmd
117                 # TEMPORARILY unsupported until someone figures out how to do it.
118                 raise "unsupported on this platform"
119         end
120         def self.read_keyboard
121                 # TEMPORARILY unsupported until someone figures out how to do it.
122                 raise "temporarily unsupported on this platform"
123         end
124         def self.set_max_timer_count num
125                 # harmless no-op in Java. There's no built-in timer limit.
126         end
127         def self.library_type
128                 :java
129         end
130
131         class Connection
132                 def associate_callback_target sig
133                         # No-op for the time being
134                 end
135         end
136 end
137
Note: See TracBrowser for help on using the browser.