1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 16:02:59 +01:00

remove unsafe cell from ws client

This commit is contained in:
Nikolay Kim 2018-06-19 09:36:17 +06:00
parent 261ad31b9a
commit 362b14c2f7
3 changed files with 9 additions and 10 deletions

View File

@ -317,9 +317,6 @@ impl Pipeline {
if self.conn.is_none() { if self.conn.is_none() {
return Ok(Async::Ready(None)); return Ok(Async::Ready(None));
} }
let conn: &mut Connection =
unsafe { &mut *(self.conn.as_mut().unwrap() as *mut _) };
let mut need_run = false; let mut need_run = false;
// need write? // need write?
@ -337,6 +334,9 @@ impl Pipeline {
// need read? // need read?
if self.parser.is_some() { if self.parser.is_some() {
let conn: &mut Connection =
unsafe { &mut *(self.conn.as_mut().unwrap() as *mut _) };
loop { loop {
match self match self
.parser .parser

View File

@ -48,7 +48,6 @@ impl Extensions {
/// If a extension of this type existed, it will be returned. /// If a extension of this type existed, it will be returned.
pub fn remove<T: 'static>(&mut self) -> Option<T> { pub fn remove<T: 'static>(&mut self) -> Option<T> {
self.map.remove(&TypeId::of::<T>()).and_then(|boxed| { self.map.remove(&TypeId::of::<T>()).and_then(|boxed| {
//TODO: we can use unsafe and remove double checking the type id
(boxed as Box<Any + 'static>) (boxed as Box<Any + 'static>)
.downcast() .downcast()
.ok() .ok()

View File

@ -1,5 +1,5 @@
//! Http client request //! Http client request
use std::cell::UnsafeCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
use std::time::Duration; use std::time::Duration;
use std::{fmt, io, str}; use std::{fmt, io, str};
@ -422,7 +422,7 @@ impl Future for ClientHandshake {
closed: false, closed: false,
}; };
let inner = Rc::new(UnsafeCell::new(inner)); let inner = Rc::new(RefCell::new(inner));
Ok(Async::Ready(( Ok(Async::Ready((
ClientReader { ClientReader {
inner: Rc::clone(&inner), inner: Rc::clone(&inner),
@ -435,7 +435,7 @@ impl Future for ClientHandshake {
/// Websocket reader client /// Websocket reader client
pub struct ClientReader { pub struct ClientReader {
inner: Rc<UnsafeCell<Inner>>, inner: Rc<RefCell<Inner>>,
max_size: usize, max_size: usize,
} }
@ -451,7 +451,7 @@ impl Stream for ClientReader {
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> { fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
let max_size = self.max_size; let max_size = self.max_size;
let inner: &mut Inner = unsafe { &mut *self.inner.get() }; let mut inner = self.inner.borrow_mut();
if inner.closed { if inner.closed {
return Ok(Async::Ready(None)); return Ok(Async::Ready(None));
} }
@ -507,14 +507,14 @@ impl Stream for ClientReader {
/// Websocket writer client /// Websocket writer client
pub struct ClientWriter { pub struct ClientWriter {
inner: Rc<UnsafeCell<Inner>>, inner: Rc<RefCell<Inner>>,
} }
impl ClientWriter { impl ClientWriter {
/// Write payload /// Write payload
#[inline] #[inline]
fn write(&mut self, mut data: Binary) { fn write(&mut self, mut data: Binary) {
let inner: &mut Inner = unsafe { &mut *self.inner.get() }; let inner = self.inner.borrow_mut();
if !inner.closed { if !inner.closed {
let _ = inner.tx.unbounded_send(data.take()); let _ = inner.tx.unbounded_send(data.take());
} else { } else {