mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-27 17:52:56 +01:00
remove unsafe cell from ws client
This commit is contained in:
parent
261ad31b9a
commit
362b14c2f7
@ -317,9 +317,6 @@ impl Pipeline {
|
||||
if self.conn.is_none() {
|
||||
return Ok(Async::Ready(None));
|
||||
}
|
||||
let conn: &mut Connection =
|
||||
unsafe { &mut *(self.conn.as_mut().unwrap() as *mut _) };
|
||||
|
||||
let mut need_run = false;
|
||||
|
||||
// need write?
|
||||
@ -337,6 +334,9 @@ impl Pipeline {
|
||||
|
||||
// need read?
|
||||
if self.parser.is_some() {
|
||||
let conn: &mut Connection =
|
||||
unsafe { &mut *(self.conn.as_mut().unwrap() as *mut _) };
|
||||
|
||||
loop {
|
||||
match self
|
||||
.parser
|
||||
|
@ -48,7 +48,6 @@ impl Extensions {
|
||||
/// If a extension of this type existed, it will be returned.
|
||||
pub fn remove<T: 'static>(&mut self) -> Option<T> {
|
||||
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>)
|
||||
.downcast()
|
||||
.ok()
|
||||
|
@ -1,5 +1,5 @@
|
||||
//! Http client request
|
||||
use std::cell::UnsafeCell;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::time::Duration;
|
||||
use std::{fmt, io, str};
|
||||
@ -422,7 +422,7 @@ impl Future for ClientHandshake {
|
||||
closed: false,
|
||||
};
|
||||
|
||||
let inner = Rc::new(UnsafeCell::new(inner));
|
||||
let inner = Rc::new(RefCell::new(inner));
|
||||
Ok(Async::Ready((
|
||||
ClientReader {
|
||||
inner: Rc::clone(&inner),
|
||||
@ -435,7 +435,7 @@ impl Future for ClientHandshake {
|
||||
|
||||
/// Websocket reader client
|
||||
pub struct ClientReader {
|
||||
inner: Rc<UnsafeCell<Inner>>,
|
||||
inner: Rc<RefCell<Inner>>,
|
||||
max_size: usize,
|
||||
}
|
||||
|
||||
@ -451,7 +451,7 @@ impl Stream for ClientReader {
|
||||
|
||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
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 {
|
||||
return Ok(Async::Ready(None));
|
||||
}
|
||||
@ -507,14 +507,14 @@ impl Stream for ClientReader {
|
||||
|
||||
/// Websocket writer client
|
||||
pub struct ClientWriter {
|
||||
inner: Rc<UnsafeCell<Inner>>,
|
||||
inner: Rc<RefCell<Inner>>,
|
||||
}
|
||||
|
||||
impl ClientWriter {
|
||||
/// Write payload
|
||||
#[inline]
|
||||
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 {
|
||||
let _ = inner.tx.unbounded_send(data.take());
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user