Permalink
Browse files

fixed bug with connecting to peers

  • Loading branch information...
Arya Asemanfar
Arya Asemanfar committed Jun 25, 2009
1 parent 3e3c3bf commit eaaecbab49bfb0e94fe0ed36617213e0203d1d87
Showing with 8 additions and 6 deletions.
  1. +1 −1 Rakefile
  2. +2 −1 lib/pandemic/connection_pool.rb
  3. +1 −1 lib/pandemic/server_side/peer.rb
  4. +3 −2 lib/pandemic/server_side/server.rb
  5. +1 −1 pandemic.gemspec
View
@@ -2,7 +2,7 @@ require 'rubygems'
require 'rake'
require 'echoe'
-Echoe.new('pandemic', '0.3.6') do |p|
+Echoe.new('pandemic', '0.3.7') do |p|
p.description = "Distribute MapReduce to any of the workers and it will spread, like a pandemic."
p.url = "https://github.com/arya/pandemic/"
p.author = "Arya Asemanfar"
@@ -11,6 +11,7 @@ def initialize(options = {})
@connections = []
@max_connections = options[:max_connections] || 10
@min_connections = options[:min_connections] || 1
+ @connect_at_define = options.include?(:connect_at_define) ? options[:connect_at_define] : true
@timeout = options[:timeout] || 3
end
@@ -36,7 +37,7 @@ def create_connection(&block)
end
else
@create_connection = block
- connect
+ connect if @connect_at_define
end
end
@@ -86,7 +86,7 @@ def add_incoming_connection(conn)
private
def initialize_connection_pool
return if @connection_pool
- @connection_pool = ConnectionPool.new
+ @connection_pool = ConnectionPool.new(:connect_at_define => false)
@connection_pool.create_connection do
connection = nil
@@ -50,17 +50,18 @@ def handler=(handler)
def start
raise "You must specify a handler" unless @handler
- debug("Listening")
@listener = TCPServer.new(@host, @port)
@running = true
@running_since = Time.now
+ debug("Connecting to peers")
@peers.values.each { |peer| peer.connect }
-
+
@listener_thread = Thread.new do
begin
while @running
begin
+ debug("Listening")
conn = @listener.accept
Thread.new(conn) { |c| handle_connection(c) }
rescue Errno::ECONNABORTED, Errno::EINTR
View
@@ -2,7 +2,7 @@
Gem::Specification.new do |s|
s.name = %q{pandemic}
- s.version = "0.3.6"
+ s.version = "0.3.7"
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
s.authors = ["Arya Asemanfar"]

0 comments on commit eaaecba

Please sign in to comment.