aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-11-04 12:49:41 +0000
committerGitHub <[email protected]>2021-11-04 12:49:41 +0000
commit26f86d7f36ebbab3e43bad2edef78bf6002456d4 (patch)
tree20932a2c68c4d428e18c1d081d38a67cb48d2677
parent1bf6e646c9ad0d14ce3510442688ef604c6f363f (diff)
parentd742d0252ef6af3617f333e6f31be9559130ded7 (diff)
Merge #470
470: Add TCP listen. r=Dirbaio a=matoushybl Co-authored-by: Matous Hybl <[email protected]>
-rw-r--r--embassy-net/src/tcp_socket.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/embassy-net/src/tcp_socket.rs b/embassy-net/src/tcp_socket.rs
index 2433771c8..bb1b626e7 100644
--- a/embassy-net/src/tcp_socket.rs
+++ b/embassy-net/src/tcp_socket.rs
@@ -58,6 +58,26 @@ impl<'a> TcpSocket<'a> {
58 .await 58 .await
59 } 59 }
60 60
61 pub async fn listen<T>(&mut self, local_endpoint: T) -> Result<()>
62 where
63 T: Into<IpEndpoint>,
64 {
65 self.with(|s| s.listen(local_endpoint))?;
66
67 futures::future::poll_fn(|cx| {
68 self.with(|s| match s.state() {
69 TcpState::Closed | TcpState::TimeWait => Poll::Ready(Err(Error::Unaddressable)),
70 TcpState::Listen => Poll::Ready(Ok(())),
71 TcpState::SynSent | TcpState::SynReceived => {
72 s.register_send_waker(cx.waker());
73 Poll::Pending
74 }
75 _ => Poll::Ready(Ok(())),
76 })
77 })
78 .await
79 }
80
61 pub fn set_timeout(&mut self, duration: Option<Duration>) { 81 pub fn set_timeout(&mut self, duration: Option<Duration>) {
62 self.with(|s| s.set_timeout(duration)) 82 self.with(|s| s.set_timeout(duration))
63 } 83 }