MattHulse-eventmachine 0.0.1

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.
Files changed (156) hide show
  1. data/.gitignore +14 -0
  2. data/README +82 -0
  3. data/Rakefile +279 -0
  4. data/docs/COPYING +60 -0
  5. data/docs/ChangeLog +211 -0
  6. data/docs/DEFERRABLES +133 -0
  7. data/docs/EPOLL +141 -0
  8. data/docs/GNU +281 -0
  9. data/docs/INSTALL +13 -0
  10. data/docs/KEYBOARD +38 -0
  11. data/docs/LEGAL +25 -0
  12. data/docs/LIGHTWEIGHT_CONCURRENCY +70 -0
  13. data/docs/PURE_RUBY +75 -0
  14. data/docs/RELEASE_NOTES +94 -0
  15. data/docs/SMTP +2 -0
  16. data/docs/SPAWNED_PROCESSES +89 -0
  17. data/docs/TODO +8 -0
  18. data/eventmachine.gemspec +41 -0
  19. data/examples/ex_channel.rb +43 -0
  20. data/examples/ex_queue.rb +2 -0
  21. data/examples/helper.rb +2 -0
  22. data/ext/binder.cpp +125 -0
  23. data/ext/binder.h +46 -0
  24. data/ext/cmain.cpp +821 -0
  25. data/ext/cplusplus.cpp +202 -0
  26. data/ext/ed.cpp +1868 -0
  27. data/ext/ed.h +416 -0
  28. data/ext/em.cpp +2270 -0
  29. data/ext/em.h +228 -0
  30. data/ext/emwin.cpp +300 -0
  31. data/ext/emwin.h +94 -0
  32. data/ext/epoll.cpp +26 -0
  33. data/ext/epoll.h +25 -0
  34. data/ext/eventmachine.h +122 -0
  35. data/ext/eventmachine_cpp.h +96 -0
  36. data/ext/extconf.rb +138 -0
  37. data/ext/fastfilereader/extconf.rb +84 -0
  38. data/ext/fastfilereader/mapper.cpp +214 -0
  39. data/ext/fastfilereader/mapper.h +59 -0
  40. data/ext/fastfilereader/rubymain.cpp +127 -0
  41. data/ext/files.cpp +94 -0
  42. data/ext/files.h +65 -0
  43. data/ext/kb.cpp +81 -0
  44. data/ext/page.cpp +107 -0
  45. data/ext/page.h +51 -0
  46. data/ext/pipe.cpp +349 -0
  47. data/ext/project.h +147 -0
  48. data/ext/rubymain.cpp +1152 -0
  49. data/ext/sigs.cpp +89 -0
  50. data/ext/sigs.h +32 -0
  51. data/ext/ssl.cpp +460 -0
  52. data/ext/ssl.h +94 -0
  53. data/java/.classpath +8 -0
  54. data/java/.project +17 -0
  55. data/java/src/com/rubyeventmachine/Application.java +192 -0
  56. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  57. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  58. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  59. data/java/src/com/rubyeventmachine/EmReactor.java +557 -0
  60. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  61. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  62. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  63. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  64. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  65. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  66. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  67. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +146 -0
  68. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  69. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  70. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  71. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  72. data/lib/em/buftok.rb +138 -0
  73. data/lib/em/callback.rb +26 -0
  74. data/lib/em/channel.rb +57 -0
  75. data/lib/em/connection.rb +564 -0
  76. data/lib/em/deferrable.rb +187 -0
  77. data/lib/em/file_watch.rb +54 -0
  78. data/lib/em/future.rb +61 -0
  79. data/lib/em/messages.rb +66 -0
  80. data/lib/em/process_watch.rb +44 -0
  81. data/lib/em/processes.rb +119 -0
  82. data/lib/em/protocols.rb +35 -0
  83. data/lib/em/protocols/header_and_content.rb +138 -0
  84. data/lib/em/protocols/httpclient.rb +263 -0
  85. data/lib/em/protocols/httpclient2.rb +582 -0
  86. data/lib/em/protocols/line_and_text.rb +126 -0
  87. data/lib/em/protocols/linetext2.rb +160 -0
  88. data/lib/em/protocols/memcache.rb +323 -0
  89. data/lib/em/protocols/object_protocol.rb +45 -0
  90. data/lib/em/protocols/postgres3.rb +247 -0
  91. data/lib/em/protocols/saslauth.rb +175 -0
  92. data/lib/em/protocols/smtpclient.rb +350 -0
  93. data/lib/em/protocols/smtpserver.rb +547 -0
  94. data/lib/em/protocols/stomp.rb +200 -0
  95. data/lib/em/protocols/tcptest.rb +53 -0
  96. data/lib/em/queue.rb +61 -0
  97. data/lib/em/spawnable.rb +85 -0
  98. data/lib/em/streamer.rb +130 -0
  99. data/lib/em/timers.rb +55 -0
  100. data/lib/em/version.rb +3 -0
  101. data/lib/eventmachine.rb +1698 -0
  102. data/lib/evma.rb +32 -0
  103. data/lib/evma/callback.rb +32 -0
  104. data/lib/evma/container.rb +75 -0
  105. data/lib/evma/factory.rb +77 -0
  106. data/lib/evma/protocol.rb +87 -0
  107. data/lib/evma/reactor.rb +48 -0
  108. data/lib/jeventmachine.rb +246 -0
  109. data/lib/pr_eventmachine.rb +1022 -0
  110. data/setup.rb +1585 -0
  111. data/tasks/cpp.rake +77 -0
  112. data/tasks/project.rake +79 -0
  113. data/tasks/tests.rake +193 -0
  114. data/tests/client.crt +31 -0
  115. data/tests/client.key +51 -0
  116. data/tests/test_attach.rb +126 -0
  117. data/tests/test_basic.rb +284 -0
  118. data/tests/test_channel.rb +63 -0
  119. data/tests/test_connection_count.rb +35 -0
  120. data/tests/test_defer.rb +47 -0
  121. data/tests/test_epoll.rb +160 -0
  122. data/tests/test_error_handler.rb +35 -0
  123. data/tests/test_errors.rb +82 -0
  124. data/tests/test_exc.rb +55 -0
  125. data/tests/test_file_watch.rb +49 -0
  126. data/tests/test_futures.rb +198 -0
  127. data/tests/test_handler_check.rb +37 -0
  128. data/tests/test_hc.rb +218 -0
  129. data/tests/test_httpclient.rb +218 -0
  130. data/tests/test_httpclient2.rb +153 -0
  131. data/tests/test_inactivity_timeout.rb +50 -0
  132. data/tests/test_kb.rb +60 -0
  133. data/tests/test_ltp.rb +182 -0
  134. data/tests/test_ltp2.rb +317 -0
  135. data/tests/test_next_tick.rb +133 -0
  136. data/tests/test_object_protocol.rb +37 -0
  137. data/tests/test_process_watch.rb +48 -0
  138. data/tests/test_processes.rb +128 -0
  139. data/tests/test_proxy_connection.rb +92 -0
  140. data/tests/test_pure.rb +125 -0
  141. data/tests/test_queue.rb +44 -0
  142. data/tests/test_running.rb +42 -0
  143. data/tests/test_sasl.rb +72 -0
  144. data/tests/test_send_file.rb +242 -0
  145. data/tests/test_servers.rb +76 -0
  146. data/tests/test_smtpclient.rb +83 -0
  147. data/tests/test_smtpserver.rb +85 -0
  148. data/tests/test_spawn.rb +322 -0
  149. data/tests/test_ssl_args.rb +68 -0
  150. data/tests/test_ssl_methods.rb +50 -0
  151. data/tests/test_ssl_verify.rb +82 -0
  152. data/tests/test_timers.rb +162 -0
  153. data/tests/test_ud.rb +36 -0
  154. data/tests/testem.rb +31 -0
  155. data/web/whatis +7 -0
  156. metadata +223 -0
