pub struct Connect { /* private fields */ }Expand description
Connect Record
Implementations§
Source§impl Connect
impl Connect
Sourcepub fn with_ysockaddr_c(
fixed_fd: u32,
ysaddr: YSockAddrC,
) -> Result<Self, ConnectError>
pub fn with_ysockaddr_c( fixed_fd: u32, ysaddr: YSockAddrC, ) -> Result<Self, ConnectError>
Construct a new Connect
Examples found in repository?
examples/connect.rs (line 59)
31fn main() {
32 // Bring up a listener
33 let listener = TcpListener::bind("127.0.0.1:0").unwrap();
34 listener.set_nonblocking(true).unwrap();
35 let listener_port = match listener.local_addr().unwrap() {
36 SocketAddr::V4(addr) => addr.port(),
37 SocketAddr::V6(_) => panic!("IPv4 Requested, IPv6 bound?"),
38 };
39
40 println!("std TcpListener on 127.0.0.1:{listener_port}");
41
42 // Now submit a completion for Connect OpCode against the std listener
43 let my_cap = Capacity::<MyCapacity, BearerCapacityKind>::with_planned(MyCapacity {});
44 let mut bearer = UringBearer::with_capacity(my_cap).unwrap();
45
46 let sock = unsafe { libc::socket(libc::AF_INET, libc::SOCK_STREAM, libc::IPPROTO_TCP) };
47 bearer
48 .io_uring()
49 .submitter()
50 .register_files(&[sock])
51 .unwrap();
52
53 let ysaddr = YSockAddrR::from_sockaddr(SocketAddr::new(
54 IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
55 listener_port,
56 ));
57
58 let _op_idx = bearer
59 .push_connect(Connect::with_ysockaddr_c(0, ysaddr.as_c()).unwrap())
60 .unwrap();
61
62 bearer.submit_and_wait(1).unwrap();
63
64 #[derive(Debug)]
65 struct UserData {
66 e: u32,
67 }
68
69 let mut user = UserData { e: 0 };
70 let mut wait_count = 0;
71
72 loop {
73 bearer
74 .completions(&mut user, |user, entry, rec| match rec {
75 Completion::Connect(c) => {
76 user.e += 1;
77 println!(
78 "Connected Q<{:?}> Fixed_fd<{}> ysaddr<{:?}",
79 entry,
80 c.fixed_fd(),
81 c.ysaddr()
82 );
83 // no error
84 assert_eq!(entry.result(), 0);
85 }
86 _ => panic!("Queue had something else than Connect?"),
87 })
88 .unwrap();
89
90 if user.e != 0 {
91 break;
92 }
93
94 if wait_count > 4 {
95 panic!("wait_count > 5 on Connect example.");
96 }
97
98 wait_count += 1;
99 println!("Waiting for the completion @ {wait_count} ..");
100 let st = std::time::Duration::from_secs(1);
101 std::thread::sleep(st);
102 }
103
104 // Now check that the listener got the connection.
105 match listener.accept() {
106 Ok((in_s, in_a)) => println!(
107 "std TcpListener accepted {} from {}",
108 in_s.as_raw_fd(),
109 in_a
110 ),
111 Err(e) => panic!("std TcpListener resulted in error = {e}"),
112 }
113}Trait Implementations§
Source§impl OpCompletion for Connect
impl OpCompletion for Connect
Auto Trait Implementations§
impl Freeze for Connect
impl RefUnwindSafe for Connect
impl Send for Connect
impl Sync for Connect
impl Unpin for Connect
impl UnwindSafe for Connect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more