470: Add TCP listen. r=Dirbaio a=matoushybl



Co-authored-by: Matous Hybl <hyblmatous@gmail.com>
This commit is contained in:
bors[bot] 2021-11-04 12:49:41 +00:00 committed by GitHub
commit 26f86d7f36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,6 +58,26 @@ impl<'a> TcpSocket<'a> {
.await .await
} }
pub async fn listen<T>(&mut self, local_endpoint: T) -> Result<()>
where
T: Into<IpEndpoint>,
{
self.with(|s| s.listen(local_endpoint))?;
futures::future::poll_fn(|cx| {
self.with(|s| match s.state() {
TcpState::Closed | TcpState::TimeWait => Poll::Ready(Err(Error::Unaddressable)),
TcpState::Listen => Poll::Ready(Ok(())),
TcpState::SynSent | TcpState::SynReceived => {
s.register_send_waker(cx.waker());
Poll::Pending
}
_ => Poll::Ready(Ok(())),
})
})
.await
}
pub fn set_timeout(&mut self, duration: Option<Duration>) { pub fn set_timeout(&mut self, duration: Option<Duration>) {
self.with(|s| s.set_timeout(duration)) self.with(|s| s.set_timeout(duration))
} }