lib/riakpb/client/rpc.rb in riakpb-0.2.2 vs lib/riakpb/client/rpc.rb in riakpb-0.2.3

- old
+ new

@@ -1,9 +1,9 @@ # Special thanks to: # # - Radar in #ruby-lang -# - xnotdotorg / arilerner[at]gmail.com - +# - xnotdotorg / arilerner[at]gmail.com - # http://blog.xnot.org/2008/11/16/communicating-from-ruby-to-erlang/ # require 'socket' module Riakpb @@ -65,18 +65,18 @@ # @return [True/False] whether or not the set client id request succeeded def set_client_id(socket) @set_c_id_req ||= assemble_request( Util::MessageCode::SET_CLIENT_ID_REQUEST, @set_client_id.serialize_to_string) - socket.send(@set_c_id_req, 0) - set_c_id_resp = socket.recv(@limit) + socket.write(@set_c_id_req) + set_c_id_resp = socket.sysread(@limit) resp_code, resp_msg = decode_message(set_c_id_resp) return(resp_code == Util::MessageCode::SET_CLIENT_ID_RESPONSE) end - + # Sends the request to the riak node # @param [Fixnum] mc The message code that identifies the request # @param [Protobuf::Message] pb_msg The protobuf message, if applicable, for the message code # @return [True/False] whether or not the set client id request succeeded def request(mc, pb_msg=nil) @@ -91,12 +91,12 @@ @req_message = assemble_request mc, pb_msg.serialize_to_string rescue NoMethodError @req_message = assemble_request mc end - socket.send(@req_message, 0) - self.parse_response socket.recv(@limit) + socket.write(@req_message) + self.parse_response socket.sysread(@limit) end while(false == (@response[:done] rescue true)) socket.flush end # with_socket @@ -124,10 +124,10 @@ # The below should never really happen if resp_mc != MC_RESPONSE_FOR[@req_message_code] raise FailedExchange.new(MC_RESPONSE_FOR[@req_message_code], @resp_message_codes, response_chunk, "failed_request") end end - + if response_chunk.size > 0 @response.parse_from_string response_chunk end @status = true