sqlx_core/rt/rt_tokio/
socket.rs

1use std::io;
2use std::pin::Pin;
3use std::task::{Context, Poll};
4
5use tokio::io::AsyncWrite;
6use tokio::net::TcpStream;
7
8use crate::io::ReadBuf;
9use crate::net::Socket;
10
11impl Socket for TcpStream {
12    fn try_read(&mut self, mut buf: &mut dyn ReadBuf) -> io::Result<usize> {
13        // Requires `&mut impl BufMut`
14        self.try_read_buf(&mut buf)
15    }
16
17    fn try_write(&mut self, buf: &[u8]) -> io::Result<usize> {
18        (*self).try_write(buf)
19    }
20
21    fn poll_read_ready(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
22        (*self).poll_read_ready(cx)
23    }
24
25    fn poll_write_ready(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
26        (*self).poll_write_ready(cx)
27    }
28
29    fn poll_shutdown(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
30        Pin::new(self).poll_shutdown(cx)
31    }
32}
33
34#[cfg(unix)]
35impl Socket for tokio::net::UnixStream {
36    fn try_read(&mut self, mut buf: &mut dyn ReadBuf) -> io::Result<usize> {
37        self.try_read_buf(&mut buf)
38    }
39
40    fn try_write(&mut self, buf: &[u8]) -> io::Result<usize> {
41        (*self).try_write(buf)
42    }
43
44    fn poll_read_ready(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
45        (*self).poll_read_ready(cx)
46    }
47
48    fn poll_write_ready(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
49        (*self).poll_write_ready(cx)
50    }
51
52    fn poll_shutdown(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
53        Pin::new(self).poll_shutdown(cx)
54    }
55}