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

Don't wrap yamux::Connection in a mutex #719

Merged
merged 7 commits into from Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions muxers/yamux/Cargo.toml
Expand Up @@ -9,6 +9,5 @@ bytes = "0.4"
futures = "0.1"
libp2p-core = { path = "../../core" }
log = "0.4"
parking_lot = "0.7"
tokio-io = "0.1"
yamux = "0.1"
yamux = "0.1.1"
14 changes: 6 additions & 8 deletions muxers/yamux/src/lib.rs
Expand Up @@ -23,27 +23,25 @@ extern crate futures;
#[macro_use]
extern crate log;
extern crate libp2p_core;
extern crate parking_lot;
extern crate tokio_io;
extern crate yamux;

use bytes::Bytes;
use futures::{future::{self, FutureResult}, prelude::*};
use libp2p_core::{muxing::Shutdown, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}};
use parking_lot::Mutex;
use std::{io, iter};
use std::io::{Error as IoError};
use tokio_io::{AsyncRead, AsyncWrite};


pub struct Yamux<C>(Mutex<yamux::Connection<C>>);
pub struct Yamux<C>(yamux::Connection<C>);

impl<C> Yamux<C>
where
C: AsyncRead + AsyncWrite + 'static
{
pub fn new(c: C, cfg: yamux::Config, mode: yamux::Mode) -> Self {
Yamux(Mutex::new(yamux::Connection::new(c, cfg, mode)))
Yamux(yamux::Connection::new(c, cfg, mode))
}
}

Expand All @@ -56,7 +54,7 @@ where

#[inline]
fn poll_inbound(&self) -> Poll<Option<Self::Substream>, IoError> {
match self.0.lock().poll() {
match self.0.poll() {
Err(e) => {
error!("connection error: {}", e);
Err(io::Error::new(io::ErrorKind::Other, e))
Expand All @@ -69,7 +67,7 @@ where

#[inline]
fn open_outbound(&self) -> Self::OutboundSubstream {
let stream = self.0.lock().open_stream().map_err(|e| io::Error::new(io::ErrorKind::Other, e));
let stream = self.0.open_stream().map_err(|e| io::Error::new(io::ErrorKind::Other, e));
future::result(stream)
}

Expand Down Expand Up @@ -108,12 +106,12 @@ where

#[inline]
fn shutdown(&self, _: Shutdown) -> Poll<(), IoError> {
self.0.lock().shutdown()
self.0.shutdown()
}

#[inline]
fn flush_all(&self) -> Poll<(), IoError> {
self.0.lock().flush()
self.0.flush()
}
}

Expand Down