eventmachine-win32 0.7.0 → 0.7.2

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.
data/LEGAL ADDED
@@ -0,0 +1,25 @@
1
+ LEGAL NOTICE INFORMATION
2
+ ------------------------
3
+
4
+ EventMachine is Copyright (C) 2006-07 by Francis Cianfrocca.
5
+
6
+ EventMachine is copyrighted software owned by Francis Cianfrocca
7
+ (blackhedd ... gmail.com). You may redistribute and/or modify this
8
+ software as long as you comply with either the terms of the GPL
9
+ (see the file GPL), or Ruby's license (see the file COPYING).
10
+
11
+ Your use of all the files in this distribution is controlled by these
12
+ license terms, except for those files specifically mentioned below:
13
+
14
+
15
+
16
+ setup.rb
17
+ This file is Copyright (C) 2000-2005 by Minero Aoki
18
+ You can distribute/modify this file under the terms of
19
+ the GNU LGPL, Lesser General Public License version 2.1.
20
+
21
+
22
+ lib/protocols/buftok.rb
23
+ This file is Copyright (C) 2007 by Tony Arcieri. This file is
24
+ covered by the terms of Ruby's License (see the file COPYING).
25
+
data/README CHANGED
@@ -1,12 +1,14 @@
1
- $Id: README 47 2006-05-15 21:42:38Z blackhedd $
1
+ $Id: README 317 2007-05-22 21:55:43Z blackhedd $
2
2
 
3
3
  = RUBY/EventMachine
4
4
 
5
5
  Homepage:: http://rubyeventmachine.com
