Skip to content

Commit 2748a7c

Browse files
committed
fix(io,net): rename to read/write ancillary
1 parent 8fa025c commit 2748a7c

8 files changed

Lines changed: 192 additions & 162 deletions

File tree

compio-io/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ pub mod framed;
134134
#[cfg(feature = "compat")]
135135
pub mod compat;
136136
mod read;
137-
pub mod socket;
138137
pub mod util;
139138
mod write;
140139

compio-io/src/read/ancillary.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#[cfg(feature = "allocator_api")]
2+
use std::alloc::Allocator;
3+
4+
use compio_buf::{BufResult, IoBufMut, 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+
}

compio-io/src/read/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use std::{io::Cursor, rc::Rc, sync::Arc};
44

55
use compio_buf::{BufResult, IntoInner, IoBufMut, IoVectoredBufMut, buf_try, t_alloc};
66

7+
mod ancillary;
78
mod buf;
89
#[macro_use]
910
mod ext;
1011
mod managed;
1112

13+
pub use ancillary::*;
1214
pub use buf::*;
1315
pub use ext::*;
1416
pub use managed::*;

compio-io/src/socket.rs

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

compio-io/src/write/ancillary.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#[cfg(feature = "allocator_api")]
2+
use std::alloc::Allocator;
3+
4+
use compio_buf::{BufResult, IoBuf, IoVectoredBuf, t_alloc};
5+
6+
/// Trait for asynchronous write with ancillary (control) data.
7+
/// Intended for connected stream sockets (TCP, Unix streams) where no
8+
/// destination address is needed.
9+
pub trait AsyncWriteAncillary {
10+
/// Write data with ancillary data from an owned buffer.
11+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
12+
&mut self,
13+
buffer: T,
14+
control: C,
15+
) -> BufResult<usize, (T, C)>;
16+
17+
/// Write data with ancillary data from a vectored buffer.
18+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
19+
&mut self,
20+
buffer: T,
21+
control: C,
22+
) -> BufResult<usize, (T, C)>;
23+
}
24+
25+
impl<A: AsyncWriteAncillary + ?Sized> AsyncWriteAncillary for &mut A {
26+
#[inline]
27+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
28+
&mut self,
29+
buffer: T,
30+
control: C,
31+
) -> BufResult<usize, (T, C)> {
32+
(**self).write_with_ancillary(buffer, control).await
33+
}
34+
35+
#[inline]
36+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
37+
&mut self,
38+
buffer: T,
39+
control: C,
40+
) -> BufResult<usize, (T, C)> {
41+
(**self)
42+
.write_vectored_with_ancillary(buffer, control)
43+
.await
44+
}
45+
}
46+
47+
impl<A: AsyncWriteAncillary + ?Sized, #[cfg(feature = "allocator_api")] Alloc: Allocator>
48+
AsyncWriteAncillary for t_alloc!(Box, A, Alloc)
49+
{
50+
#[inline]
51+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
52+
&mut self,
53+
buffer: T,
54+
control: C,
55+
) -> BufResult<usize, (T, C)> {
56+
(**self).write_with_ancillary(buffer, control).await
57+
}
58+
59+
#[inline]
60+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
61+
&mut self,
62+
buffer: T,
63+
control: C,
64+
) -> BufResult<usize, (T, C)> {
65+
(**self)
66+
.write_vectored_with_ancillary(buffer, control)
67+
.await
68+
}
69+
}

compio-io/src/write/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ use compio_buf::{BufResult, IntoInner, IoBuf, IoVectoredBuf, buf_try, t_alloc};
66

77
use crate::IoResult;
88

9+
mod ancillary;
910
mod buf;
1011
#[macro_use]
1112
mod ext;
1213

14+
pub use ancillary::*;
1315
pub use buf::*;
1416
pub use ext::*;
1517

compio-net/src/tcp.rs

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::{future::Future, io, net::SocketAddr};
33
use compio_buf::{BufResult, IoBuf, IoBufMut, IoVectoredBuf, IoVectoredBufMut};
44
use compio_driver::impl_raw_fd;
55
use compio_io::{
6-
AsyncRead, AsyncReadManaged, AsyncWrite,
7-
socket::{AsyncRecvMsg, AsyncSendMsg},
6+
AsyncRead, AsyncReadAncillary, AsyncReadManaged, AsyncWrite, AsyncWriteAncillary,
87
util::Splittable,
98
};
109
use compio_runtime::{BorrowedBuffer, BufferPool, fd::PollFd};
@@ -384,57 +383,49 @@ impl AsyncReadManaged for &TcpStream {
384383
}
385384
}
386385

