brianmario-eventmachine 0.12.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/COPYING +60 -0
  2. data/DEFERRABLES +138 -0
  3. data/EPOLL +141 -0
  4. data/GNU +281 -0
  5. data/KEYBOARD +38 -0
  6. data/LEGAL +25 -0
  7. data/LIGHTWEIGHT_CONCURRENCY +72 -0
  8. data/PURE_RUBY +77 -0
  9. data/README +74 -0
  10. data/RELEASE_NOTES +96 -0
  11. data/SMTP +9 -0
  12. data/SPAWNED_PROCESSES +93 -0
  13. data/TODO +10 -0
  14. data/eventmachine.gemspec +15 -0
  15. data/ext/binder.cpp +126 -0
  16. data/ext/binder.h +48 -0
  17. data/ext/cmain.cpp +553 -0
  18. data/ext/cplusplus.cpp +172 -0
  19. data/ext/ed.cpp +1473 -0
  20. data/ext/ed.h +361 -0
  21. data/ext/em.cpp +1890 -0
  22. data/ext/em.h +170 -0
  23. data/ext/emwin.cpp +300 -0
  24. data/ext/emwin.h +94 -0
  25. data/ext/epoll.cpp +26 -0
  26. data/ext/epoll.h +25 -0
  27. data/ext/eventmachine.h +90 -0
  28. data/ext/eventmachine_cpp.h +94 -0
  29. data/ext/extconf.rb +203 -0
  30. data/ext/files.cpp +94 -0
  31. data/ext/files.h +65 -0
  32. data/ext/kb.cpp +368 -0
  33. data/ext/page.cpp +107 -0
  34. data/ext/page.h +51 -0
  35. data/ext/pipe.cpp +327 -0
  36. data/ext/project.h +119 -0
  37. data/ext/rubymain.cpp +678 -0
  38. data/ext/sigs.cpp +89 -0
  39. data/ext/sigs.h +32 -0
  40. data/ext/ssl.cpp +408 -0
  41. data/ext/ssl.h +86 -0
  42. data/lib/em/deferrable.rb +208 -0
  43. data/lib/em/eventable.rb +39 -0
  44. data/lib/em/future.rb +62 -0
  45. data/lib/em/messages.rb +66 -0
  46. data/lib/em/processes.rb +68 -0
  47. data/lib/em/spawnable.rb +88 -0
  48. data/lib/em/streamer.rb +112 -0
  49. data/lib/eventmachine.rb +1756 -0
  50. data/lib/eventmachine_version.rb +31 -0
  51. data/lib/evma.rb +32 -0
  52. data/lib/evma/callback.rb +32 -0
  53. data/lib/evma/container.rb +75 -0
  54. data/lib/evma/factory.rb +77 -0
  55. data/lib/evma/protocol.rb +87 -0
  56. data/lib/evma/reactor.rb +48 -0
  57. data/lib/jeventmachine.rb +132 -0
  58. data/lib/pr_eventmachine.rb +1011 -0
  59. data/lib/protocols/buftok.rb +127 -0
  60. data/lib/protocols/header_and_content.rb +129 -0
  61. data/lib/protocols/httpcli2.rb +784 -0
  62. data/lib/protocols/httpclient.rb +264 -0
  63. data/lib/protocols/line_and_text.rb +122 -0
  64. data/lib/protocols/linetext2.rb +163 -0
  65. data/lib/protocols/postgres.rb +261 -0
  66. data/lib/protocols/saslauth.rb +179 -0
  67. data/lib/protocols/smtpclient.rb +308 -0
  68. data/lib/protocols/smtpserver.rb +543 -0
  69. data/lib/protocols/stomp.rb +130 -0
  70. data/lib/protocols/tcptest.rb +57 -0
  71. data/setup.rb +1585 -0
  72. metadata +126 -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.2"
29
+
30
+ end
31
+
@@ -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,132 @@
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
+
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
+ def self.initialize_event_machine
53
+ @em = JEM.new
54
+ end
55
+ def self.release_machine
56
+ @em = nil
57
+ end
58
+ def self.add_oneshot_timer interval
59
+ @em.installOneshotTimer interval
60
+ end
61
+ def self.run_machine
62
+ @em.run
63
+ end
64
+ def self.stop
65
+ @em.stop
66
+ end
67
+ def self.start_tcp_server server, port
68
+ @em.startTcpServer server, port
69
+ end
70
+ def self.stop_tcp_server sig
71
+ @em.stopTcpServer sig
72
+ end
73
+ def self.start_unix_server filename
74
+ # TEMPORARILY unsupported until someone figures out how to do it.
75
+ raise "unsupported on this platform"
76
+ end
77
+ def self.send_data sig, data, length
78
+ @em.sendData sig, data.to_java_bytes
79
+ end
80
+ def self.send_datagram sig, data, length, address, port
81
+ @em.sendDatagram sig, data, length, address, port
82
+ end
83
+ def self.connect_server server, port
84
+ @em.connectTcpServer server, port
85
+ end
86
+ def self.close_connection sig, after_writing
87
+ @em.closeConnection sig, after_writing
88
+ end
89
+ def self.set_comm_inactivity_timeout sig, interval
90
+ @em.setCommInactivityTimeout sig, interval
91
+ end
92
+ def self.start_tls sig
93
+ @em.startTls sig
94
+ end
95
+ def self.signal_loopbreak
96
+ @em.signalLoopbreak
97
+ end
98
+ def self.set_timer_quantum q
99
+ @em.setTimerQuantum q
100
+ end
101
+ def self.epoll
102
+ # Epoll is a no-op for Java.
103
+ # The latest Java versions run epoll when possible in NIO.
104
+ end
105
+ def self.set_rlimit_nofile n_descriptors
106
+ # Currently a no-op for Java.
107
+ end
108
+ def self.open_udp_socket server, port
109
+ @em.openUdpSocket server, port
110
+ end
111
+ def self.invoke_popen cmd
112
+ # TEMPORARILY unsupported until someone figures out how to do it.
113
+ raise "unsupported on this platform"
114
+ end
115
+ def self.read_keyboard
116
+ # TEMPORARILY unsupported until someone figures out how to do it.
117
+ raise "temporarily unsupported on this platform"
118
+ end
119
+ def self.set_max_timer_count num
120
+ # harmless no-op in Java. There's no built-in timer limit.
121
+ end
122
+ def self.library_type
123
+ :java
124
+ end
125
+
126
+ class Connection
127
+ def associate_callback_target sig
128
+ # No-op for the time being
129
+ end
130
+ end
131
+ end
132
+