mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 16:51:34 +00:00
Don't wrap yamux::Connection in a mutex (#719)
Get rid of double mutex * Use inherent `poll()` that takes an immutable ref * Remove parking_lot dependency from yamux * Update muxers/yamux/Cargo.toml Co-Authored-By: dvdplm <dvdplm@gmail.com>
This commit is contained in:
@ -9,6 +9,5 @@ bytes = "0.4"
|
|||||||
futures = "0.1"
|
futures = "0.1"
|
||||||
libp2p-core = { path = "../../core" }
|
libp2p-core = { path = "../../core" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
parking_lot = "0.7"
|
|
||||||
tokio-io = "0.1"
|
tokio-io = "0.1"
|
||||||
yamux = "0.1"
|
yamux = "0.1.1"
|
||||||
|
@ -23,27 +23,25 @@ extern crate futures;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate libp2p_core;
|
extern crate libp2p_core;
|
||||||
extern crate parking_lot;
|
|
||||||
extern crate tokio_io;
|
extern crate tokio_io;
|
||||||
extern crate yamux;
|
extern crate yamux;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::{future::{self, FutureResult}, prelude::*};
|
use futures::{future::{self, FutureResult}, prelude::*};
|
||||||
use libp2p_core::{muxing::Shutdown, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}};
|
use libp2p_core::{muxing::Shutdown, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}};
|
||||||
use parking_lot::Mutex;
|
|
||||||
use std::{io, iter};
|
use std::{io, iter};
|
||||||
use std::io::{Error as IoError};
|
use std::io::{Error as IoError};
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
|
|
||||||
pub struct Yamux<C>(Mutex<yamux::Connection<C>>);
|
pub struct Yamux<C>(yamux::Connection<C>);
|
||||||
|
|
||||||
impl<C> Yamux<C>
|
impl<C> Yamux<C>
|
||||||
where
|
where
|
||||||
C: AsyncRead + AsyncWrite + 'static
|
C: AsyncRead + AsyncWrite + 'static
|
||||||
{
|
{
|
||||||
pub fn new(c: C, cfg: yamux::Config, mode: yamux::Mode) -> Self {
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +54,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn poll_inbound(&self) -> Poll<Option<Self::Substream>, IoError> {
|
fn poll_inbound(&self) -> Poll<Option<Self::Substream>, IoError> {
|
||||||
match self.0.lock().poll() {
|
match self.0.poll() {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("connection error: {}", e);
|
error!("connection error: {}", e);
|
||||||
Err(io::Error::new(io::ErrorKind::Other, e))
|
Err(io::Error::new(io::ErrorKind::Other, e))
|
||||||
@ -69,7 +67,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn open_outbound(&self) -> Self::OutboundSubstream {
|
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)
|
future::result(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,12 +106,12 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn shutdown(&self, _: Shutdown) -> Poll<(), IoError> {
|
fn shutdown(&self, _: Shutdown) -> Poll<(), IoError> {
|
||||||
self.0.lock().shutdown()
|
self.0.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn flush_all(&self) -> Poll<(), IoError> {
|
fn flush_all(&self) -> Poll<(), IoError> {
|
||||||
self.0.lock().flush()
|
self.0.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user