use write_io instead of handshake

This commit is contained in:
quininer 2019-10-11 01:01:27 +08:00
parent 7864945694
commit 9a161beb87
5 changed files with 13 additions and 13 deletions

View File

@ -56,8 +56,8 @@ where
futures::ready!(stream.handshake(cx))?;
}
if stream.session.wants_write() {
futures::ready!(stream.handshake(cx))?;
while stream.session.wants_write() {
futures::ready!(stream.write_io(cx))?;
}
}

View File

@ -33,7 +33,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
Pin::new(self)
}
fn process_new_packets(&mut self, cx: &mut Context) -> io::Result<()> {
pub fn process_new_packets(&mut self, cx: &mut Context) -> io::Result<()> {
self.session.process_new_packets()
.map_err(|err| {
// In case we have an alert to send describing this error,
@ -45,7 +45,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
})
}
fn read_io(&mut self, cx: &mut Context) -> Poll<io::Result<usize>> {
pub fn read_io(&mut self, cx: &mut Context) -> Poll<io::Result<usize>> {
struct Reader<'a, 'b, T> {
io: &'a mut T,
cx: &'a mut Context<'b>
@ -71,7 +71,7 @@ impl<'a, IO: AsyncRead + AsyncWrite + Unpin, S: Session> Stream<'a, IO, S> {
Poll::Ready(Ok(n))
}
fn write_io(&mut self, cx: &mut Context) -> Poll<io::Result<usize>> {
pub fn write_io(&mut self, cx: &mut Context) -> Poll<io::Result<usize>> {
struct Writer<'a, 'b, T> {
io: &'a mut T,
cx: &'a mut Context<'b>

View File

@ -191,8 +191,8 @@ fn do_handshake(client: &mut ClientSession, server: &mut ServerSession, cx: &mut
ready!(stream.handshake(cx))?;
}
if stream.session.wants_write() {
ready!(stream.handshake(cx))?;
while stream.session.wants_write() {
ready!(stream.write_io(cx))?;
}
Poll::Ready(Ok(()))

View File

@ -51,8 +51,8 @@ where
futures::ready!(stream.handshake(cx))?;
}
if stream.session.wants_write() {
futures::ready!(stream.handshake(cx))?;
while stream.session.wants_write() {
futures::ready!(stream.write_io(cx))?;
}
}

View File

@ -40,11 +40,11 @@ async fn send(config: Arc<ClientConfig>, addr: SocketAddr, data: &[u8])
stream.write_all(data).await?;
stream.flush().await?;
// sleep 3s
// sleep 1s
//
// see https://www.mail-archive.com/openssl-users@openssl.org/msg84451.html
let sleep3 = delay_for(Duration::from_secs(3));
let mut stream = match future::select(Read1(stream), sleep3).await {
let sleep1 = delay_for(Duration::from_secs(1));
let mut stream = match future::select(Read1(stream), sleep1).await {
future::Either::Right((_, Read1(stream))) => stream,
future::Either::Left((Err(err), _)) => return Err(err),
future::Either::Left((Ok(_), _)) => unreachable!(),
@ -77,7 +77,7 @@ async fn test_0rtt() -> io::Result<()> {
.map(DropKill)?;
// wait openssl server
delay_for(Duration::from_secs(3)).await;
delay_for(Duration::from_secs(1)).await;
let mut config = ClientConfig::new();
let mut chain = BufReader::new(Cursor::new(include_str!("end.chain")));