Import std io
This commit is contained in:
parent
455e22cec3
commit
19156b2434
34
src/lib.rs
34
src/lib.rs
@ -83,7 +83,7 @@ extern crate postgres_protocol;
|
|||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
use std::collections::{VecDeque, HashMap};
|
use std::collections::{VecDeque, HashMap};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::prelude::*;
|
use std::io;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -201,13 +201,13 @@ pub fn cancel_query<T>(params: T,
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bad_response() -> std::io::Error {
|
fn bad_response() -> io::Error {
|
||||||
std::io::Error::new(std::io::ErrorKind::InvalidInput,
|
io::Error::new(io::ErrorKind::InvalidInput,
|
||||||
"the server returned an unexpected response")
|
"the server returned an unexpected response")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn desynchronized() -> std::io::Error {
|
fn desynchronized() -> io::Error {
|
||||||
std::io::Error::new(std::io::ErrorKind::Other,
|
io::Error::new(io::ErrorKind::Other,
|
||||||
"communication with the server has desynchronized due to an earlier IO \
|
"communication with the server has desynchronized due to an earlier IO \
|
||||||
error")
|
error")
|
||||||
}
|
}
|
||||||
@ -322,7 +322,7 @@ impl InnerConnection {
|
|||||||
Ok(conn)
|
Ok(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_message_with_notification(&mut self) -> std::io::Result<backend::Message> {
|
fn read_message_with_notification(&mut self) -> io::Result<backend::Message> {
|
||||||
debug_assert!(!self.desynchronized);
|
debug_assert!(!self.desynchronized);
|
||||||
loop {
|
loop {
|
||||||
match try_desync!(self, self.stream.read_message()) {
|
match try_desync!(self, self.stream.read_message()) {
|
||||||
@ -341,7 +341,7 @@ impl InnerConnection {
|
|||||||
|
|
||||||
fn read_message_with_notification_timeout(&mut self,
|
fn read_message_with_notification_timeout(&mut self,
|
||||||
timeout: Duration)
|
timeout: Duration)
|
||||||
-> std::io::Result<Option<backend::Message>> {
|
-> io::Result<Option<backend::Message>> {
|
||||||
debug_assert!(!self.desynchronized);
|
debug_assert!(!self.desynchronized);
|
||||||
loop {
|
loop {
|
||||||
match try_desync!(self, self.stream.read_message_timeout(timeout)) {
|
match try_desync!(self, self.stream.read_message_timeout(timeout)) {
|
||||||
@ -359,7 +359,7 @@ impl InnerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn read_message_with_notification_nonblocking(&mut self)
|
fn read_message_with_notification_nonblocking(&mut self)
|
||||||
-> std::io::Result<Option<backend::Message>> {
|
-> io::Result<Option<backend::Message>> {
|
||||||
debug_assert!(!self.desynchronized);
|
debug_assert!(!self.desynchronized);
|
||||||
loop {
|
loop {
|
||||||
match try_desync!(self, self.stream.read_message_nonblocking()) {
|
match try_desync!(self, self.stream.read_message_nonblocking()) {
|
||||||
@ -376,7 +376,7 @@ impl InnerConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_message(&mut self) -> std::io::Result<backend::Message> {
|
fn read_message(&mut self) -> io::Result<backend::Message> {
|
||||||
loop {
|
loop {
|
||||||
match try!(self.read_message_with_notification()) {
|
match try!(self.read_message_with_notification()) {
|
||||||
backend::Message::NotificationResponse { process_id, channel, payload } => {
|
backend::Message::NotificationResponse { process_id, channel, payload } => {
|
||||||
@ -413,7 +413,7 @@ impl InnerConnection {
|
|||||||
backend::Message::AuthenticationSCMCredential |
|
backend::Message::AuthenticationSCMCredential |
|
||||||
backend::Message::AuthenticationGSS |
|
backend::Message::AuthenticationGSS |
|
||||||
backend::Message::AuthenticationSSPI => {
|
backend::Message::AuthenticationSSPI => {
|
||||||
return Err(ConnectError::Io(std::io::Error::new(std::io::ErrorKind::Other,
|
return Err(ConnectError::Io(io::Error::new(io::ErrorKind::Other,
|
||||||
"unsupported authentication")))
|
"unsupported authentication")))
|
||||||
}
|
}
|
||||||
backend::Message::ErrorResponse { fields } => return DbError::new_connect(fields),
|
backend::Message::ErrorResponse { fields } => return DbError::new_connect(fields),
|
||||||
@ -436,7 +436,7 @@ impl InnerConnection {
|
|||||||
|
|
||||||
try!(self.stream.write_message(|buf| frontend::parse(stmt_name, query, None, 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| frontend::describe(b'S', stmt_name, buf)));
|
||||||
try!(self.stream.write_message(|buf| Ok::<(), std::io::Error>(frontend::sync(buf))));
|
try!(self.stream.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
|
||||||
try!(self.stream.flush());
|
try!(self.stream.flush());
|
||||||
|
|
||||||
match try!(self.read_message()) {
|
match try!(self.read_message()) {
|
||||||
@ -497,7 +497,7 @@ impl InnerConnection {
|
|||||||
frontend::copy_fail("COPY queries cannot be directly executed", buf)
|
frontend::copy_fail("COPY queries cannot be directly executed", buf)
|
||||||
}));
|
}));
|
||||||
try!(self.stream
|
try!(self.stream
|
||||||
.write_message(|buf| Ok::<(), std::io::Error>(frontend::sync(buf))));
|
.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
|
||||||
try!(self.stream.flush());
|
try!(self.stream.flush());
|
||||||
}
|
}
|
||||||
backend::Message::CopyOutResponse { .. } => {
|
backend::Message::CopyOutResponse { .. } => {
|
||||||
@ -506,7 +506,7 @@ impl InnerConnection {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Err(Error::Io(std::io::Error::new(std::io::ErrorKind::InvalidInput,
|
return Err(Error::Io(io::Error::new(io::ErrorKind::InvalidInput,
|
||||||
"COPY queries cannot be directly \
|
"COPY queries cannot be directly \
|
||||||
executed")));
|
executed")));
|
||||||
}
|
}
|
||||||
@ -560,7 +560,7 @@ impl InnerConnection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try!(self.stream.write_message(|buf| frontend::execute(portal_name, row_limit, 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.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
|
||||||
try!(self.stream.flush());
|
try!(self.stream.flush());
|
||||||
|
|
||||||
match try!(self.read_message()) {
|
match try!(self.read_message()) {
|
||||||
@ -616,7 +616,7 @@ impl InnerConnection {
|
|||||||
|
|
||||||
fn close_statement(&mut self, name: &str, type_: u8) -> Result<()> {
|
fn close_statement(&mut self, name: &str, type_: u8) -> Result<()> {
|
||||||
try!(self.stream.write_message(|buf| frontend::close(type_, name, 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.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
|
||||||
try!(self.stream.flush());
|
try!(self.stream.flush());
|
||||||
let resp = match try!(self.read_message()) {
|
let resp = match try!(self.read_message()) {
|
||||||
backend::Message::CloseComplete => Ok(()),
|
backend::Message::CloseComplete => Ok(()),
|
||||||
@ -838,7 +838,7 @@ impl InnerConnection {
|
|||||||
frontend::copy_fail("COPY queries cannot be directly executed", buf)
|
frontend::copy_fail("COPY queries cannot be directly executed", buf)
|
||||||
}));
|
}));
|
||||||
try!(self.stream
|
try!(self.stream
|
||||||
.write_message(|buf| Ok::<(), std::io::Error>(frontend::sync(buf))));
|
.write_message(|buf| Ok::<(), io::Error>(frontend::sync(buf))));
|
||||||
try!(self.stream.flush());
|
try!(self.stream.flush());
|
||||||
}
|
}
|
||||||
backend::Message::ErrorResponse { fields } => {
|
backend::Message::ErrorResponse { fields } => {
|
||||||
@ -853,7 +853,7 @@ impl InnerConnection {
|
|||||||
|
|
||||||
fn finish_inner(&mut self) -> Result<()> {
|
fn finish_inner(&mut self) -> Result<()> {
|
||||||
check_desync!(self);
|
check_desync!(self);
|
||||||
try!(self.stream.write_message(|buf| Ok::<(), std::io::Error>(frontend::terminate(buf))));
|
try!(self.stream.write_message(|buf| Ok::<(), io::Error>(frontend::terminate(buf))));
|
||||||
try!(self.stream.flush());
|
try!(self.stream.flush());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user