runtime_raw/
tcp.rs

1use futures::prelude::*;
2use futures::task::{Context, Poll};
3
4use std::fmt::Debug;
5use std::io;
6use std::net::SocketAddr;
7use std::pin::Pin;
8
9/// A TcpStream for this Runtime
10pub trait TcpStream: AsyncRead + AsyncWrite + Debug + Send {
11    /// Check if the stream can be written to.
12    fn poll_write_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>>;
13
14    /// Check if the stream can be read from.
15    fn poll_read_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>>;
16
17    /// Check if any socket errors exist on the `TcpStream`.
18    ///
19    /// Checking for socket errors is fallible, which is why the outer type is
20    /// `Result`.
21    fn take_error(&self) -> io::Result<Option<io::Error>>;
22
23    /// Returns the local address that this stream is connected to.
24    fn local_addr(&self) -> io::Result<SocketAddr>;
25
26    /// Returns the remote address that this stream is connected to.
27    fn peer_addr(&self) -> io::Result<SocketAddr>;
28
29    /// Shuts down the read, write, or both halves of this connection.
30    fn shutdown(&self, how: std::net::Shutdown) -> std::io::Result<()>;
31
32    /// Extracts the raw file descriptor.
33    #[cfg(unix)]
34    fn as_raw_fd(&self) -> std::os::unix::io::RawFd;
35}
36
37/// A TcpListener for this Runtime
38pub trait TcpListener: Debug + Send {
39    /// Get the address the listener is listening on.
40    fn local_addr(&self) -> io::Result<SocketAddr>;
41
42    /// Check if the listener is ready to accept connections.
43    fn poll_accept(
44        self: Pin<&mut Self>,
45        cx: &mut Context<'_>,
46    ) -> Poll<io::Result<Pin<Box<dyn TcpStream>>>>;
47
48    /// Extracts the raw file descriptor.
49    #[cfg(unix)]
50    fn as_raw_fd(&self) -> std::os::unix::io::RawFd;
51}