tokio-rs / tokio-uds Goto Github PK
View Code? Open in Web Editor NEWUnix Domain Sockets for tokio
License: Apache License 2.0
Unix Domain Sockets for tokio
License: Apache License 2.0
How do I use pre-opened (for example by inetd) or received from another UNIX socket file descriptor in tokio-uds?
The tokio documentation has a simple example of setting up a TCP service with tokio-proto: https://tokio.rs/docs/getting-started/simple-server/#configure-and-run
I'm trying to understand how to do something similar with unix sockets, but it's not clear to me how to connect my implementation of a Service
with a UnixStream
.
I'd be useful to have a method for getting peer credentials. I suggest get_peer_cred(&self) -> UCred
.
I need this now, so I'll now impl it via extension trait (by getting RawFd
) but I plan to submit a proper PR later.
Hi! In trying to compile pijul for openbsd 6.3-current, rustc 1.25.0,, I get the following error:
Compiling tokio-uds v0.1.7
error[E0425]: cannot find function `get_peer_cred` in module `ucred`
--> /home/patrick/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-uds-0.1.7/src/lib.rs:310:16
|
310 | ucred::get_peer_cred(self)
| ^^^^^^^^^^^^^ not found in `ucred`
error: aborting due to previous error
error: Could not compile `tokio-uds`.
warning: build failed, waiting for other jobs to finish...
error: failed to compile `pijul v0.9.0`, intermediate artifacts can be found at `/tmp/cargo-install.DADQlJvS3dW6`
Caused by:
build failed
I noticed that, contrary to my unsubstantiated expectations, thatUnixDatagram::{send, recv}
return io::Result
, instead of turningWouldBlock
errors into futures::Async::NotReady
.
It's not clear to me what result types are approriate for each layer -- I'd have assumed io::Result
in mio, and public, but primitive methods (like send
and recv
) in tokio-based APIs would use some Async
type variant.
I'm asking not due to API usability issues, but since I am trying using tokio-uds
as a blueprint for zmq-tokio
.
This is really one of the biggest hurdles for me: that there's no blueprint I'm totally confident in having the API types right, and no docs explaining how it should be done, and why.
If I reach sufficient understanding, I can maybe come up with a documentation patch for tokio-core that explains the design ideas behind that, but right now I'm at quite a loss.
"... for inclusion in Serde by you, ..."
This crate still requires handle for UnixStream
, UnixStream
and UnixDatagram
constructors (connect
, bind
, pair
...)
It should be changed to support tokio
crate and the new style of writing Tokio-based services.
First, I am a Rust newbie...
I am trying to read data from a Unix socket, but I am failing:
extern crate futures;
extern crate tokio_core;
extern crate tokio_signal;
extern crate tokio_uds;
use std::io::Read;
use futures::{Future, Async, Poll};
use tokio_core::reactor::Core;
use tokio_uds::{UnixListener, UnixStream};
struct Echo {
listener: UnixListener,
}
impl Future for Echo {
type Item = ();
type Error = ();
fn poll(&mut self) -> Poll<(), ()> {
loop {
if let Async::Ready(()) = self.listener.poll_read() {
println!("New Connection");
let (mut stream, _) = self.listener.accept().unwrap();
let mut buffer = Vec::new();
stream.read_to_end(&mut buffer);
println!("{:?}", buffer);
}
}
}
}
fn main() {
let mut core = Core::new().unwrap();
let handle = core.handle();
let listener = UnixListener::bind("/var/run/hello.sock", &handle).unwrap();
core.run(Echo {listener: listener}).unwrap()
}
Can somebody provide an example of howto get this working, please? Thanks!
It's currently impossible to use this crate with a raw fd, because all the functions that could make a UnixListener from a raw fd are private.
The row 25 of ucred.rs
: use libc::ucred;
fails to compile.
error[E0425]: cannot find function get_peer_cred
in module ucred
--> /home/andy/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-uds-0.1.6/src/lib.rs:288:16
|
288 | ucred::get_peer_cred(self)
| ^^^^^^^^^^^^^ not found in ucred
error: aborting due to previous error
This is to track implementation status on Windows. This will become feasible.
https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/
Hi, I would like to send/receive file descriptors (unix sockets). I searched the docs but did not find anything, is it possible to do that right now?
Hello, I need to use UnixListener::from_listener()
method which is present in unreleased version of the library. Can you release 0.1.2 with that method included? If not, what is needed for release? Can I/do you need help with that?
I'm going to clone this repo for now but I'd like to use package from crates.io.
Thank you!
To add a new TUN/TAP device, you have to open /dev/net/tun
, configure it with ioctl
then read/select it like a normal fd. Would it be appropriate for use with UnixDatagram
? If so, did you consider adding impl FromRawFd for UnixDatagram
?
From the documentation:
The returned future will resolve once the stream is successfully connected.
Maybe I'm misunderstanding something, but UnixStream::connect
returns Result<UnixStream>
, not a future.
A short example would be really helpful here.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.