Fix requests failing with 'operation would block'
This commit is contained in:
parent
0c46f27f89
commit
af36130edb
1 changed files with 22 additions and 8 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::protocol::*;
|
||||
use mime::Mime;
|
||||
use std::io::{self, BufRead, Read, Write};
|
||||
use std::io::{self, BufRead, Write};
|
||||
use std::{net, str::FromStr, sync::Arc};
|
||||
use url::Url;
|
||||
|
||||
|
@ -15,15 +15,29 @@ impl Server {
|
|||
let (mut stream, _) = self.listener.accept()?;
|
||||
let mut conn = rustls::ServerConnection::new(Arc::new(self.tls_config.clone()))?;
|
||||
|
||||
loop {
|
||||
conn.complete_io(&mut stream)?;
|
||||
let response = read_request(conn.reader())?.process();
|
||||
let request = match read_request(conn.reader()) {
|
||||
Ok(r) => r,
|
||||
// This is the best way I can find to verify it's an
|
||||
// ErrorKind::WouldBlock. But to be honest this whole way of
|
||||
// having it in a loop to fix the blocking problem is a bodge.
|
||||
// There's probably a Correct Way to fix it.
|
||||
Err(RequestParseError::Error(e)) if e.to_string() == "operation would block" => {
|
||||
continue
|
||||
}
|
||||
Err(e) => return Err(Box::new(e)),
|
||||
};
|
||||
let response = request.process();
|
||||
|
||||
conn.writer()
|
||||
.write_all(response.serialize().as_slice())
|
||||
.expect("23");
|
||||
conn.send_close_notify();
|
||||
conn.complete_io(&mut stream)?;
|
||||
|
||||
Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue