smparkes-eventmachine 0.12.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/.gitignore +15 -0
  2. data/README +81 -0
  3. data/Rakefile +374 -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 +40 -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 +827 -0
  25. data/ext/cplusplus.cpp +202 -0
  26. data/ext/ed.cpp +1901 -0
  27. data/ext/ed.h +424 -0
  28. data/ext/em.cpp +2288 -0
  29. data/ext/em.h +229 -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 +150 -0
  37. data/ext/fastfilereader/extconf.rb +85 -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 +156 -0
  48. data/ext/rubymain.cpp +1194 -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/EmReactor.java +570 -0
  56. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  57. data/java/src/com/rubyeventmachine/EventableChannel.java +69 -0
  58. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +189 -0
  59. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +364 -0
  60. data/java/src/com/rubyeventmachine/application/Application.java +194 -0
  61. data/java/src/com/rubyeventmachine/application/Connection.java +74 -0
  62. data/java/src/com/rubyeventmachine/application/ConnectionFactory.java +37 -0
  63. data/java/src/com/rubyeventmachine/application/DefaultConnectionFactory.java +46 -0
  64. data/java/src/com/rubyeventmachine/application/PeriodicTimer.java +38 -0
  65. data/java/src/com/rubyeventmachine/application/Timer.java +54 -0
  66. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +109 -0
  67. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +148 -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 +75 -0
  71. data/java/src/com/rubyeventmachine/tests/TestTimers.java +90 -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 +192 -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/header_and_content.rb +138 -0
  83. data/lib/em/protocols/httpclient.rb +263 -0
  84. data/lib/em/protocols/httpclient2.rb +590 -0
  85. data/lib/em/protocols/line_and_text.rb +125 -0
  86. data/lib/em/protocols/linetext2.rb +161 -0
  87. data/lib/em/protocols/memcache.rb +323 -0
  88. data/lib/em/protocols/object_protocol.rb +45 -0
  89. data/lib/em/protocols/postgres3.rb +247 -0
  90. data/lib/em/protocols/saslauth.rb +175 -0
  91. data/lib/em/protocols/smtpclient.rb +357 -0
  92. data/lib/em/protocols/smtpserver.rb +547 -0
  93. data/lib/em/protocols/socks4.rb +66 -0
  94. data/lib/em/protocols/stomp.rb +200 -0
  95. data/lib/em/protocols/tcptest.rb +53 -0
  96. data/lib/em/protocols.rb +36 -0
  97. data/lib/em/queue.rb +61 -0
  98. data/lib/em/spawnable.rb +85 -0
  99. data/lib/em/streamer.rb +130 -0
  100. data/lib/em/timers.rb +56 -0
  101. data/lib/em/version.rb +3 -0
  102. data/lib/eventmachine.rb +1592 -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/evma.rb +32 -0
  109. data/lib/jeventmachine.rb +257 -0
  110. data/lib/pr_eventmachine.rb +1022 -0
  111. data/setup.rb +1585 -0
  112. data/tasks/cpp.rake_example +77 -0
  113. data/tests/client.crt +31 -0
  114. data/tests/client.key +51 -0
  115. data/tests/test_attach.rb +126 -0
  116. data/tests/test_basic.rb +284 -0
  117. data/tests/test_channel.rb +63 -0
  118. data/tests/test_connection_count.rb +35 -0
  119. data/tests/test_defer.rb +47 -0
  120. data/tests/test_epoll.rb +160 -0
  121. data/tests/test_error_handler.rb +35 -0
  122. data/tests/test_errors.rb +82 -0
  123. data/tests/test_exc.rb +55 -0
  124. data/tests/test_file_watch.rb +49 -0
  125. data/tests/test_futures.rb +198 -0
  126. data/tests/test_get_sock_opt.rb +30 -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_pause.rb +70 -0
  138. data/tests/test_pending_connect_timeout.rb +48 -0
  139. data/tests/test_process_watch.rb +48 -0
  140. data/tests/test_processes.rb +128 -0
  141. data/tests/test_proxy_connection.rb +92 -0
  142. data/tests/test_pure.rb +125 -0
  143. data/tests/test_queue.rb +44 -0
  144. data/tests/test_running.rb +42 -0
  145. data/tests/test_sasl.rb +72 -0
  146. data/tests/test_send_file.rb +242 -0
  147. data/tests/test_servers.rb +76 -0
  148. data/tests/test_smtpclient.rb +83 -0
  149. data/tests/test_smtpserver.rb +85 -0
  150. data/tests/test_spawn.rb +322 -0
  151. data/tests/test_ssl_args.rb +79 -0
  152. data/tests/test_ssl_methods.rb +50 -0
  153. data/tests/test_ssl_verify.rb +82 -0
  154. data/tests/test_timers.rb +162 -0
  155. data/tests/test_ud.rb +36 -0
  156. data/tests/testem.rb +31 -0
  157. data/web/whatis +7 -0
  158. metadata +237 -0
