lib/fastdfs-client/socket.rb in fastdfs-client-1.0.2 vs lib/fastdfs-client/socket.rb in fastdfs-client-1.2.0

- old
+ new

@@ -27,16 +27,17 @@ def close @socket.close if connected end - def connection + def connection(&block) if @socket.nil? || !connected @socket = Timeout.timeout(@connection_timeout) do TCPSocket.new(@host, @port) end end + yield if block_given? end def connected !@socket.closed? end @@ -56,10 +57,10 @@ private def parseHeader err_msg = nil err_msg = "recv package size #{@header} is not equal #{@header_len}, cmd: #{@cmd}" unless @header.length == @header_len || err_msg - err_msg = "recv cmd: #{@header[8]} is not correct, expect cmd: #{CMD::RESP_CODE}, cmd: #{@cmd}" unless @header[8] == CMD::RESP_CODE || err_msg + err_msg = "recv cmd: #{@header[8]} is not correct, expect recv code: #{CMD::RESP_CODE}, cmd: #{@cmd}" unless @header[8] == CMD::RESP_CODE || err_msg err_msg = "recv erron #{@header[9]}, 0 is correct cmd: #{@cmd}" unless @header[9] == 0 || err_msg {status: err_msg.nil?, err_msg: err_msg} end def timeout_recv \ No newline at end of file