Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementing IORING_OP_CONNECT #15

Open
Geal opened this issue Feb 10, 2020 · 2 comments
Open

implementing IORING_OP_CONNECT #15

Geal opened this issue Feb 10, 2020 · 2 comments

Comments

@Geal
Copy link
Contributor

Geal commented Feb 10, 2020

hello! I am implementing the connect() operation and need some advice on the API. The call looks like this:

pub fn connect<'a>(                            
        &'a self,                                          
        socket: &TcpStream,                      
        address: *const libc::sockaddr,                  
    ) -> Completion<'a, ()> {                            
        self.with_sqe(None, false, |sqe| {         
            sqe.prep_rw(                                   
                IORING_OP_CONNECT,                         
                socket.as_raw_fd(),                  
                0,                                         
                std::mem::size_of::<libc::sockaddr>() as u64,
                Ordering::None,                   
            );                                
                                                           
            sqe.addr = address as u64;         
        })                                         
    } 

And it is called like this:

 let mut stream = net2::TcpBuilder::new_v4()?.to_tcp_stream()?;
  let c: SocketAddr = "127.0.0.1:8080".parse().unwrap();
  let (address, len) = addr2raw(&c);
  println!("connecting to address {:?} ({:?}) -> {:?}, len = {:?}", c, &c as *const SocketAddr, address, len);
  let c1 = ring.connect(&stream, address);

(I took the addr2raw function from https://github.com/rust-lang-nursery/net2-rs/blob/eda403f03033b58560d81b821f0df822f50cde4d/src/socket.rs#L87-L96 ).

I think the function should take a SocketAddr as argument instead of a libc::sockaddr (so connect() would do the conversion), I'd like to add an Ordering argument (to try and link a read or write just after connecting), and I'm ambivalent about requiring net2, but std::net:TcpStream does not allow creation of a socket outside of TcpStream::connect() or TcpListener::accept().

What do you think?

@the8472
Copy link

the8472 commented Feb 18, 2020

I'm ambivalent about requiring net2, but std::net:TcpStream does not allow creation of a socket outside of TcpStream::connect() or TcpListener::accept()

Perhaps this discussion is relevant where I propose that a builder for unconnected sockets should be added to the stdlib: rust-lang/rust#68053

@Geal
Copy link
Contributor Author

Geal commented Feb 19, 2020

Yup, that would be great to have unconnected sockets in the stdlib

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants