Git Product home page Git Product logo

parity-tokio-ipc's Introduction

parity-tokio-ipc

CI Documentation

This crate abstracts interprocess transport for UNIX/Windows.

It utilizes unix sockets on UNIX (via tokio::net::UnixStream) and named pipes on windows (via tokio::net::windows::named_pipe module).

Endpoint is transport-agnostic interface for incoming connections:

use parity_tokio_ipc::Endpoint;
use futures::stream::StreamExt;

// For testing purposes only - instead, use a path to an actual socket or a pipe
let addr = parity_tokio_ipc::dummy_endpoint();

let server = async move {
    Endpoint::new(addr)
        .incoming()
        .expect("Couldn't set up server")
        .for_each(|conn| async {
            match conn {
                Ok(stream) => println!("Got connection!"),
                Err(e) => eprintln!("Error when receiving connection: {:?}", e),
            }
        });
};

let rt = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
rt.block_on(server);

License

parity-tokio-ipc is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See LICENSE-APACHE, and LICENSE-MIT for details.

parity-tokio-ipc's People

Contributors

c0gent avatar demi-marie avatar ff14wed avatar nikvolf avatar nukemandan avatar parasyte avatar pinkisemils avatar seunlanlege avatar xanewok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parity-tokio-ipc's Issues

Addition of license?

Is there any chance of having a non-copyleft open source license added to this crate, e.g. MIT or Apache?

I think this crate is extremely useful and I was hoping to use it in a project that I'm working on. I was just about to write something similar when I came across your discussion on alexcrichton/tokio-named-pipes#1. I know your implementation is still new, but it looks reasonably solid.

Panic on windows:The filename, directory name, or volume label syntax is incorrect

I run the example on windows and got an error: "The filename, directory name, or volume label syntax is incorrect". I try to change the ipc file path, and also not work.

 wmic os get version

Version
10.0.18363

This is the backtrace:

.\target\debug\examples\server.exe test.ipc
thread 'main' panicked at 'failed to open new socket: Os { code: 123, kind: Other, message: "The filename, directory name, or volume label syntax is incorrect." }', examples\server.rs:14:24
stack backtrace:
   0:     0x7ff701d453bf - backtrace::backtrace::trace_unsynchronized
                               at C:\Users\VssAdministrator\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.44\src\backtrace\mod.rs:66
   1:     0x7ff701d453bf - std::sys_common::backtrace::_print_fmt
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\sys_common\backtrace.rs:78
   2:     0x7ff701d453bf - std::sys_common::backtrace::_print::{{impl}}::fmt
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\sys_common\backtrace.rs:59
   3:     0x7ff701d546bb - core::fmt::write
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libcore\fmt\mod.rs:1063
   4:     0x7ff701d42bfc - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\io\mod.rs:1426
   5:     0x7ff701d4835c - std::sys_common::backtrace::_print
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\sys_common\backtrace.rs:62
   6:     0x7ff701d4835c - std::sys_common::backtrace::print
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\sys_common\backtrace.rs:49
   7:     0x7ff701d4835c - std::panicking::default_hook::{{closure}}
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\panicking.rs:204
   8:     0x7ff701d47faf - std::panicking::default_hook
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\panicking.rs:224
   9:     0x7ff701d48b37 - std::panicking::rust_panic_with_hook
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\panicking.rs:470
  10:     0x7ff701d486bf - std::panicking::begin_panic_handler
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\panicking.rs:378
  11:     0x7ff701d539c0 - core::panicking::panic_fmt
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libcore\panicking.rs:85
  12:     0x7ff701d537e3 - core::option::expect_none_failed
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libcore\option.rs:1211
  13:     0x7ff701cc1c0a - core::result::Result<parity_tokio_ipc::win::Incoming, std::io::error::Error>::expect<parity_tokio_ipc::win::Incoming,std::io::error::Error>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\src\libcore\result.rs:961
  14:     0x7ff701cc3299 - server::run_server::{{closure}}
                               at C:\Users\jolestar\opensource\src\github.com\NikVolf\parity-tokio-ipc\examples\server.rs:14
  15:     0x7ff701cc6871 - std::future::{{impl}}::poll<generator-0>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\src\libstd\future.rs:44
  16:     0x7ff701cc6557 - std::future::poll_with_tls_context<std::future::GenFuture<generator-0>>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\src\libstd\future.rs:102
  17:     0x7ff701cc3bfc - server::main::{{closure}}
                               at C:\Users\jolestar\opensource\src\github.com\NikVolf\parity-tokio-ipc\examples\server.rs:46
  18:     0x7ff701cc66b1 - std::future::{{impl}}::poll<generator-0>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\src\libstd\future.rs:44
  19:     0x7ff701cc9803 - tokio::runtime::basic_scheduler::{{impl}}::block_on::{{closure}}::{{closure}}<tokio::park::either::Either<tokio::time::driver::Driver<tokio::park::either::Either<tokio::io::driver::Driver, tokio::park::thread::ParkThread>>, tokio::park::either::Either<tok
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\basic_scheduler.rs:131
  20:     0x7ff701cc1246 - tokio::coop::with_budget::{{closure}}<core::task::poll::Poll<()>,closure-0>
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\coop.rs:127
  21:     0x7ff701cd22a4 - std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget>>::try_with<core::cell::Cell<tokio::coop::Budget>,closure-0,core::task::poll::Poll<()>>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\src\libstd\thread\local.rs:262
  22:     0x7ff701cd189d - std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget>>::with<core::cell::Cell<tokio::coop::Budget>,closure-0,core::task::poll::Poll<()>>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\src\libstd\thread\local.rs:239
  23:     0x7ff701cc92d7 - tokio::coop::with_budget
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\coop.rs:120
  24:     0x7ff701cc92d7 - tokio::coop::budget
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\coop.rs:96
  25:     0x7ff701cc92d7 - tokio::runtime::basic_scheduler::{{impl}}::block_on::{{closure}}<tokio::park::either::Either<tokio::time::driver::Driver<tokio::park::either::Either<tokio::io::driver::Driver, tokio::park::thread::ParkThread>>, tokio::park::either::Either<tokio::io::drive
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\basic_scheduler.rs:131
  26:     0x7ff701cc9cba - tokio::runtime::basic_scheduler::enter::{{closure}}<closure-0,(),tokio::park::either::Either<tokio::time::driver::Driver<tokio::park::either::Either<tokio::io::driver::Driver, tokio::park::thread::ParkThread>>, tokio::park::either::Either<tokio::io::drive
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\basic_scheduler.rs:213
  27:     0x7ff701cc57a4 - tokio::macros::scoped_tls::ScopedKey<tokio::runtime::basic_scheduler::Context>::set<tokio::runtime::basic_scheduler::Context,closure-0,()>
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\macros\scoped_tls.rs:63
  28:     0x7ff701cc9b3c - tokio::runtime::basic_scheduler::enter<closure-0,(),tokio::park::either::Either<tokio::time::driver::Driver<tokio::park::either::Either<tokio::io::driver::Driver, tokio::park::thread::ParkThread>>, tokio::park::either::Either<tokio::io::driver::Driver, to
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\basic_scheduler.rs:213
  29:     0x7ff701cc911e - tokio::runtime::basic_scheduler::BasicScheduler<tokio::park::either::Either<tokio::time::driver::Driver<tokio::park::either::Either<tokio::io::driver::Driver, tokio::park::thread::ParkThread>>, tokio::park::either::Either<tokio::io::driver::Driver, tokio:
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\basic_scheduler.rs:123
  30:     0x7ff701ccbb01 - tokio::runtime::{{impl}}::block_on::{{closure}}<std::future::GenFuture<generator-0>>
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\mod.rs:444
  31:     0x7ff701cca272 - tokio::runtime::context::enter<closure-0,()>
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\context.rs:72
  32:     0x7ff701ccc0df - tokio::runtime::handle::Handle::enter<closure-0,()>
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\handle.rs:76
  33:     0x7ff701ccba7e - tokio::runtime::Runtime::block_on<std::future::GenFuture<generator-0>>
                               at C:\Users\jolestar\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.21\src\runtime\mod.rs:441
  34:     0x7ff701cc4956 - server::main
                               at C:\Users\jolestar\opensource\src\github.com\NikVolf\parity-tokio-ipc\examples\server.rs:43
  35:     0x7ff701cc9e0b - std::rt::lang_start::{{closure}}<()>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\src\libstd\rt.rs:67
  36:     0x7ff701d48557 - std::rt::lang_start_internal::{{closure}}
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\rt.rs:52
  37:     0x7ff701d48557 - std::panicking::try::do_call<closure-0,i32>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\panicking.rs:303
  38:     0x7ff701d4b472 - panic_unwind::__rust_maybe_catch_panic
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libpanic_unwind\lib.rs:86
  39:     0x7ff701d48d78 - std::panicking::try
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\panicking.rs:281
  40:     0x7ff701d48d78 - std::panic::catch_unwind
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\panic.rs:394
  41:     0x7ff701d48d78 - std::rt::lang_start_internal
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\/src\libstd\rt.rs:51
  42:     0x7ff701cc9de3 - std::rt::lang_start<()>
                               at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd\src\libstd\rt.rs:67
  43:     0x7ff701cc4a00 - main
  44:     0x7ff701d58d50 - invoke_main
                               at d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  45:     0x7ff701d58d50 - __scrt_common_main_seh
                               at d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  46:     0x7ff86f567bd4 - BaseThreadInitThunk
  47:     0x7ff870a4ce51 - RtlUserThreadStart

Simple pipe-server hanging forever

Thanks for providing this crate. I'm new to rust and tokio, so please forgive me if this looks dumb.

However, I encountered a hanging issue when using it on Windows. I'm building an IpcServer as a Future from an Incoming and then I run it with tokio. I got an IPC client which can connect (with CreateFile) to the pipe successfully. The client can even write to the pipe asynchronously. But IpcServer::poll never fires again except for the first time.

I'm pretty sure this is related to my code. Would you please kindly point it out? Thanks.

use futures::prelude::*;
use parity_tokio_ipc::{Endpoint, Incoming};
use tokio;
use std::io::ErrorKind;

const DAEMON_PIPE_NAME: &str = "\\\\.\\pipe\\TestPipe\\ServiceControl\0";

pub struct IpcServer {
    incoming: Incoming,
}

impl IpcServer {
    pub fn new() -> Self {
        let endpoint = Endpoint::new(DAEMON_PIPE_NAME.to_string());

        let incoming = match endpoint.incoming(&tokio::reactor::Handle::default()) {
            Ok(inc) => inc,
            Err(e) => {
                println!("IpcServer: Endpoint creation failed {:?}", e);
                panic!("Check the pipe");
            }
        };

        IpcServer {
            incoming,
        }
    }
}

impl Future for IpcServer {
    type Item = ();
    type Error = ();

    fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
        loop {
            match self.incoming.poll() {
                Ok(Async::Ready(Some((_, _)))) => {
                    println!("IpcServer: new pipe incoming");
                    continue;
                }

                Ok(Async::Ready(None)) => {
                    panic!("impossible!");
                }

                Ok(Async::NotReady) => return Ok(Async::NotReady),

                Err(e) => {
                    match e.kind() {
                        ErrorKind::BrokenPipe | ErrorKind::Interrupted => continue,
                        _ => {
                            println!("IpcServer: endpoint connection error {:?}", e);
                            return Err(());
                        }
                    }
                } 
            }
        }
    }
}

fn main() {
    tokio::run(IpcServer::new());
}

Publishing on crates.io

How about we start publishing this library on crates.io? It'd be a lot easier to use this library then, especially when we introduce breaking changes. I understand that we should probably do some more work on documenting it, but aside from that, all of our dependencies are either owned by @NikVolf or are published on crates.io already.

Aside from putting tokio-named-pipes on crates.io and documenting the security attributes properly for both platforms, are there any more tasks that should be done before the crate is published?

If any of the contributors/owners are categorically opposed to this, I'm OK with that as well ๐Ÿ™‚

Migrate from winapi to windows-rs

It doesn't seem that parity-tokio-ipc can be built any longer on my windows 11 box:

error[E0432]: unresolved import `winapi::shared::winerror`
 --> C:\Users\pronebird\.cargo\registry\src\index.crates.io-6f17d22bba15001f\parity-tokio-ipc-0.9.0\src\win.rs:1:21
  |
1 | use winapi::shared::winerror::{ERROR_PIPE_BUSY, ERROR_SUCCESS};
  |                     ^^^^^^^^ could not find `winerror` in `shared`

Perhaps it's time to ditch the winapi-rs and move on to official crate?

SecurityAttribute::allow_everyone_connect doesn't work on Windows as expected

I have two IPC endpoints: the server part is a system service which calls Endpoint::new and then endpoint.set_security_attributes(SecurityAttributes::empty().allow_everyone_connect().

The client part is a user-level app which does read/write to it. An attempt to write to this endpoint from the client causes "Access denied" system error.
The problem goes away if I use allow_everyone_create and the code is guarded like this:

            if cfg!(windows) {
                endpoint.set_security_attributes(SecurityAttributes::allow_everyone_create()?);
            } else {
                endpoint.set_security_attributes(SecurityAttributes::empty().allow_everyone_connect()?);
            }

The only difference as far as I can see is FILE_WRITE_DATA vs GENERIC_WRITE.

P.S. Another thing I noticed is that the API around SecurityAttributes is not very consistent: some methods are static, others require &self parameter.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.