387-
impl AsyncRecvMsg for TcpStream {
388-
type AddrType = ();
389-
386+
impl AsyncReadAncillary for TcpStream {
390387
#[inline]
391-
async fn recv_msg<T: IoBufMut, C: IoBufMut>(
388+
async fn read_with_ancillary<T: IoBufMut, C: IoBufMut>(
392389
&mut self,
393390
buffer: T,
394391
control: C,
395-
flags: i32,
396-
) -> BufResult<(usize, usize, Option<()>), (T, C)> {
397-
(&*self).recv_msg(buffer, control, flags).await
392+
) -> BufResult<(usize, usize), (T, C)> {
393+
(&*self).read_with_ancillary(buffer, control).await
398394
}
399395

400396
#[inline]
401-
async fn recv_msg_vectored<T: IoVectoredBufMut, C: IoBufMut>(
397+
async fn read_vectored_with_ancillary<T: IoVectoredBufMut, C: IoBufMut>(
402398
&mut self,
403399
buffer: T,
404400
control: C,
405-
flags: i32,
406-
) -> BufResult<(usize, usize, Option<()>), (T, C)> {
407-
(&*self).recv_msg_vectored(buffer, control, flags).await
401+
) -> BufResult<(usize, usize), (T, C)> {
402+
(&*self).read_vectored_with_ancillary(buffer, control).await
408403
}
409404
}
410405

411-
impl AsyncRecvMsg for &TcpStream {
412-
type AddrType = ();
413-
406+
impl AsyncReadAncillary for &TcpStream {
414407
#[inline]
415-
async fn recv_msg<T: IoBufMut, C: IoBufMut>(
408+
async fn read_with_ancillary<T: IoBufMut, C: IoBufMut>(
416409
&mut self,
417410
buffer: T,
418411
control: C,
419-
flags: i32,
420-
) -> BufResult<(usize, usize, Option<()>), (T, C)> {
412+
) -> BufResult<(usize, usize), (T, C)> {
421413
self.inner
422-
.recv_msg(buffer, control, flags)
414+
.recv_msg(buffer, control, 0)
423415
.await
424-
.map_res(|(res, len, _addr)| (res, len, None))
416+
.map_res(|(res, len, _addr)| (res, len))
425417
}
426418

427419
#[inline]
428-
async fn recv_msg_vectored<T: IoVectoredBufMut, C: IoBufMut>(
420+
async fn read_vectored_with_ancillary<T: IoVectoredBufMut, C: IoBufMut>(
429421
&mut self,
430422
buffer: T,
431423
control: C,
432-
flags: i32,
433-
) -> BufResult<(usize, usize, Option<()>), (T, C)> {
424+
) -> BufResult<(usize, usize), (T, C)> {
434425
self.inner
435-
.recv_msg_vectored(buffer, control, flags)
426+
.recv_msg_vectored(buffer, control, 0)
436427
.await
437-
.map_res(|(res, len, _addr)| (res, len, None))
428+
.map_res(|(res, len, _addr)| (res, len))
438429
}
439430
}
440431

@@ -482,59 +473,45 @@ impl AsyncWrite for &TcpStream {
482473
}
483474
}
484475

485-
impl AsyncSendMsg for TcpStream {
486-
type AddrType = ();
487-
476+
impl AsyncWriteAncillary for TcpStream {
488477
#[inline]
489-
async fn send_msg<T: IoBuf, C: IoBuf>(
478+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
490479
&mut self,
491480
buffer: T,
492481
control: C,
493-
_addr: Option<&()>,
494-
flags: i32,
495482
) -> BufResult<usize, (T, C)> {
496-
(&*self).send_msg(buffer, control, None, flags).await
483+
(&*self).write_with_ancillary(buffer, control).await
497484
}
498485

499486
#[inline]
500-
async fn send_msg_vectored<T: IoVectoredBuf, C: IoBuf>(
487+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
501488
&mut self,
502489
buffer: T,
503490
control: C,
504-
_addr: Option<&()>,
505-
flags: i32,
506491
) -> BufResult<usize, (T, C)> {
507492
(&*self)
508-
.send_msg_vectored(buffer, control, None, flags)
493+
.write_vectored_with_ancillary(buffer, control)
509494
.await
510495
}
511496
}
512497

513-
impl AsyncSendMsg for &TcpStream {
514-
type AddrType = ();
515-
498+
impl AsyncWriteAncillary for &TcpStream {
516499
#[inline]
517-
async fn send_msg<T: IoBuf, C: IoBuf>(
500+
async fn write_with_ancillary<T: IoBuf, C: IoBuf>(
518501
&mut self,
519502
buffer: T,
520503
control: C,
521-
_addr: Option<&()>,
522-
flags: i32,
523504
) -> BufResult<usize, (T, C)> {
524-
self.inner.send_msg(buffer, control, None, flags).await
505+
self.inner.send_msg(buffer, control, None, 0).await
525506
}
526507

527508
#[inline]
528-
async fn send_msg_vectored<T: IoVectoredBuf, C: IoBuf>(
509+
async fn write_vectored_with_ancillary<T: IoVectoredBuf, C: IoBuf>(
529510
&mut self,
530511
buffer: T,
531512
control: C,
532-
_addr: Option<&()>,
533-
flags: i32,
534513
) -> BufResult<usize, (T, C)> {
535-
self.inner
536-
.send_msg_vectored(buffer, control, None, flags)
537-
.await
514+
self.inner.send_msg_vectored(buffer, control, None, 0).await
538515
}
539516
}
540517

0 commit comments

Comments
 (0)