Use Read::read_exact

This commit is contained in:
Steven Fackler
2016-03-03 21:19:46 -08:00
parent 86a9eb82a1
commit 16bc4b951d
3 changed files with 4 additions and 22 deletions

View File

@@ -5,7 +5,6 @@ use std::time::Duration;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use types::Oid;
use util;
use priv_io::StreamOptions;
use self::BackendMessage::*;
@@ -438,7 +437,7 @@ fn read_data_row<R: BufRead>(buf: &mut R) -> io::Result<BackendMessage> {
-1 => None,
len => {
let mut data = vec![0; len as usize];
try!(util::read_all(buf, &mut data));
try!(buf.read_exact(&mut data));
Some(data)
}
};
@@ -455,7 +454,7 @@ fn read_auth_message<R: Read>(buf: &mut R) -> io::Result<BackendMessage> {
3 => AuthenticationCleartextPassword,
5 => {
let mut salt = [0; 4];
try!(util::read_all(buf, &mut salt));
try!(buf.read_exact(&mut salt));
AuthenticationMD5Password { salt: salt }
}
6 => AuthenticationSCMCredential,

View File

@@ -11,7 +11,6 @@ pub use self::slice::Slice;
pub use self::types::Type;
use {Result, SessionInfoNew, InnerConnection, OtherNew, WrongTypeNew, FieldNew};
use error::Error;
use util;
/// Generates a simple implementation of `ToSql::accepts` which accepts the
/// types passed to it.
@@ -409,7 +408,7 @@ impl FromSql for HashMap<String, Option<String>> {
for _ in 0..count {
let key_len = try!(raw.read_i32::<BigEndian>());
let mut key = vec![0; key_len as usize];
try!(util::read_all(raw, &mut key));
try!(raw.read_exact(&mut key));
let key = match String::from_utf8(key) {
Ok(key) => key,
Err(err) => return Err(Error::Conversion(Box::new(err))),
@@ -420,7 +419,7 @@ impl FromSql for HashMap<String, Option<String>> {
None
} else {
let mut val = vec![0; val_len as usize];
try!(util::read_all(raw, &mut val));
try!(raw.read_exact(&mut val));
match String::from_utf8(val) {
Ok(val) => Some(val),
Err(err) => return Err(Error::Conversion(Box::new(err))),

View File

@@ -1,19 +1,3 @@
use std::io;
use std::io::prelude::*;
pub fn parse_update_count(tag: String) -> u64 {
tag.split(' ').last().unwrap().parse().unwrap_or(0)
}
pub fn read_all<R: Read>(r: &mut R, mut buf: &mut [u8]) -> io::Result<()> {
while !buf.is_empty() {
match r.read(buf) {
Ok(0) => return Err(io::Error::new(io::ErrorKind::Other, "unexpected EOF")),
#[cfg_attr(rustfmt, rustfmt_skip)]
Ok(len) => buf = &mut {buf}[len..],
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
Err(e) => return Err(e),
}
}
Ok(())
}