write_message2 -> write_message

This commit is contained in:
Steven Fackler 2016-09-20 16:58:04 -04:00
parent c3bd2eba39
commit 6de2fb038c
4 changed files with 33 additions and 31 deletions

View File

@ -274,7 +274,7 @@ impl InnerConnection {
}
let options = options.iter().map(|&(ref a, ref b)| (&**a, &**b));
try!(conn.stream.write_message2(|buf| frontend::startup_message(options, buf)));
try!(conn.stream.write_message(|buf| frontend::startup_message(options, buf)));
try!(conn.stream.flush());
try!(conn.handle_auth(user));
@ -370,7 +370,7 @@ impl InnerConnection {
let pass = try!(user.password.ok_or_else(|| {
ConnectError::ConnectParams("a password was requested but not provided".into())
}));
try!(self.stream.write_message2(|buf| frontend::password_message(&pass, buf)));
try!(self.stream.write_message(|buf| frontend::password_message(&pass, buf)));
try!(self.stream.flush());
}
backend::Message::AuthenticationMD5Password { salt } => {
@ -378,7 +378,7 @@ impl InnerConnection {
ConnectError::ConnectParams("a password was requested but not provided".into())
}));
let output = authentication::md5_hash(user.user.as_bytes(), pass.as_bytes(), salt);
try!(self.stream.write_message2(|buf| frontend::password_message(&output, buf)));
try!(self.stream.write_message(|buf| frontend::password_message(&output, buf)));
try!(self.stream.flush());
}
backend::Message::AuthenticationKerberosV5 |
@ -406,9 +406,9 @@ impl InnerConnection {
fn raw_prepare(&mut self, stmt_name: &str, query: &str) -> Result<(Vec<Type>, Vec<Column>)> {
debug!("preparing query with name `{}`: {}", stmt_name, query);
try!(self.stream.write_message2(|buf| frontend::parse(stmt_name, query, None, buf)));
try!(self.stream.write_message2(|buf| frontend::describe(b'S', stmt_name, buf)));
try!(self.stream.write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
try!(self.stream.write_message(|buf| frontend::parse(stmt_name, query, None, buf)));
try!(self.stream.write_message(|buf| frontend::describe(b'S', stmt_name, buf)));
try!(self.stream.write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
try!(self.stream.flush());
match try!(self.read_message()) {
@ -465,11 +465,11 @@ impl InnerConnection {
return DbError::new(fields);
}
backend::Message::CopyInResponse { .. } => {
try!(self.stream.write_message2(|buf| {
try!(self.stream.write_message(|buf| {
frontend::copy_fail("COPY queries cannot be directly executed", buf)
}));
try!(self.stream
.write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
.write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
try!(self.stream.flush());
}
backend::Message::CopyOutResponse { .. } => {
@ -509,7 +509,7 @@ impl InnerConnection {
{
let info = SessionInfo::new(&self.parameters);
let r = self.stream.write_message2(|buf| {
let r = self.stream.write_message(|buf| {
frontend::bind(portal_name,
&stmt_name,
Some(1),
@ -531,8 +531,8 @@ impl InnerConnection {
}
}
try!(self.stream.write_message2(|buf| frontend::execute(portal_name, row_limit, buf)));
try!(self.stream.write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
try!(self.stream.write_message(|buf| frontend::execute(portal_name, row_limit, buf)));
try!(self.stream.write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
try!(self.stream.flush());
match try!(self.read_message()) {
@ -587,8 +587,8 @@ impl InnerConnection {
}
fn close_statement(&mut self, name: &str, type_: u8) -> Result<()> {
try!(self.stream.write_message2(|buf| frontend::close(type_, name, buf)));
try!(self.stream.write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
try!(self.stream.write_message(|buf| frontend::close(type_, name, buf)));
try!(self.stream.write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
try!(self.stream.flush());
let resp = match try!(self.read_message()) {
backend::Message::CloseComplete => Ok(()),
@ -798,7 +798,7 @@ impl InnerConnection {
fn quick_query(&mut self, query: &str) -> Result<Vec<Vec<Option<String>>>> {
check_desync!(self);
debug!("executing query: {}", query);
try!(self.stream.write_message2(|buf| frontend::query(query, buf)));
try!(self.stream.write_message(|buf| frontend::query(query, buf)));
try!(self.stream.flush());
let mut result = vec![];
@ -811,11 +811,11 @@ impl InnerConnection {
.collect());
}
backend::Message::CopyInResponse { .. } => {
try!(self.stream.write_message2(|buf| {
try!(self.stream.write_message(|buf| {
frontend::copy_fail("COPY queries cannot be directly executed", buf)
}));
try!(self.stream
.write_message2(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
.write_message(|buf| Ok::<(), std_io::Error>(frontend::sync(buf))));
try!(self.stream.flush());
}
backend::Message::ErrorResponse { fields } => {
@ -830,7 +830,7 @@ impl InnerConnection {
fn finish_inner(&mut self) -> Result<()> {
check_desync!(self);
try!(self.stream.write_message2(|buf| Ok::<(), std_io::Error>(frontend::terminate(buf))));
try!(self.stream.write_message(|buf| Ok::<(), std_io::Error>(frontend::terminate(buf))));
try!(self.stream.flush());
Ok(())
}

View File

@ -39,7 +39,7 @@ impl MessageStream {
self.stream.get_ref()
}
pub fn write_message2<F, E>(&mut self, f: F) -> Result<(), E>
pub fn write_message<F, E>(&mut self, f: F) -> Result<(), E>
where F: FnOnce(&mut Vec<u8>) -> Result<(), E>,
E: From<io::Error>
{

View File

@ -354,8 +354,8 @@ impl<'trans, 'stmt> LazyRows<'trans, 'stmt> {
fn execute(&mut self) -> Result<()> {
let mut conn = self.stmt.conn().conn.borrow_mut();
try!(conn.stream.write_message2(|buf| frontend::execute(&self.name, self.row_limit, buf)));
try!(conn.stream.write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
try!(conn.stream.write_message(|buf| frontend::execute(&self.name, self.row_limit, buf)));
try!(conn.stream.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
try!(conn.stream.flush());
conn.read_rows(&mut self.data).map(|more_rows| self.more_rows = more_rows)
}

View File

@ -146,11 +146,11 @@ impl<'conn> Statement<'conn> {
break;
}
backend::Message::CopyInResponse { .. } => {
try!(conn.stream.write_message2(|buf| {
try!(conn.stream.write_message(|buf| {
frontend::copy_fail("COPY queries cannot be directly executed", buf)
}));
try!(conn.stream
.write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
try!(conn.stream.flush());
}
backend::Message::CopyOutResponse { .. } => {
@ -297,16 +297,18 @@ impl<'conn> Statement<'conn> {
match fill_copy_buf(&mut buf, r, &info) {
Ok(0) => break,
Ok(len) => {
try!(info.conn.stream.write_message2(|out| frontend::copy_data(&buf[..len], out)));
try!(info
.conn
.stream.write_message(|out| frontend::copy_data(&buf[..len], out)));
}
Err(err) => {
try!(info.conn.stream.write_message2(|buf| frontend::copy_fail("", buf)));
try!(info.conn.stream.write_message(|buf| frontend::copy_fail("", buf)));
try!(info.conn
.stream
.write_message2(|buf| Ok::<(), io::Error>(frontend::copy_done(buf))));
.write_message(|buf| Ok::<(), io::Error>(frontend::copy_done(buf))));
try!(info.conn
.stream
.write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
try!(info.conn.stream.flush());
match try!(info.conn.read_message()) {
backend::Message::ErrorResponse { .. } => {
@ -323,8 +325,8 @@ impl<'conn> Statement<'conn> {
}
}
try!(info.conn.stream.write_message2(|buf| Ok::<(), io::Error>(frontend::copy_done(buf))));
try!(info.conn.stream.write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
try!(info.conn.stream.write_message(|buf| Ok::<(), io::Error>(frontend::copy_done(buf))));
try!(info.conn.stream.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
try!(info.conn.stream.flush());
let num = match try!(info.conn.read_message()) {
@ -374,10 +376,10 @@ impl<'conn> Statement<'conn> {
(format, column_formats)
}
backend::Message::CopyInResponse { .. } => {
try!(conn.stream.write_message2(|buf| frontend::copy_fail("", buf)));
try!(conn.stream.write_message(|buf| frontend::copy_fail("", buf)));
try!(conn.stream
.write_message2(|buf| Ok::<(), io::Error>(frontend::copy_done(buf))));
try!(conn.stream.write_message2(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
.write_message(|buf| Ok::<(), io::Error>(frontend::copy_done(buf))));
try!(conn.stream.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
try!(conn.stream.flush());
match try!(conn.read_message()) {
backend::Message::ErrorResponse { .. } => {