revent 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/revent/as_r.rb CHANGED
@@ -2,6 +2,8 @@ require 'rubygems'
2
2
  require 'eventmachine'
3
3
  require 'zlib'
4
4
  require 'logger'
5
+
6
+ require "#{File.dirname(__FILE__)}/synchronize"
5
7
  require "#{File.dirname(__FILE__)}/amf3/amf3"
6
8
 
7
9
  # AS clients are not reliable. For security, we close the connection immediately
@@ -75,12 +77,8 @@ module Revent
75
77
 
76
78
  def unbind
77
79
  @connected = false
78
- if @cons.nil?
79
- @me.on_close
80
- else
81
- @me.on_close(self)
82
- @cons.delete(self)
83
- end
80
+ @cons.synchronize { @cons.delete(self) }
81
+ @me.on_close(self)
84
82
  end
85
83
 
86
84
  # ----------------------------------------------------------------------------
@@ -168,8 +166,9 @@ EOF
168
166
  end
169
167
 
170
168
  @revent_cons = []
169
+ @revent_cons_mutex = Mutex.new
171
170
  EventMachine::start_server(host, port, ASRCon) do |con|
172
- @revent_cons << con
171
+ @revent_cons.synchronize { @revent_cons << con }
173
172
  con.me = self
174
173
  con.cons = @revent_cons
175
174
  on_connect(con)
data/lib/revent/r_r.rb CHANGED
@@ -2,6 +2,8 @@ require 'rubygems'
2
2
  require 'eventmachine'
3
3
  require 'stringio'
4
4
 
5
+ require "#{File.dirname(__FILE__)}/synchronize"
6
+
5
7
  module Revent
6
8
  # Included by both Revent::RRServer and Revent::RRClient.
7
9
  module RRCon
@@ -55,7 +57,7 @@ module Revent
55
57
  @me.on_close
56
58
  else
57
59
  @me.on_close(self)
58
- @cons.delete(self)
60
+ @cons.synchronize { @cons.delete(self) }
59
61
  end
60
62
  end
61
63
 
@@ -87,7 +89,7 @@ module Revent
87
89
  def start_server(host, port)
88
90
  @revent_cons = []
89
91
  EventMachine::start_server(host, port, RRCon) do |con|
90
- @revent_cons << con
92
+ @revent_cons.synchronize { @revent_cons << con }
91
93
  con.me = self
92
94
  con.cons = @revent_cons
93
95
  on_connect(con)
@@ -173,4 +175,4 @@ module Revent
173
175
  def on_error(cmd, value)
174
176
  end
175
177
  end
176
- end
178
+ end
@@ -0,0 +1,9 @@
1
+ class Object
2
+ def synchronize
3
+ mutex.synchronize { yield self }
4
+ end
5
+
6
+ def mutex
7
+ @mutex ||= Mutex.new
8
+ end
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: revent
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.3"
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngoc DAO Thanh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-17 00:00:00 +09:00
12
+ date: 2008-02-20 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -36,6 +36,7 @@ files:
36
36
  - lib/revent/r_r.rb
37
37
  - lib/revent/as_r.rb
38
38
  - lib/revent/Client.as
39
+ - lib/revent/synchronize.rb
39
40
  - lib/revent/amf3
40
41
  - lib/revent/amf3/app
41
42
  - lib/revent/amf3/app/fault_object.rb