add back in logging and size checks around all socket receive's
This commit is contained in:
parent
3ef1a6dfa8
commit
8b9bcb1e63
|
@ -18,6 +18,9 @@ require 'mongo/message'
|
|||
require 'mongo/util/byte_buffer'
|
||||
require 'mongo/util/bson'
|
||||
|
||||
require 'logger'
|
||||
LOG = Logger.new('recv_file.log', 'daily')
|
||||
|
||||
module XGen
|
||||
module Mongo
|
||||
module Driver
|
||||
|
@ -165,7 +168,10 @@ module XGen
|
|||
|
||||
def read_response_header
|
||||
header_buf = ByteBuffer.new
|
||||
header_buf.put_array(@db.receive_full(RESPONSE_HEADER_SIZE).unpack("C*"))
|
||||
read = @db.receive_full(RESPONSE_HEADER_SIZE)
|
||||
header_buf.put_array(read.unpack("C*"))
|
||||
LOG.debug "resp head: #{read.inspect}\n"
|
||||
raise "BAD SIZE" unless read.length == RESPONSE_HEADER_SIZE
|
||||
raise "Short read for DB response header; expected #{RESPONSE_HEADER_SIZE} bytes, saw #{header_buf.length}" unless header_buf.length == RESPONSE_HEADER_SIZE
|
||||
header_buf.rewind
|
||||
@result_flags = header_buf.get_int
|
||||
|
@ -200,10 +206,16 @@ module XGen
|
|||
|
||||
def object_from_stream
|
||||
buf = ByteBuffer.new
|
||||
buf.put_array(@db.receive_full(4).unpack("C*"))
|
||||
read1 = @db.receive_full(4)
|
||||
buf.put_array(read1.unpack("C*"))
|
||||
LOG.debug "size: #{read1.inspect}\n"
|
||||
raise "BAD SIZE" unless read1.length == 4
|
||||
buf.rewind
|
||||
size = buf.get_int
|
||||
buf.put_array(@db.receive_full(size - 4).unpack("C*"), 4)
|
||||
read2 = @db.receive_full(size - 4)
|
||||
buf.put_array(read2.unpack("C*"), 4)
|
||||
LOG.debug "body: #{read2.inspect}\n"
|
||||
raise "BAD SIZE" unless read2.length == size - 4
|
||||
@n_remaining -= 1
|
||||
buf.rewind
|
||||
BSON.new(@db).deserialize(buf)
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
require 'mongo/util/byte_buffer'
|
||||
|
||||
require 'logger'
|
||||
LOG = Logger.new('recv_file.log', 'daily')
|
||||
|
||||
module XGen
|
||||
module Mongo
|
||||
module Driver
|
||||
|
@ -30,7 +33,10 @@ module XGen
|
|||
|
||||
def read_header(db)
|
||||
@buf.rewind
|
||||
@buf.put_array(db.receive_full(HEADER_SIZE).unpack("C*"))
|
||||
read = db.receive_full(HEADER_SIZE)
|
||||
@buf.put_array(read.unpack("C*"))
|
||||
LOG.debug "header: #{read.inspect}\n"
|
||||
raise "BAD SIZE" unless read.length == HEADER_SIZE
|
||||
raise "Short read for DB response header: expected #{HEADER_SIZE} bytes, saw #{@buf.size}" unless @buf.size == HEADER_SIZE
|
||||
@buf.rewind
|
||||
@size = @buf.get_int
|
||||
|
|
Loading…
Reference in New Issue