Struct Connect

Source
pub struct Connect { /* private fields */ }
Expand description

Connect Record

Implementations§

Source§

impl Connect

Source

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 Clone for Connect

Source§

fn clone(&self) -> Connect

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Connect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl OpCode<Connect> for Connect

Source§

fn submission(self) -> Result<Connect, OpError>

It is recommended that you use a harmonized error type but is not mandatory.
Source§

fn completion(&mut self, _: Pin<&mut Connect>) -> Result<(), OpError>

io-uring-bearer will call this upno completion
Source§

impl OpCompletion for Connect

Source§

type Error = OpError

It is recommended that you use a harmonized error type but is not mandatory.
Source§

fn entry(&self) -> Entry

Provide the squeue entry
Source§

fn owner(&self) -> Owner

Get the current Owner
Source§

fn force_owner_kernel(&mut self) -> bool

Force set the owner to Kernel
Source§

impl OpExtConnect for Connect

Source§

fn fixed_fd(&self) -> u32

Underlying Fixed Fd

Source§

fn ysaddr(&self) -> &YSockAddrC

Underlying YSockAddrC

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.