Comments (9)
Sounds reasonable to me! The TcpServer
code is actually pretty simple and basically just boils down to this function. The trick is the BindServer
trait which typically takes any I/O object, including a UnixStream
.
from tokio-uds.
The documentation for BindServer says "This trait is not intended to be implemented directly". Is this an exception to that rule, or should one of the other traits suggested in that documentation be used?
from tokio-uds.
@nicholasbishop oh yeah it's not implemented directly, but it can be called with a UnixStream. Most implementations of it (transitively through the impl you see) are generic over T: Io
from tokio-uds.
I think I am still lost :) I was able to make a modified copy of tcp_server.rs
that serves over a unix socket, but I don't feel any closer to understanding why tcp_server.rs
is implemented the way it is.
When you say "it's not implemented directly, but it can be called with a UnixStream", does "it" mean the BindServer
trait? If so, what does it mean to call the trait with a UnixStream
?
At a higher level, what is the point of the BindServer
trait, as opposed to a more direct Server
trait?
Actually, where are the other four traits mentioned in BindServer
's documentation? It refers to pipeline::Server
and three others, but the pipeline
module doesn't document a trait of that name.
from tokio-uds.
There are a number of main "proto" traits
pipeline::ServerProto
multiplex::ServerProto
streaming::pipeline::ServerProto
streaming::multiplex::ServerProto
These are intended to be implemented by protocol authors, and work in the various styles as described by the modules.
The BindServer
trait then has a number of blanket impls to implement itself for free on your protocol once you implement one or more of the above Proto traits. The purpose of BindServer
is to instantiate the protocol internals for you, e.g. the pipeline/multiplex dispatch.
The bind_server
method takes any I/O object and spawns a future that handles the connection. This I/O object can be a unix stream.
The tl;dr; of TcpServer
is:
- Create a
Core
- Create a
TcpListener
- Crate a loop over each accepted connection
- For each accepted connection, call
bind_server
Does that help clear things up?
from tokio-uds.
This is a bit of a late response, but I just published a crate that makes a UnixServer
and UnixClient
with a similar API to tokio-proto
. The documentation is lacking at the moment. But it should work in the same way.
from tokio-uds.
Thanks @dgriffen!
from tokio-uds.
Nice! I have my tokio experimentation on the back burner but I'll definitely give it a try when I get back to it. Thanks for putting that crate up.
from tokio-uds.
Has there been any progress on this issue? I currently have a project that uses a nanomsg as the networking library since I need to switch between TCP and UDS connections for different scenarios.
However, I'm looking to move away from that library for several reasons and Tokio in general looks fantastic for my purposes, I just wanted to make sure I can create UDS connections without problems first, and I have yet to find an example of how this works.
Any documentation you could point me to?
from tokio-uds.
Related Issues (17)
- UnixStream::connect does not return a future HOT 6
- Method for getting credentials of the peer HOT 1
- Sending and receiving file descriptors HOT 2
- unresolved import `libc::ucred` when compiling for musl HOT 2
- Why no FromRawFd? HOT 4
- Doesn't build on android target HOT 1
- Readme mentions Serde not tokio-uds
- Add me as owner to crate? HOT 1
- Use with /dev/net/tun HOT 1
- Support Windows
- Compatibility with tokio crate (not tokio-core) HOT 6
- ucred problems on openbsd HOT 1
- The use of `io::Result` instead of `futures::Async` HOT 2
- Currently doesn't expose any way to make a UnixListener from a raw fd, even indirectly HOT 1
- Release new version with from_listener method HOT 2
- Example of reading from a Unix socket HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tokio-uds.