-
Notifications
You must be signed in to change notification settings - Fork 115
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
TcpListener::from_listener() doesn't seem to work with listeners created via std::net::TcpListener::from_raw_fd() #241
Comments
Hm interesting! If you can slim this down that'd be great, and maybe try poking around with The address being passed in is only actually used on Windows, it's just required everywhere for a consistent interface. |
I've made some progress here. Something inside of tokio is doing something that results in "Error: Invalid argument (os error 22)" which causes the Here's the strace of that happening:
I suspect this is happening because something is trying to use the address of the TcpListener which of course won't work. |
Is the file descriptor coming out of xcb actually a TCP listener? Or is it a unix socket? (in which case |
The file descriptor coming out of xcb is a Unix Socket. I looked at the |
Actually, I'm not sure what the file descriptor points to. It's whatever I get back from |
Oh the tokio-uds crate is intended to basically be the same as the TCP types in tokio-core (hence the lack of current docs), so you should be able to use mostly the same APIs? |
I was able to finagle the code into using tokio-uds but I get the same exact error, "Error: Invalid argument (os error 22)". Wish it was more descriptive! |
I'm totally lost at this point as to how to get tokio to work like it does with mio. I thought it might be helpful to post the mio equivalent code (which works fine): https://gist.github.com/liftoff/d6cead19e434871985047769ee3df7a3 The relevant portion is probably this:
|
It looks like in the mio code you're ignoring the return value of |
I'm not sure what you mean? I'm only calling |
Right what Tokio is doing is also calling |
How do I do the equivalent in Tokio though? |
Probably something like -- |
Replacing:
...with:
Results in compilation errors:
The same thing happens if I replace:
...with your |
I have an idea... Maybe the problem is that something is calling |
Hm so in any case it sounds like this maybe isn't the best usage of raw file descriptors. When creating a Rust type it's consumign ownership of the file descriptor but it looks like the C side of things still has the file descriptor in this case? It may be best to basically use |
As far as I know, XCB is a client library for X window server. Maybe you need to create TcpStream\UdsStream instead of TcpListener\UdsListener? |
@alexcrichton I have no idea what I'm doing (haha)... Can you point me to a minimal example of a @0xd34d10cc How would I use UdsListener instead of TcpStream? I only have examples that use |
@liftoff |
Actually, I think tokio cannot be used with XCB that way. XCB handles io by itself so the only thing you want is to be notified when socket is ready to read. Tokio has much more higher-level api which cannot provide such information. |
@0xd34d10cc Any recommendations as to how I should proceed then? I was wondering if there was an easy way to just have Tokio repeatedly call poll_for_event() in the background until the program ends. |
@0xd34d10cc Tokio should work fine, it has far more than request / response (despite what the docs might make seem). |
@carllerche ah, I've missed that |
Sorry for the lengthy code but here's my example:
https://gist.github.com/liftoff/d15fbb2d472642240af4b0acf2664bae
The pertinent lines are:
Then later I start up the reactor like so:
The
webserver
works fine. Thexcb_handler
does not. It's like the reactor isn't detecting that the underlying fd has data to be read.If I use mio directly with
poll.register(&fd_listener, XCBEVENT, mio::Ready::readable(), mio::PollOpt::edge()).unwrap();
it seems to work fine (fd_listener
was made from mio:tcp:TcpListener::from_raw_fd()`).I asked in #rust-beginners but no one was able to figure it out. As I understand it the value of
addr
passed totokio_core::net::TcpListener::from_listener()
should be ignored if the underlying socket is from an fd but I'm not certain of this. I'm also not certain that I'm going about this the best way. I mean, it seems logical but I can't find any examples of using Tokio to listen for events on an fd.Any assistance with this is greatly appreciated.
The text was updated successfully, but these errors were encountered: