add back in logging and size checks around all socket receive's

This commit is contained in:
Mike Dirolf 2009-03-06 10:02:43 -05:00
parent 3ef1a6dfa8
commit 8b9bcb1e63
2 changed files with 22 additions and 4 deletions

View File

@ -18,6 +18,9 @@ require 'mongo/message'
require 'mongo/util/byte_buffer' require 'mongo/util/byte_buffer'
require 'mongo/util/bson' require 'mongo/util/bson'
require 'logger'
LOG = Logger.new('recv_file.log', 'daily')
module XGen module XGen
module Mongo module Mongo
module Driver module Driver
@ -165,7 +168,10 @@ module XGen
def read_response_header def read_response_header
header_buf = ByteBuffer.new 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 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 header_buf.rewind
@result_flags = header_buf.get_int @result_flags = header_buf.get_int
@ -200,10 +206,16 @@ module XGen
def object_from_stream def object_from_stream
buf = ByteBuffer.new 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 buf.rewind
size = buf.get_int 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 @n_remaining -= 1
buf.rewind buf.rewind
BSON.new(@db).deserialize(buf) BSON.new(@db).deserialize(buf)

View File

@ -16,6 +16,9 @@
require 'mongo/util/byte_buffer' require 'mongo/util/byte_buffer'
require 'logger'
LOG = Logger.new('recv_file.log', 'daily')
module XGen module XGen
module Mongo module Mongo
module Driver module Driver
@ -30,7 +33,10 @@ module XGen
def read_header(db) def read_header(db)
@buf.rewind @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 raise "Short read for DB response header: expected #{HEADER_SIZE} bytes, saw #{@buf.size}" unless @buf.size == HEADER_SIZE
@buf.rewind @buf.rewind
@size = @buf.get_int @size = @buf.get_int