forked from M-Labs/zynq-rs
1
0
Fork 0

libasync: add TcpSocket::{close, abort, keep_alive, timeout}()

This commit is contained in:
Astro 2020-04-16 20:43:36 +02:00
parent 60e45f096d
commit bcedd02ad9
1 changed files with 33 additions and 0 deletions

View File

@ -14,6 +14,7 @@ use smoltcp::{
SocketHandle, SocketRef, SocketHandle, SocketRef,
TcpSocketBuffer, TcpSocket, TcpState, TcpSocketBuffer, TcpSocket, TcpState,
}, },
time::Duration,
}; };
use crate::task; use crate::task;
use super::Sockets; use super::Sockets;
@ -217,6 +218,38 @@ impl TcpStream {
} }
}).await }).await
} }
/// Close the transmit half of the connection
pub async fn close(&self) {
self.with_socket(|mut socket| socket.close());
// Yield for one iface.poll() to send the packet
task::r#yield().await;
}
/// Destroy the socket, sending the RST
pub async fn abort(self) {
self.with_socket(|mut socket| socket.abort());
// Yield for one iface.poll() to send the packet
task::r#yield().await;
}
pub fn keep_alive(&self) -> Option<Duration> {
self.with_socket(|socket| socket.keep_alive())
}
pub fn set_keep_alive(&mut self, interval: Option<Duration>) {
self.with_socket(|mut socket| socket.set_keep_alive(interval));
}
pub fn timeout(&self) -> Option<Duration> {
self.with_socket(|socket| socket.timeout())
}
pub fn set_timeout(&mut self, duration: Option<Duration>) {
self.with_socket(|mut socket| socket.set_timeout(duration));
}
} }
impl Drop for TcpStream { impl Drop for TcpStream {