6
- Copyright:: (C) 2006 by Francis Cianfrocca. All Rights Reserved.
6
+ Copyright:: (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
7
7
  Email:: gmail address: garbagecat10
8
8
 
9
- This program is made available under the terms of the Lesser-GPL version 2.
9
+ EventMachine is copyrighted free software made available under the terms
10
+ of either the GPL or Ruby's License. See the file COPYING for full licensing
11
+ information.
10
12
  See EventMachine and EventMachine::Connection for documentation and
11
13
  usage examples.
12
14
 
@@ -1,9 +1,14 @@
1
- $Id: RELEASE_NOTES 223 2006-08-08 20:30:41Z blackhedd $
1
+ $Id: RELEASE_NOTES 286 2006-11-28 03:18:18Z blackhedd $
2
2
 
3
3
  RUBY/EventMachine RELEASE NOTES
4
4
 
5
5
  --------------------------------------------------
6
- Version: 0.7.0, released xxAug06
6
+ Version: 0.7.1, released xxNov06
7
+ Added protocol handlers for line-oriented protocols.
8
+ Various bug fixes.
9
+
10
+ --------------------------------------------------
11
+ Version: 0.7.0, released 20Nov06
7
12
  Added a fix in em.cpp/ConnectToServer to fix a fatal exception that
8
13
  occurred in FreeBSD when connecting successfully to a remote server.
9
14
 
@@ -1,34 +1,23 @@
1
- # $Id: deferrable.rb 216 2006-07-17 10:20:42Z blackhedd $
1
+ # $Id: deferrable.rb 320 2007-05-22 22:12:59Z blackhedd $
2
2
  #
3
- # Author:: blackhedd (gmail address: garbagecat10).
4
- # Date:: 16 July 2006
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 16 Jul 2006
5
6
  #
6
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
7
- #
8
- # This program is made available under the terms of the GPL version 2.
9
- #
10
7
  # See EventMachine and EventMachine::Connection for documentation and
11
8
  # usage examples.
12
9
  #
13
10
  #----------------------------------------------------------------------------
14
11
  #
15
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
- #
17
- # Gmail: garbagecat10
18
- #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
19
15
  # This program is free software; you can redistribute it and/or modify
20
- # it under the terms of the GNU General Public License as published by
21
- # the Free Software Foundation; either version 2 of the License, or
22
- # (at your option) any later version.
23
- #
24
- # This program is distributed in the hope that it will be useful,
25
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
26
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
- # GNU General Public License for more details.
28
- #
29
- # You should have received a copy of the GNU General Public License
30
- # along with this program; if not, write to the Free Software
31
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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.
32
21
  #
33
22
  #---------------------------------------------------------------------------
34
23
  #
@@ -42,7 +31,7 @@ module Deferrable
42
31
  def callback &block
43
32
  return unless block
44
33
  if @deferred_status == :succeeded
45
- block.call
34
+ block.call(*@deferred_args)
46
35
  else
47
36
  @callbacks ||= []
48
37
  @callbacks << block
@@ -52,7 +41,7 @@ module Deferrable
52
41
  def errback &block
53
42
  return unless block
54
43
  if @deferred_status == :failed
55
- block.call
44
+ block.call(*@deferred_args)
56
45
  else
57
46
  @errbacks ||= []
58
47
  @errbacks << block
@@ -65,6 +54,18 @@ module Deferrable
65
54
  # user code will throw an argument exception.
66
55
  # Implementors of deferrable classes <b>must</b>
67
56
  # document the arguments they will supply to user callbacks.
57
+ #
58
+ # OBSERVE SOMETHING VERY SPECIAL here: you may call this method even
59
+ # on the INSIDE of a callback. This is very useful when a previously-registered
60
+ # callback wants to change the parameters that will be passed to subsequently-registered
61
+ # ones.
62
+ # --
63
+ # We're shifting callbacks off and discarding them as we execute them.
64
+ # This is valid because by definition callbacks are executed no more than
65
+ # once. It also has the magic effect of permitting recursive calls, which
66
+ # means that a callback can call #set_deferred_status and change the parameters
67
+ # that will be sent to subsequent callbacks down the chain.
68
+ #
68
69
  def set_deferred_status arg, *args
69
70
  @deferred_status = arg
70
71
  @deferred_args = args
@@ -72,18 +73,30 @@ module Deferrable
72
73
  when :succeeded
73
74
  if @callbacks
74
75
  while cb = @callbacks.shift
75
- cb.call *@deferred_args
76
+ cb.call(*@deferred_args)
76
77
  end
77
78
  end
78
79
  when :failed
79
80
  if @errbacks
80
81
  while eb = @errbacks.shift
81
- eb.call *@deferred_args
82
+ eb.call(*@deferred_args)
82
83
  end
83
84
  end
84
85
  end
85
86
  end
86
87
 
88
+ # Equivalent to set_deferred_status(:succeeded, ...)
89
+ #
90
+ def set_deferred_success *args
91
+ set_deferred_status :succeeded, *args
92
+ end
93
+
94
+ # Equivalent to set_deferred_status(:failed, ...)
95
+ #
96
+ def set_deferred_failure *args
97
+ set_deferred_status :failed, *args
98
+ end
99
+
87
100
  end
88
101
  end
89
102
 
@@ -1,34 +1,23 @@
1
- # $Id: eventable.rb 252 2006-09-02 19:23:20Z blackhedd $
1
+ # $Id: eventable.rb 320 2007-05-22 22:12:59Z blackhedd $
2
2
  #
3
- # Author:: blackhedd (gmail address: garbagecat10).
4
- # Date:: 16 July 2006
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 16 Jul 2006
5
6
  #
6
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
7
- #
8
- # This program is made available under the terms of the GPL version 2.
9
- #
10
7
  # See EventMachine and EventMachine::Connection for documentation and
11
8
  # usage examples.
12
9
  #
13
10
  #----------------------------------------------------------------------------
14
11
  #
15
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
- #
17
- # Gmail: garbagecat10
18
- #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
19
15
  # This program is free software; you can redistribute it and/or modify
20
- # it under the terms of the GNU General Public License as published by
21
- # the Free Software Foundation; either version 2 of the License, or
22
- # (at your option) any later version.
23
- #
24
- # This program is distributed in the hope that it will be useful,
25
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
26
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
- # GNU General Public License for more details.
28
- #
29
- # You should have received a copy of the GNU General Public License
30
- # along with this program; if not, write to the Free Software
31
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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.
32
21
  #
33
22
  #---------------------------------------------------------------------------
34
23
  #
@@ -0,0 +1,62 @@
1
+ # $Id: future.rb 320 2007-05-22 22:12:59Z blackhedd $
2
+ #
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
5
+ # Date:: 16 Jul 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 defines EventMachine::Deferrable#future, which requires
27
+ # that the rest of EventMachine::Deferrable has already been seen.
28
+ # (It's in deferrable.rb.)
29
+ #
30
+ # A future is a sugaring of a typical deferrable usage.
31
+
32
+ module EventMachine
33
+ module Deferrable
34
+
35
+ class << self
36
+ # Evaluate arg (which may be an expression or a block).
37
+ # What's the class of arg?
38
+ # If arg is an ordinary expression, then return it.
39
+ # If arg is deferrable (responds to :set_deferred_status),
40
+ # then look at the arguments. If either callback or errback
41
+ # are defined, then use them. If neither are defined, then
42
+ # use the supplied block (if any) as the callback.
43
+ # Then return arg.
44
+ def future arg, cb=nil, eb=nil, &blk
45
+ arg = arg.call if arg.respond_to?(:call)
46
+
47
+ if arg.respond_to?(:set_deferred_status)
48
+ if cb || eb
49
+ arg.callback(&cb) if cb
50
+ arg.errback(&eb) if eb
51
+ else
52
+ arg.callback(&blk) if blk
53
+ end
54
+ end
55
+
56
+ arg
57
+ end
58
+ end
59
+
60
+ end
61
+ end
62
+
@@ -1,34 +1,23 @@
1
- # $Id: eventmachine.rb 283 2006-11-22 14:44:38Z blackhedd $
1
+ # $Id: eventmachine.rb 319 2007-05-22 22:11:18Z blackhedd $
2
2
  #
3
- # Author:: blackhedd (gmail address: garbagecat10).
3
+ # Author:: Francis Cianfrocca (gmail: blackhedd)
4
+ # Homepage:: http://rubyeventmachine.com
4
5
  # Date:: 8 Apr 2006
5
6
  #
6
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
7
- #
8
- # This program is made available under the terms of the GPL version 2.
9
- #
10
7
  # See EventMachine and EventMachine::Connection for documentation and
11
8
  # usage examples.
12
9
  #
13
10
  #----------------------------------------------------------------------------
14
11
  #
15
- # Copyright (C) 2006 by Francis Cianfrocca. All Rights Reserved.
16
- #
17
- # Gmail: garbagecat10
18
- #
12
+ # Copyright (C) 2006-07 by Francis Cianfrocca. All Rights Reserved.
13
+ # Gmail: blackhedd
14
+ #
19
15
  # This program is free software; you can redistribute it and/or modify
20
- # it under the terms of the GNU General Public License as published by
21
- # the Free Software Foundation; either version 2 of the License, or
22
- # (at your option) any later version.
23
- #
24
- # This program is distributed in the hope that it will be useful,
25
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
26
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
- # GNU General Public License for more details.
28
- #
29
- # You should have received a copy of the GNU General Public License
30
- # along with this program; if not, write to the Free Software
31
- # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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.
32
21
  #
33
22
  #---------------------------------------------------------------------------
34
23
  #
@@ -36,6 +25,7 @@
36
25
 
37
26
 
38
27
  #-- Select in a library based on a global variable.
28
+ $eventmachine_library ||= nil
39
29
  case $eventmachine_library
40
30
  when :pure_ruby
41
31
  require 'pr_eventmachine'
@@ -54,6 +44,7 @@ end
54
44
 
55
45
  require "eventmachine_version"
56
46
  require 'em/deferrable'
47
+ require 'em/future'
57
48
  require 'em/eventable'
58
49
  #-- Additional requires are at the BOTTOM of this file, because they
59
50
  #-- depend on stuff defined in here. Refactor that someday.
@@ -157,50 +148,59 @@ require 'em/eventable'
157
148
  module EventMachine
158
149
 
159
150
 
160
- # EventMachine::run initializes and runs an event loop.
161
- # This method only returns if user-callback code calls stop_event_loop.
162
- # Use the supplied block to define your clients and servers.
163
- # The block is called by EventMachine::run immediately after initializing
164
- # its internal event loop but <i>before</i> running the loop.
165
- # Therefore this block is the right place to call start_server if you
166
- # want to accept connections from remote clients.
167
- #
168
- # For programs that are structured as servers, it's usually appropriate
169
- # to start an event loop by calling EventMachine::run, and let it
170
- # run forever. It's also possible to use EventMachine::run to make a single
171
- # client-connection to a remote server, process the data flow from that
172
- # single connection, and then call stop_event_loop to force EventMachine::run
173
- # to return. Your program will then continue from the point immediately
174
- # following the call to EventMachine::run.
175
- #
176
- # You can of course do both client and servers simultaneously in the same program.
177
- # One of the strengths of the event-driven programming model is that the
178
- # handling of network events on many different connections will be interleaved,
179
- # and scheduled according to the actual events themselves. This maximizes
180
- # efficiency.
181
- #
182
- # === Server usage example
183
- #
184
- # See the text at the top of this file for an example of an echo server.
185
- #
186
- # === Client usage example
187
- #
188
- # See the description of stop_event_loop for an extremely simple client example.
189
- #
190
- #--
191
- # Obsoleted the use_threads mechanism.
192
- #
193
- def EventMachine::run &block
194
- #def EventMachine::run use_threads = true, &block
195
- @conns = {}
196
- @acceptors = {}
197
- @timers = {}
198
- initialize_event_machine
199
- block and add_timer 0, block
200
- #use_threads ? run_machine : run_machine_without_threads
201
- run_machine
202
- release_machine
203
- end
151
+ # EventMachine::run initializes and runs an event loop.
152
+ # This method only returns if user-callback code calls stop_event_loop.
153
+ # Use the supplied block to define your clients and servers.
154
+ # The block is called by EventMachine::run immediately after initializing
155
+ # its internal event loop but <i>before</i> running the loop.
156
+ # Therefore this block is the right place to call start_server if you
157
+ # want to accept connections from remote clients.
158
+ #
159
+ # For programs that are structured as servers, it's usually appropriate
160
+ # to start an event loop by calling EventMachine::run, and let it
161
+ # run forever. It's also possible to use EventMachine::run to make a single
162
+ # client-connection to a remote server, process the data flow from that
163
+ # single connection, and then call stop_event_loop to force EventMachine::run
164
+ # to return. Your program will then continue from the point immediately
165
+ # following the call to EventMachine::run.
166
+ #
167
+ # You can of course do both client and servers simultaneously in the same program.
168
+ # One of the strengths of the event-driven programming model is that the
169
+ # handling of network events on many different connections will be interleaved,
170
+ # and scheduled according to the actual events themselves. This maximizes
171
+ # efficiency.
172
+ #
173
+ # === Server usage example
174
+ #
175
+ # See the text at the top of this file for an example of an echo server.
176
+ #
177
+ # === Client usage example
178
+ #
179
+ # See the description of stop_event_loop for an extremely simple client example.
180
+ #
181
+ #--
182
+ # Obsoleted the use_threads mechanism.
183
+ # 25Nov06: Added the begin/ensure block. We need to be sure that release_machine
184
+ # gets called even if an exception gets thrown within any of the user code
185
+ # that the event loop runs. The best way to see this is to run a unit
186
+ # test with two functions, each of which calls EventMachine#run and each of
187
+ # which throws something inside of #run. Without the ensure, the second test
188
+ # will start without release_machine being called and will immediately throw
189
+ # a C++ runtime error.
190
+ #
191
+ def EventMachine::run &block
192
+ @conns = {}
193
+ @acceptors = {}
194
+ @timers = {}
195
+ begin
196
+ initialize_event_machine
197
+ block and add_timer 0, block
198
+ run_machine
199
+ ensure
200
+ release_machine
201
+ end
202
+ end
203
+
204
204
 
205
205
  # +deprecated+
206
206
  #--
@@ -259,6 +259,7 @@ module EventMachine
259
259
  # check too many timers!
260
260
  s = add_oneshot_timer((interval * 1000).to_i)
261
261
  @timers[s] = code
262
+ s
262
263
  end
263
264
  end
264
265
 
@@ -290,6 +291,13 @@ module EventMachine
290
291
  end
291
292
  end
292
293
 
294
+ #--
295
+ #
296
+ def EventMachine::cancel_timer signature
297
+ @timers[signature] = proc{} if @timers.has_key?(signature)
298
+ end
299
+ private_class_method :cancel_timer
300
+
293
301
 
294
302
  # stop_event_loop may called from within a callback method
295
303
  # while EventMachine's processing loop is running.
@@ -594,6 +602,37 @@ module EventMachine
594
602
  end
595
603
 
596
604
 
605
+
606
+
607
+ # Make a connection to a Unix-domain socket. This is not implemented on Windows platforms.
608
+ # The parameter socketname is a String which identifies the Unix-domain socket you want
609
+ # to connect to. socketname is the name of a file on your local system, and in most cases
610
+ # is a fully-qualified path name. Make sure that your process has enough local permissions
611
+ # to open the Unix-domain socket.
612
+ # See also the documentation for #connect_server. This method behaves like #connect_server
613
+ # in all respects except for the fact that it connects to a local Unix-domain
614
+ # socket rather than a TCP socket.
615
+ # NOTE: this functionality will soon be subsumed into the #connect method. This method
616
+ # will still be supported as an alias.
617
+ #--
618
+ # For making connections to Unix-domain sockets.
619
+ # Eventually this has to get properly documented and unified with the TCP-connect methods.
620
+ # Note how nearly identical this is to EventMachine#connect
621
+ def EventMachine::connect_unix_domain socketname, handler=nil
622
+ klass = if (handler and handler.is_a?(Class))
623
+ handler
624
+ else
625
+ Class.new( Connection ) {handler and include handler}
626
+ end
627
+
628
+ s = connect_unix_server socketname
629
+ c = klass.new s
630
+ @conns[s] = c
631
+ block_given? and yield c
632
+ c
633
+ end
634
+
635
+
597
636
  # EventMachine#open_datagram_socket is for support of UDP-based
598
637
  # protocols. Its usage is similar to that of EventMachine#start_server.
599
638
  # It takes three parameters: an IP address (which must be valid
@@ -763,6 +802,18 @@ module EventMachine
763
802
  @threadqueue << [op,callback]
764
803
  end
765
804
 
805
+ # A wrapper over the setuid system call. Particularly useful when opening a network
806
+ # server on a privileged port because you can use this call to drop privileges
807
+ # after opening the port.
808
+ # This method has no effective implementation on Windows or in the pure-Ruby
809
+ # implementation of EventMachine.
810
+ # Call #set_effective_user by passing it a string containing the effective name
811
+ # of the user whose privilege-level your process should attain.
812
+ # This method is intended for use in enforcing security requirements, consequently
813
+ # it will throw a fatal error and end your program if it fails.
814
+ def self::set_effective_user username
815
+ EventMachine::setuid_string username
816
+ end
766
817
 
767
818
 
768
819
  private
@@ -1055,6 +1106,45 @@ class Connection
1055
1106
  EventMachine::reconnect server, port, self
1056
1107
  end
1057
1108
 
1109
+
1110
+
1111
+
1112
+ #
1113
+ #
1114
+ #
1115
+ class EventMachine::PeriodicTimer
1116
+ def initialize *args, &block
1117
+ @interval = args.shift
1118
+ @code = args.shift || block
1119
+ schedule
1120
+ end
1121
+ def schedule
1122
+ EventMachine::add_timer @interval, proc {self.fire}
1123
+ end
1124
+ def fire
1125
+ @code.call
1126
+ schedule unless @cancelled
1127
+ end
1128
+ def cancel
1129
+ @cancelled = true
1130
+ end
1131
+ end
1132
+
1133
+ #
1134
+ #
1135
+ #
1136
+ class EventMachine::Timer
1137
+ def initialize *args, &block
1138
+ @signature = EventMachine::add_timer(*args, &block)
1139
+ end
1140
+ def cancel
1141
+ EventMachine.send :cancel_timer, @signature
1142
+ end
1143
+ end
1144
+
1145
+
1146
+
1147
+
1058
1148
  end
1059
1149
 
1060
1150