Skip to content

Commit b41d62c

Browse files
committed
fix(io,net): update to latest
1 parent e6c6224 commit b41d62c

6 files changed

Lines changed: 197 additions & 160 deletions

File tree

compio-io/src/ancillary/io.rs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#[cfg(feature = "allocator_api")]
2+
use std::alloc::Allocator;
3+
4+
use compio_buf::{BufResult, IoBuf, IoBufMut, IoVectoredBuf, IoVectoredBufMut, t_alloc};
5+
6+
/// Trait for asynchronous read with ancillary (control) data.
7+
/// Intended for connected stream sockets (TCP, Unix streams) where no source
8+
/// address is needed.
9+
pub trait AsyncReadAncillary {
10+
/// Read data with ancillary data into an owned buffer.
11+
async fn read_with_ancillary<T: IoBufMut, C: IoBufMut>(
12+
&mut self,
13+
buffer: T,
14+
control: C,
15+
) -> BufResult<(usize, usize), (T, C)>;
16+
17+
/// Read data with ancillary data into a vectored buffer.
18+
async fn read_vectored_with_ancillary<T: IoVectoredBufMut, C: IoBufMut>(
19+
&mut self,
20+
buffer: T,
21+
control: C,
22+
) -> BufResult<(usize, usize), (T, C)>;
23+
}
24+
25+
impl<A: AsyncReadAncillary + ?Sized> AsyncReadAncillary for &mut A {
26+
#[inline]
27+
async fn read_with_ancillary<T: IoBufMut, C: IoBufMut>(
28+
&mut self,
29+
buffer: T,
30+
control: C,
31+
) -> BufResult<(usize, usize), (T, C)> {
32+
(**self).read_with_ancillary(buffer, control).await
33+
}
34+
35+
#[inline]
36+
async fn read_vectored_with_ancillary<T: IoVectoredBufMut, C: IoBufMut>(
37+
&mut self,
38+
buffer: T,
39+
control: C,
40+
) -> BufResult<(usize, usize), (T, C)> {
41+
(**self).read_vectored_with_ancillary(buffer, control).await
42+
}
43+
}
44+
45+
impl<A: AsyncReadAncillary + ?Sized, #[cfg(feature = "allocator_api")] Alloc: Allocator>
46+
AsyncReadAncillary for t_alloc!(Box, A, Alloc)
47+
{
48+
#[inline]
49+
async fn read_with_ancillary<T: IoBufMut, C: IoBufMut>(
50+
&mut self,
51+
buffer: T,
52+
control: C,
53+
) -> BufResult<(usize, usize), (T, C)> {
54+
(**self).read_with_ancillary(buffer, control).await
55+
}
56+
57+
#[inline]
58+
async fn read_vectored_with_ancillary<T: IoVectoredBufMut, C: IoBufMut>(
59+
&mut self,
60+
buffer: T,
61+
control: C,
62+
) -> BufResult<(usize, usize), (T, C)> {
63+
(**self).read_vectored_with_ancillary(buffer, control).await
64+
}
65+
}
66+
67+
/// Trait for asynchronous write with ancillary (control) data.
68+
/// Intended for connected stream sockets (TCP, Unix streams) where no
69+
/// destination address is needed.
70+
pub trait AsyncWriteAncillary {
71+
/// Write data with ancillary data from an owned buffer.
72+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
73+
&mut self,
74+
buffer: T,
75+
control: C,
76+
) -> BufResult<usize, (T, C)>;
77+
78+
/// Write data with ancillary data from a vectored buffer.
79+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
80+
&mut self,
81+
buffer: T,
82+
control: C,
83+
) -> BufResult<usize, (T, C)>;
84+
}
85+
86+
impl<A: AsyncWriteAncillary + ?Sized> AsyncWriteAncillary for &mut A {
87+
#[inline]
88+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
89+
&mut self,
90+
buffer: T,
91+
control: C,
92+
) -> BufResult<usize, (T, C)> {
93+
(**self).write_with_ancillary(buffer, control).await
94+
}
95+
96+
#[inline]
97+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
98+
&mut self,
99+
buffer: T,
100+
control: C,
101+
) -> BufResult<usize, (T, C)> {
102+
(**self)
103+
.write_vectored_with_ancillary(buffer, control)
104+
.await
105+
}
106+
}
107+
108+
impl<A: AsyncWriteAncillary + ?Sized, #[cfg(feature = "allocator_api")] Alloc: Allocator>
109+
AsyncWriteAncillary for t_alloc!(Box, A, Alloc)
110+
{
111+
#[inline]
112+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
113+
&mut self,
114+
buffer: T,
115+
control: C,
116+
) -> BufResult<usize, (T, C)> {
117+
(**self).write_with_ancillary(buffer, control).await
118+
}
119+
120+
#[inline]
121+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
122+
&mut self,
123+
buffer: T,
124+
control: C,
125+
) -> BufResult<usize, (T, C)> {
126+
(**self)
127+
.write_vectored_with_ancillary(buffer, control)
128+
.await
129+
}
130+
}

