Skip to content

Commit

Permalink
internal_send function
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed Sep 13, 2024
1 parent 2538684 commit ffddc21
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/async_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ impl AsyncSession {
}

pub async fn send(&self, buf: &[u8]) -> std::io::Result<usize> {
self.internal_send(buf)
}

fn internal_send(&self, buf: &[u8]) -> std::io::Result<usize> {
let packet = self.session.allocate_send_packet(buf.len() as _)?;
packet.bytes.copy_from_slice(buf);
self.session.send_packet(packet);
Expand Down Expand Up @@ -122,8 +126,8 @@ impl AsyncRead for AsyncSession {
Ok(guard) => guard,
Err(e) => {
self.read_state = ReadState::Waiting(Some(task));
use std::io::{Error, ErrorKind};
return Poll::Ready(Err(Error::new(ErrorKind::Other, format!("Lock task failed: {}", e))));
use std::io::{Error, ErrorKind::Other};
return Poll::Ready(Err(Error::new(Other, format!("Lock task failed: {}", e))));
}
};
self.read_state = match Pin::new(&mut *task_guard).poll(cx) {
Expand All @@ -143,10 +147,7 @@ impl AsyncRead for AsyncSession {

impl AsyncWrite for AsyncSession {
fn poll_write(self: Pin<&mut Self>, _cx: &mut Context<'_>, buf: &[u8]) -> Poll<std::io::Result<usize>> {
let packet = self.session.allocate_send_packet(buf.len() as _)?;
packet.bytes.copy_from_slice(buf);
self.session.send_packet(packet);
Poll::Ready(Ok(buf.len()))
Poll::Ready(Ok(self.internal_send(buf)?))
}

fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Expand Down

0 comments on commit ffddc21

Please sign in to comment.