Fixes for pairing.

This commit is contained in:
Kyle Banker 2009-11-24 13:55:59 -05:00
parent 20562e96ab
commit 154abda235
1 changed files with 14 additions and 5 deletions

View File

@ -294,7 +294,7 @@ module Mongo
end end
# Note: slave_ok can be true only when connecting to a single node. # Note: slave_ok can be true only when connecting to a single node.
if @nodes.length > 1 && !is_master && !@slave_ok if @nodes.length == 1 && !is_master && !@slave_ok
raise ConfigurationError, "Trying to connect directly to slave; " + raise ConfigurationError, "Trying to connect directly to slave; " +
"if this is what you want, specify :slave_ok => true." "if this is what you want, specify :slave_ok => true."
end end
@ -524,17 +524,26 @@ module Mongo
# Low-level method for sending a message on a socket. # Low-level method for sending a message on a socket.
# Requires a packed message and an available socket, # Requires a packed message and an available socket,
def send_message_on_socket(packed_message, socket) def send_message_on_socket(packed_message, socket)
begin
socket.send(packed_message, 0) socket.send(packed_message, 0)
rescue => ex
close
raise ConnectionFailure, "Operation failed with the following exception: #{ex}"
end
end end
# Low-level method for receiving data from socket. # Low-level method for receiving data from socket.
# Requires length and an available socket. # Requires length and an available socket.
def receive_message_on_socket(length, socket) def receive_message_on_socket(length, socket)
message = "" message = ""
while message.length < length do begin
chunk = socket.recv(length - message.length) while message.length < length do
raise "connection closed" unless chunk.length > 0 chunk = socket.recv(length - message.length)
message += chunk raise ConnectionFailure, "connection closed" unless chunk.length > 0
message += chunk
end
rescue => ex
raise ConnectionFailure, "Operation failed with the following exception: #{ex}"
end end
message message
end end