compio-io/src/ancillary/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
//! caller-supplied send buffer.
1212
//! - [`AncillaryBuf`]: A fixed-size, properly aligned stack buffer for
1313
//! ancillary data
14+
//!
15+
//! # Traits
16+
//!
17+
//! - [`AsyncReadAncillary`]: read data together with ancillary data
18+
//! - [`AsyncWriteAncillary`]: write data together with ancillary data
1419
1520
use std::{
1621
marker::PhantomData,
@@ -22,6 +27,10 @@ use compio_buf::{IoBuf, IoBufMut, SetLen};
2227
#[cfg(windows)]
2328
use windows_sys::Win32::Networking::WinSock;
2429

30+
mod io;
31+
32+
pub use io::*;
33+
2534
cfg_if::cfg_if! {
2635
if #[cfg(windows)] {
2736
#[path = "windows.rs"]

compio-io/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ pub mod framed;
136136
#[cfg(feature = "compat")]
137137
pub mod compat;
138138
mod read;
139-
pub mod socket;
140139
pub mod util;
141140
mod write;
142141

compio-io/src/socket.rs

Lines changed: 0 additions & 61 deletions
This file was deleted.

compio-net/src/tcp.rs

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use compio_buf::{BufResult, IoBuf, IoBufMut, IoVectoredBuf, IoVectoredBufMut};
44
use compio_driver::impl_raw_fd;
55
use compio_io::{
66
AsyncRead, AsyncReadManaged, AsyncWrite,
7-
socket::{AsyncRecvMsg, AsyncSendMsg},
7+
ancillary::{AsyncReadAncillary, AsyncWriteAncillary},
88
util::Splittable,
99
};
1010
use compio_runtime::{BorrowedBuffer, BufferPool, fd::PollFd};
@@ -384,57 +384,49 @@ impl AsyncReadManaged for &TcpStream {
384384
}
385385
}
386386

387-
impl AsyncRecvMsg for TcpStream {
388-
type AddrType = SocketAddr;
389-
387+
impl AsyncReadAncillary for TcpStream {
390388
#[inline]
391-
async fn recv_msg<T: IoBufMut, C: IoBufMut>(
389+
async fn read_with_ancillary<T: IoBufMut, C: IoBufMut>(
392390
&mut self,
393391
buffer: T,
394392
control: C,
395-
flags: i32,
396-
) -> BufResult<(usize, usize, SocketAddr), (T, C)> {
397-
(&*self).recv_msg(buffer, control, flags).await
393+
) -> BufResult<(usize, usize), (T, C)> {
394+
(&*self).read_with_ancillary(buffer, control).await
398395
}
399396

400397
#[inline]
401-
async fn recv_msg_vectored<T: IoVectoredBufMut, C: IoBufMut>(
398+
async fn read_vectored_with_ancillary<T: IoVectoredBufMut, C: IoBufMut>(
402399
&mut self,
403400
buffer: T,
404401
control: C,
405-
flags: i32,
406-
) -> BufResult<(usize, usize, SocketAddr), (T, C)> {
407-
(&*self).recv_msg_vectored(buffer, control, flags).await
402+
) -> BufResult<(usize, usize), (T, C)> {
403+
(&*self).read_vectored_with_ancillary(buffer, control).await
408404
}
409405
}
410406

411-
impl AsyncRecvMsg for &TcpStream {
412-
type AddrType = SocketAddr;
413-
407+
impl AsyncReadAncillary for &TcpStream {
414408
#[inline]
415-
async fn recv_msg<T: IoBufMut, C: IoBufMut>(
409+
async fn read_with_ancillary<T: IoBufMut, C: IoBufMut>(
416410
&mut self,
417411
buffer: T,
418412
control: C,
419-
flags: i32,
420-
) -> BufResult<(usize, usize, SocketAddr), (T, C)> {
413+
) -> BufResult<(usize, usize), (T, C)> {
421414
self.inner
422-
.recv_msg(buffer, control, flags)
415+
.recv_msg(buffer, control, 0)
423416
.await
424-
.map_res(|(res, len, addr)| (res, len, addr.as_socket().expect("IP socket address")))
417+
.map_res(|(res, len, _addr)| (res, len))
425418
}
426419

427420
#[inline]
428-
async fn recv_msg_vectored<T: IoVectoredBufMut, C: IoBufMut>(
421+
async fn read_vectored_with_ancillary<T: IoVectoredBufMut, C: IoBufMut>(
429422
&mut self,
430423
buffer: T,
431424
control: C,
432-
flags: i32,
433-
) -> BufResult<(usize, usize, SocketAddr), (T, C)> {
425+
) -> BufResult<(usize, usize), (T, C)> {
434426
self.inner
435-
.recv_msg_vectored(buffer, control, flags)
427+
.recv_msg_vectored(buffer, control, 0)
436428
.await
437-
.map_res(|(res, len, addr)| (res, len, addr.as_socket().expect("IP socket address")))
429+
.map_res(|(res, len, _addr)| (res, len))
438430
}
439431
}
440432

@@ -482,61 +474,45 @@ impl AsyncWrite for &TcpStream {
482474
}
483475
}
484476

485-
impl AsyncSendMsg for TcpStream {
486-
type AddrType = SocketAddr;
487-
477+
impl AsyncWriteAncillary for TcpStream {
488478
#[inline]
489-
async fn send_msg<T: IoBuf, C: IoBuf>(
479+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
490480
&mut self,
491481
buffer: T,
492482
control: C,
493-
addr: &SocketAddr,
494-
flags: i32,
495483
) -> BufResult<usize, (T, C)> {
496-
(&*self).send_msg(buffer, control, addr, flags).await
484+
(&*self).write_with_ancillary(buffer, control).await
497485
}
498486

499487
#[inline]
500-
async fn send_msg_vectored<T: IoVectoredBuf, C: IoBuf>(
488+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
501489
&mut self,
502490
buffer: T,
503491
control: C,
504-
addr: &SocketAddr,
505-
flags: i32,
506492
) -> BufResult<usize, (T, C)> {
507493
(&*self)
508-
.send_msg_vectored(buffer, control, addr, flags)
494+
.write_vectored_with_ancillary(buffer, control)
509495
.await
510496
}
511497
}
512498

513-
impl AsyncSendMsg for &TcpStream {
514-
type AddrType = SocketAddr;
515-
499+
impl AsyncWriteAncillary for &TcpStream {
516500
#[inline]
517-
async fn send_msg<T: IoBuf, C: IoBuf>(
501+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
518502
&mut self,
519503
buffer: T,
520504
control: C,
521-
addr: &SocketAddr,
522-
flags: i32,
523505
) -> BufResult<usize, (T, C)> {
524-
self.inner
525-
.send_msg(buffer, control, &(*addr).into(), flags)
526-
.await
506+
self.inner.send_msg(buffer, control, None, 0).await
527507
}
528508

529509
#[inline]
530-
async fn send_msg_vectored<T: IoVectoredBuf, C: IoBuf>(
510+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
531511
&mut self,
532512
buffer: T,
533513
control: C,
534-
addr: &SocketAddr,
535-
flags: i32,
536514
) -> BufResult<usize, (T, C)> {
537-
self.inner
538-
.send_msg_vectored(buffer, control, &(*addr).into(), flags)
539-
.await
515+
self.inner.send_msg_vectored(buffer, control, None, 0).await
540516
}
541517
}
542518

0 commit comments

Comments
 (0)