data/lib/evma.rb ADDED
@@ -0,0 +1,32 @@
1
+ #--
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
+ require 'rubyeventmachine'
27
+ require 'evma/reactor'
28
+ require 'evma/callback'
29
+ require 'evma/protocol'
30
+ require 'evma/factory'
31
+ require 'evma/container'
32
+
@@ -0,0 +1,32 @@
1
+ # $Id$
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 19 May 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
+ module EventMachine
27
+
28
+ def self.event_callback target, opcode, data
29
+ Evma::Container.callback target, opcode, data
30
+ end
31
+
32
+ end # module EventMachine
@@ -0,0 +1,75 @@
1
+ # $Id$
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 19 May 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
+ require 'singleton'
28
+
29
+ module Evma
30
+
31
+ class ContainerHasObject < Exception; end
32
+ class UnsupportedCallback < Exception; end
33
+ class UnknownTarget < Exception; end
34
+
35
+ class Container
36
+ include Singleton
37
+
38
+ def initialize
39
+ @objects = {}
40
+ end
41
+
42
+ def self.store obj
43
+ instance.store obj
44
+ end
45
+
46
+ def self.callback target, opcode, data
47
+ instance.callback target, opcode, data
48
+ end
49
+
50
+ def store obj
51
+ sig = obj.signature
52
+ raise ContainerHasObject.new(sig) if @objects.has_key?(sig)
53
+ @objects[sig] = obj
54
+ end
55
+
56
+ def callback target, opcode, data
57
+ case opcode
58
+ when 101 # received data
59
+ obj = @objects[target] or raise UnknownTarget.new( target )
60
+ obj.receive_data data
61
+ when 102 # unbind
62
+ obj = @objects[target] or raise UnknownTarget.new( target )
63
+ obj.unbind
64
+ @objects.delete obj.signature
65
+ when 103 # accept
66
+ obj = @objects[target] or raise UnknownTarget.new( target )
67
+ obj.accept data
68
+ else
69
+ raise UnsupportedCallback.new( opcode.to_s )
70
+ end
71
+ end
72
+
73
+ end # class Container
74
+ end # module Evma
75
+
@@ -0,0 +1,77 @@
1
+ # $Id$
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 19 May 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
+ module Evma
27
+ class ProtocolFactory < Protocol
28
+
29
+ #--
30
+ # default implementation raises an exception.
31
+ # we expect subclasses to override this.
32
+ # we can't do anything reasonable here because
33
+ def accept new_object
34
+ # don't bother calling Evma::Reactor.instance, since only Reactor can call accept
35
+ Evma::Container.store Evma::Protocol.new( new_object )
36
+ EventMachine.close_connection new_object, false
37
+ end
38
+
39
+
40
+ end # class ProtocolFactory
41
+ end # module Evma
42
+
43
+ ######################################
44
+
45
+ module Evma
46
+ class TcpSocket
47
+
48
+ def self.connect server, port, protocol_handler = Evma::Protocol
49
+ Evma::Reactor.instance # ensure initialization
50
+ sig = EventMachine.connect_server server, port
51
+ Evma::Container.store protocol_handler.new( sig )
52
+ end
53
+
54
+ end
55
+ end # module Evma
56
+
57
+ ######################################
58
+
59
+ module Evma
60
+ class TcpServerFactory < Evma::ProtocolFactory
61
+
62
+ def initialize server, port, protocol_handler = Evma::Protocol
63
+ Evma::Reactor.instance # ensure initialization
64
+ sig = EventMachine.start_tcp_server server, port
65
+ super sig
66
+ @protocol_handler = protocol_handler
67
+ Evma::Container.store self
68
+ end
69
+
70
+ def accept new_obj
71
+ # don't bother calling Evma::Reactor.instance, since only Reactor can call accept
72
+ Evma::Container.store @protocol_handler.new( new_obj )
73
+ end
74
+
75
+ end
76
+ end # module Evma
77
+
@@ -0,0 +1,87 @@
1
+ # $Id$
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 19 May 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
+ module Evma
27
+ class Protocol
28
+
29
+ attr_reader :signature
30
+
31
+ def initialize sig
32
+ @signature = sig
33
+ end
34
+
35
+ def unbind
36
+ end
37
+
38
+ def close
39
+ Evma::Reactor.instance # ensure initialized
40
+ EventMachine.close_connection signature, false
41
+ end
42
+
43
+ def close_after_writing
44
+ Evma::Reactor.instance # ensure initialized
45
+ EventMachine.close_connection signature, true
46
+ end
47
+
48
+ end # class Protocol
49
+ end # module Evma
50
+
51
+
52
+ ###########################################
53
+
54
+ module Evma
55
+ class StreamProtocol < Protocol
56
+
57
+ def initialize sig
58
+ super
59
+ end
60
+
61
+ def send_data data
62
+ Evma::Reactor.instance # ensure initialized
63
+ EventMachine.send_data signature, data, data.length
64
+ end
65
+
66
+ end # class Protocol
67
+ end # module Evma
68
+
69
+
70
+ ###########################################
71
+
72
+ module Evma
73
+ class DatagramProtocol < Protocol
74
+
75
+ def initialize sig
76
+ super
77
+ end
78
+
79
+ def send_message data
80
+ Evma::Reactor.instance # ensure initialized
81
+ raise "unimplemented"
82
+ end
83
+
84
+ end # class Protocol
85
+ end # module Evma
86
+
87
+
@@ -0,0 +1,48 @@
1
+ # $Id$
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 18 May 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
+ require 'singleton'
28
+
29
+ module Evma
30
+ class Reactor
31
+ include Singleton
32
+
33
+ #--
34
+ def initialize
35
+ EventMachine.initialize_event_machine
36
+ end
37
+
38
+ #--
39
+ #
40
+ def run
41
+ EventMachine.run_machine
42
+ end
43
+
44
+ end # class Reactor
45
+ end # module Evma
46
+
47
+
48
+
@@ -0,0 +1,246 @@
1
+ #--
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
+ # This module provides "glue" for the Java version of the EventMachine reactor core.
27
+ # For C++ EventMachines, the analogous functionality is found in ext/rubymain.cpp,
28
+ # which is a garden-variety Ruby-extension glue module.
29
+
30
+ require 'java'
31
+ require 'em_reactor'
32
+ require 'socket'
33
+
34
+ java_import java.io.FileDescriptor
35
+ java_import java.nio.channels.SocketChannel
36
+ java_import java.lang.reflect.Field
37
+
38
+ module JavaFields
39
+ def set_field(key, value)
40
+ field = getClass.getDeclaredField(key)
41
+ field.setAccessible(true)
42
+ field.set(self, value)
43
+ end
44
+
45
+ def get_field(key)
46
+ field = getClass.getDeclaredField(key)
47
+ field.setAccessible(true)
48
+ field.get(self)
49
+ end
50
+ end
51
+
52
+ FileDescriptor.send :include, JavaFields
53
+ SocketChannel.send :include, JavaFields
54
+
55
+ module EventMachine
56
+ # TODO: These event numbers are defined in way too many places.
57
+ # DRY them up.
58
+ TimerFired = 100
59
+ ConnectionData = 101
60
+ ConnectionUnbound = 102
61
+ ConnectionAccepted = 103
62
+ ConnectionCompleted = 104
63
+ LoopbreakSignalled = 105
64
+ ConnectionNotifyReadable = 106
65
+ ConnectionNotifyWritable = 107
66
+
67
+ # This thunk class used to be called EM, but that caused conflicts with
68
+ # the alias "EM" for module EventMachine. (FC, 20Jun08)
69
+ class JEM < com.rubyeventmachine.EmReactor
70
+ def eventCallback a1, a2, a3, a4
71
+ s = String.from_java_bytes(a3.array[a3.position...a3.limit]) if a3
72
+ EventMachine::event_callback a1, a2, s || a4
73
+ end
74
+ end
75
+ # class Connection < com.rubyeventmachine.Connection
76
+ # def associate_callback_target sig
77
+ # # No-op for the time being.
78
+ # end
79
+ # end
80
+ def self.initialize_event_machine
81
+ @em = JEM.new
82
+ end
83
+ def self.release_machine
84
+ @em = nil
85
+ end
86
+ def self.add_oneshot_timer interval
87
+ @em.installOneshotTimer interval
88
+ end
89
+ def self.run_machine
90
+ @em.run
91
+ end
92
+ def self.stop
93
+ @em.stop
94
+ end
95
+ def self.start_tcp_server server, port
96
+ @em.startTcpServer server, port
97
+ end
98
+ def self.stop_tcp_server sig
99
+ @em.stopTcpServer sig
100
+ end
101
+ def self.start_unix_server filename
102
+ # TEMPORARILY unsupported until someone figures out how to do it.
103
+ raise "unsupported on this platform"
104
+ end
105
+ def self.send_data sig, data, length
106
+ @em.sendData sig, data.to_java_bytes
107
+ end
108
+ def self.send_datagram sig, data, length, address, port
109
+ @em.sendDatagram sig, data, length, address, port
110
+ end
111
+ def self.connect_server server, port
112
+ bind_connect_server nil, nil, server, port
113
+ end
114
+ def self.bind_connect_server bind_addr, bind_port, server, port
115
+ @em.connectTcpServer bind_addr, bind_port.to_i, server, port
116
+ end
117
+ def self.close_connection sig, after_writing
118
+ @em.closeConnection sig, after_writing
119
+ end
120
+ def self.set_comm_inactivity_timeout sig, interval
121
+ @em.setCommInactivityTimeout sig, interval
122
+ end
123
+ def self.start_tls sig
124
+ @em.startTls sig
125
+ end
126
+ def self.ssl?
127
+ false
128
+ end
129
+ def self.signal_loopbreak
130
+ @em.signalLoopbreak
131
+ end
132
+ def self.set_timer_quantum q
133
+ @em.setTimerQuantum q
134
+ end
135
+ def self.epoll
136
+ # Epoll is a no-op for Java.
137
+ # The latest Java versions run epoll when possible in NIO.
138
+ end
139
+ def self.epoll= val
140
+ end
141
+ def self.kqueue
142
+ end
143
+ def self.kqueue= val
144
+ end
145
+ def self.epoll?
146
+ false
147
+ end
148
+ def self.kqueue?
149
+ false
150
+ end
151
+ def self.set_rlimit_nofile n_descriptors
152
+ # Currently a no-op for Java.
153
+ end
154
+ def self.open_udp_socket server, port
155
+ @em.openUdpSocket server, port
156
+ end
157
+ def self.invoke_popen cmd
158
+ # TEMPORARILY unsupported until someone figures out how to do it.
159
+ raise "unsupported on this platform"
160
+ end
161
+ def self.read_keyboard
162
+ # TEMPORARILY unsupported until someone figures out how to do it.
163
+ raise "temporarily unsupported on this platform"
164
+ end
165
+ def self.set_max_timer_count num
166
+ # harmless no-op in Java. There's no built-in timer limit.
167
+ @max_timer_count = num
168
+ end
169
+ def self.get_max_timer_count
170
+ # harmless no-op in Java. There's no built-in timer limit.
171
+ @max_timer_count || 100_000
172
+ end
173
+ def self.library_type
174
+ :java
175
+ end
176
+ def self.get_peername sig
177
+ if peer = @em.getPeerName(sig)
178
+ Socket.pack_sockaddr_in *peer
179
+ end
180
+ end
181
+ def self.attach_fd fileno, watch_mode
182
+ # 3Aug09: We could pass in the actual SocketChannel, but then it would be modified (set as non-blocking), and
183
+ # we would need some logic to make sure detach_fd below didn't clobber it. For now, we just always make a new
184
+ # SocketChannel for the underlying file descriptor
185
+ # if fileno.java_kind_of? SocketChannel
186
+ # ch = fileno
187
+ # ch.configureBlocking(false)
188
+ # fileno = nil
189
+ # elsif fileno.java_kind_of? java.nio.channels.Channel
190
+
191
+ if fileno.java_kind_of? java.nio.channels.Channel
192
+ field = fileno.getClass.getDeclaredField('fdVal')
193
+ field.setAccessible(true)
194
+ fileno = field.get(fileno)
195
+ else
196
+ raise ArgumentError, 'attach_fd requires Java Channel or POSIX fileno' unless fileno.is_a? Fixnum
197
+ end
198
+
199
+ if fileno == 0
200
+ raise "can't open STDIN as selectable in Java =("
201
+ elsif fileno.is_a? Fixnum
202
+ # 8Aug09: The following code is specific to the sun jvm's SocketChannelImpl. Is there a cross-platform
203
+ # way of implementing this? If so, also remember to update EventableSocketChannel#close and #cleanup
204
+ fd = FileDescriptor.new
205
+ fd.set_field 'fd', fileno
206
+
207
+ ch = SocketChannel.open
208
+ ch.configureBlocking(false)
209
+ ch.kill
210
+ ch.set_field 'fd', fd
211
+ ch.set_field 'fdVal', fileno
212
+ ch.set_field 'state', ch.get_field('ST_CONNECTED')
213
+ end
214
+
215
+ @em.attachChannel(ch,watch_mode)
216
+ end
217
+ def self.detach_fd sig
218
+ if ch = @em.detachChannel(sig)
219
+ ch.get_field 'fdVal'
220
+ end
221
+ end
222
+
223
+ def self.set_notify_readable sig, mode
224
+ @em.setNotifyReadable(sig, mode)
225
+ end
226
+ def self.set_notify_writable sig, mode
227
+ @em.setNotifyWritable(sig, mode)
228
+ end
229
+
230
+ def self.is_notify_readable sig
231
+ @em.isNotifyReadable(sig)
232
+ end
233
+ def self.is_notify_writable sig
234
+ @em.isNotifyWritable(sig)
235
+ end
236
+ def self.get_connection_count
237
+ @em.getConnectionCount
238
+ end
239
+
240
+ class Connection
241
+ def associate_callback_target sig
242
+ # No-op for the time being
243
+ end
244
+ end
245
+ end
246
+