@@ -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
+
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,257 @@
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
+ if field.getType.toString == 'int'
43
+ field.setInt(self, value)
44
+ else
45
+ field.set(self, value)
46
+ end
47
+ end
48
+
49
+ def get_field(key)
50
+ field = getClass.getDeclaredField(key)
51
+ field.setAccessible(true)
52
+ field.get(self)
53
+ end
54
+ end
55
+
56
+ FileDescriptor.send :include, JavaFields
57
+ SocketChannel.send :include, JavaFields
58
+
59
+ module EventMachine
60
+ # TODO: These event numbers are defined in way too many places.
61
+ # DRY them up.
62
+ TimerFired = 100
63
+ ConnectionData = 101
64
+ ConnectionUnbound = 102
65
+ ConnectionAccepted = 103
66
+ ConnectionCompleted = 104
67
+ LoopbreakSignalled = 105
68
+ ConnectionNotifyReadable = 106
69
+ ConnectionNotifyWritable = 107
70
+ SslHandshakeCompleted = 108
71
+
72
+ # Exceptions that are defined in rubymain.cpp
73
+ class ConnectionNotBound < RuntimeError; end
74
+ class UnknownTimerFired < RuntimeError; end
75
+ class Unsupported < RuntimeError; end
76
+
77
+ # This thunk class used to be called EM, but that caused conflicts with
78
+ # the alias "EM" for module EventMachine. (FC, 20Jun08)
79
+ class JEM < com.rubyeventmachine.EmReactor
80
+ def eventCallback a1, a2, a3, a4
81
+ s = String.from_java_bytes(a3.array[a3.position...a3.limit]) if a3
82
+ EventMachine::event_callback a1, a2, s || a4
83
+ nil
84
+ end
85
+ end
86
+ # class Connection < com.rubyeventmachine.Connection
87
+ # def associate_callback_target sig
88
+ # # No-op for the time being.
89
+ # end
90
+ # end
91
+ def self.initialize_event_machine
92
+ @em = JEM.new
93
+ end
94
+ def self.release_machine
95
+ @em = nil
96
+ end
97
+ def self.add_oneshot_timer interval
98
+ @em.installOneshotTimer interval
99
+ end
100
+ def self.run_machine
101
+ @em.run
102
+ end
103
+ def self.stop
104
+ @em.stop
105
+ end
106
+ def self.start_tcp_server server, port
107
+ @em.startTcpServer server, port
108
+ end
109
+ def self.stop_tcp_server sig
110
+ @em.stopTcpServer sig
111
+ end
112
+ def self.start_unix_server filename
113
+ # TEMPORARILY unsupported until someone figures out how to do it.
114
+ raise "unsupported on this platform"
115
+ end
116
+ def self.send_data sig, data, length
117
+ @em.sendData sig, data.to_java_bytes
118
+ end
119
+ def self.send_datagram sig, data, length, address, port
120
+ @em.sendDatagram sig, data, length, address, port
121
+ end
122
+ def self.connect_server server, port
123
+ bind_connect_server nil, nil, server, port
124
+ end
125
+ def self.bind_connect_server bind_addr, bind_port, server, port
126
+ @em.connectTcpServer bind_addr, bind_port.to_i, server, port
127
+ end
128
+ def self.close_connection sig, after_writing
129
+ @em.closeConnection sig, after_writing
130
+ end
131
+ def self.set_comm_inactivity_timeout sig, interval
132
+ @em.setCommInactivityTimeout sig, interval
133
+ end
134
+ def self.start_tls sig
135
+ @em.startTls sig
136
+ end
137
+ def self.ssl?
138
+ false
139
+ end
140
+ def self.signal_loopbreak
141
+ @em.signalLoopbreak
142
+ end
143
+ def self.set_timer_quantum q
144
+ @em.setTimerQuantum q
145
+ end
146
+ def self.epoll
147
+ # Epoll is a no-op for Java.
148
+ # The latest Java versions run epoll when possible in NIO.
149
+ end
150
+ def self.epoll= val
151
+ end
152
+ def self.kqueue
153
+ end
154
+ def self.kqueue= val
155
+ end
156
+ def self.epoll?
157
+ false
158
+ end
159
+ def self.kqueue?
160
+ false
161
+ end
162
+ def self.set_rlimit_nofile n_descriptors
163
+ # Currently a no-op for Java.
164
+ end
165
+ def self.open_udp_socket server, port
166
+ @em.openUdpSocket server, port
167
+ end
168
+ def self.invoke_popen cmd
169
+ # TEMPORARILY unsupported until someone figures out how to do it.
170
+ raise "unsupported on this platform"
171
+ end
172
+ def self.read_keyboard
173
+ # TEMPORARILY unsupported until someone figures out how to do it.
174
+ raise "temporarily unsupported on this platform"
175
+ end
176
+ def self.set_max_timer_count num
177
+ # harmless no-op in Java. There's no built-in timer limit.
178
+ @max_timer_count = num
179
+ end
180
+ def self.get_max_timer_count
181
+ # harmless no-op in Java. There's no built-in timer limit.
182
+ @max_timer_count || 100_000
183
+ end
184
+ def self.library_type
185
+ :java
186
+ end
187
+ def self.get_peername sig
188
+ if peer = @em.getPeerName(sig)
189
+ Socket.pack_sockaddr_in *peer
190
+ end
191
+ end
192
+ def self.attach_fd fileno, watch_mode
193
+ # 3Aug09: We could pass in the actual SocketChannel, but then it would be modified (set as non-blocking), and
194
+ # we would need some logic to make sure detach_fd below didn't clobber it. For now, we just always make a new
195
+ # SocketChannel for the underlying file descriptor
196
+ # if fileno.java_kind_of? SocketChannel
197
+ # ch = fileno
198
+ # ch.configureBlocking(false)
199
+ # fileno = nil
200
+ # elsif fileno.java_kind_of? java.nio.channels.Channel
201
+
202
+ if fileno.java_kind_of? java.nio.channels.Channel
203
+ field = fileno.getClass.getDeclaredField('fdVal')
204
+ field.setAccessible(true)
205
+ fileno = field.get(fileno)
206
+ else
207
+ raise ArgumentError, 'attach_fd requires Java Channel or POSIX fileno' unless fileno.is_a? Fixnum
208
+ end
209
+
210
+ if fileno == 0
211
+ raise "can't open STDIN as selectable in Java =("
212
+ elsif fileno.is_a? Fixnum
213
+ # 8Aug09: The following code is specific to the sun jvm's SocketChannelImpl. Is there a cross-platform
214
+ # way of implementing this? If so, also remember to update EventableSocketChannel#close and #cleanup
215
+ fd = FileDescriptor.new
216
+ fd.set_field 'fd', fileno
217
+
218
+ ch = SocketChannel.open
219
+ ch.configureBlocking(false)
220
+ ch.kill
221
+ ch.set_field 'fd', fd
222
+ ch.set_field 'fdVal', fileno
223
+ ch.set_field 'state', ch.get_field('ST_CONNECTED')
224
+ end
225
+
226
+ @em.attachChannel(ch,watch_mode)
227
+ end
228
+ def self.detach_fd sig
229
+ if ch = @em.detachChannel(sig)
230
+ ch.get_field 'fdVal'
231
+ end
232
+ end
233
+
234
+ def self.set_notify_readable sig, mode
235
+ @em.setNotifyReadable(sig, mode)
236
+ end
237
+ def self.set_notify_writable sig, mode
238
+ @em.setNotifyWritable(sig, mode)
239
+ end
240
+
241
+ def self.is_notify_readable sig
242
+ @em.isNotifyReadable(sig)
243
+ end
244
+ def self.is_notify_writable sig
245
+ @em.isNotifyWritable(sig)
246
+ end
247
+ def self.get_connection_count
248
+ @em.getConnectionCount
249
+ end
250
+
251
+ class Connection
252
+ def associate_callback_target sig
253
+ # No-op for the time being
254
+ end
255
+ end
256
+ end
257
+