eventmachine-eventmachine 0.12.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/Rakefile +169 -0
  2. data/docs/COPYING +60 -0
  3. data/docs/ChangeLog +183 -0
  4. data/docs/DEFERRABLES +138 -0
  5. data/docs/EPOLL +141 -0
  6. data/docs/GNU +281 -0
  7. data/docs/INSTALL +15 -0
  8. data/docs/KEYBOARD +38 -0
  9. data/docs/LEGAL +25 -0
  10. data/docs/LIGHTWEIGHT_CONCURRENCY +72 -0
  11. data/docs/PURE_RUBY +77 -0
  12. data/docs/README +74 -0
  13. data/docs/RELEASE_NOTES +96 -0
  14. data/docs/SMTP +9 -0
  15. data/docs/SPAWNED_PROCESSES +93 -0
  16. data/docs/TODO +10 -0
  17. data/ext/binder.cpp +126 -0
  18. data/ext/binder.h +48 -0
  19. data/ext/cmain.cpp +530 -0
  20. data/ext/cplusplus.cpp +172 -0
  21. data/ext/ed.cpp +1473 -0
  22. data/ext/ed.h +361 -0
  23. data/ext/em.cpp +1895 -0
  24. data/ext/em.h +170 -0
  25. data/ext/emwin.cpp +300 -0
  26. data/ext/emwin.h +94 -0
  27. data/ext/epoll.cpp +26 -0
  28. data/ext/epoll.h +25 -0
  29. data/ext/eventmachine.h +90 -0
  30. data/ext/eventmachine_cpp.h +94 -0
  31. data/ext/extconf.rb +150 -0
  32. data/ext/files.cpp +94 -0
  33. data/ext/files.h +65 -0
  34. data/ext/kb.cpp +368 -0
  35. data/ext/page.cpp +107 -0
  36. data/ext/page.h +51 -0
  37. data/ext/pipe.cpp +327 -0
  38. data/ext/project.h +119 -0
  39. data/ext/rubymain.cpp +683 -0
  40. data/ext/sigs.cpp +89 -0
  41. data/ext/sigs.h +32 -0
  42. data/ext/ssl.cpp +408 -0
  43. data/ext/ssl.h +86 -0
  44. data/java/src/com/rubyeventmachine/Application.java +196 -0
  45. data/java/src/com/rubyeventmachine/Connection.java +74 -0
  46. data/java/src/com/rubyeventmachine/ConnectionFactory.java +37 -0
  47. data/java/src/com/rubyeventmachine/DefaultConnectionFactory.java +46 -0
  48. data/java/src/com/rubyeventmachine/EmReactor.java +408 -0
  49. data/java/src/com/rubyeventmachine/EmReactorException.java +40 -0
  50. data/java/src/com/rubyeventmachine/EventableChannel.java +57 -0
  51. data/java/src/com/rubyeventmachine/EventableDatagramChannel.java +171 -0
  52. data/java/src/com/rubyeventmachine/EventableSocketChannel.java +244 -0
  53. data/java/src/com/rubyeventmachine/PeriodicTimer.java +38 -0
  54. data/java/src/com/rubyeventmachine/Timer.java +54 -0
  55. data/java/src/com/rubyeventmachine/tests/ApplicationTest.java +108 -0
  56. data/java/src/com/rubyeventmachine/tests/ConnectTest.java +124 -0
  57. data/java/src/com/rubyeventmachine/tests/EMTest.java +80 -0
  58. data/java/src/com/rubyeventmachine/tests/TestDatagrams.java +53 -0
  59. data/java/src/com/rubyeventmachine/tests/TestServers.java +74 -0
  60. data/java/src/com/rubyeventmachine/tests/TestTimers.java +89 -0
  61. data/lib/em/deferrable.rb +208 -0
  62. data/lib/em/eventable.rb +39 -0
  63. data/lib/em/future.rb +62 -0
  64. data/lib/em/messages.rb +66 -0
  65. data/lib/em/processes.rb +68 -0
  66. data/lib/em/spawnable.rb +88 -0
  67. data/lib/em/streamer.rb +112 -0
  68. data/lib/eventmachine.rb +1763 -0
  69. data/lib/eventmachine_version.rb +31 -0
  70. data/lib/evma.rb +32 -0
  71. data/lib/evma/callback.rb +32 -0
  72. data/lib/evma/container.rb +75 -0
  73. data/lib/evma/factory.rb +77 -0
  74. data/lib/evma/protocol.rb +87 -0
  75. data/lib/evma/reactor.rb +48 -0
  76. data/lib/jeventmachine.rb +137 -0
  77. data/lib/pr_eventmachine.rb +1011 -0
  78. data/lib/protocols/buftok.rb +127 -0
  79. data/lib/protocols/header_and_content.rb +129 -0
  80. data/lib/protocols/httpcli2.rb +794 -0
  81. data/lib/protocols/httpclient.rb +270 -0
  82. data/lib/protocols/line_and_text.rb +122 -0
  83. data/lib/protocols/linetext2.rb +163 -0
  84. data/lib/protocols/postgres.rb +261 -0
  85. data/lib/protocols/saslauth.rb +179 -0
  86. data/lib/protocols/smtpclient.rb +308 -0
  87. data/lib/protocols/smtpserver.rb +556 -0
  88. data/lib/protocols/stomp.rb +130 -0
  89. data/lib/protocols/tcptest.rb +57 -0
  90. data/tasks/cpp.rake +77 -0
  91. data/tasks/project.rake +78 -0
  92. data/tasks/tests.rake +192 -0
  93. data/tests/test_attach.rb +66 -0
  94. data/tests/test_basic.rb +231 -0
  95. data/tests/test_defer.rb +47 -0
  96. data/tests/test_epoll.rb +161 -0
  97. data/tests/test_errors.rb +82 -0
  98. data/tests/test_eventables.rb +78 -0
  99. data/tests/test_exc.rb +58 -0
  100. data/tests/test_futures.rb +214 -0
  101. data/tests/test_hc.rb +218 -0
  102. data/tests/test_httpclient.rb +215 -0
  103. data/tests/test_httpclient2.rb +133 -0
  104. data/tests/test_kb.rb +61 -0
  105. data/tests/test_ltp.rb +192 -0
  106. data/tests/test_ltp2.rb +320 -0
  107. data/tests/test_next_tick.rb +102 -0
  108. data/tests/test_processes.rb +56 -0
  109. data/tests/test_pure.rb +129 -0
  110. data/tests/test_running.rb +47 -0
  111. data/tests/test_sasl.rb +74 -0
  112. data/tests/test_send_file.rb +245 -0
  113. data/tests/test_servers.rb +80 -0
  114. data/tests/test_smtpclient.rb +81 -0
  115. data/tests/test_smtpserver.rb +93 -0
  116. data/tests/test_spawn.rb +329 -0
  117. data/tests/test_ssl_args.rb +68 -0
  118. data/tests/test_timers.rb +146 -0
  119. data/tests/test_ud.rb +43 -0
  120. data/tests/testem.rb +31 -0
  121. metadata +197 -0
@@ -0,0 +1,31 @@
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
+ module EventMachine
27
+
28
+ VERSION = "0.12.3"
29
+
30
+ end
31
+
data/lib/evma.rb ADDED
@@ -0,0 +1,32 @@
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
+ 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,137 @@
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
+