native: Remove UnsafeArc in favor of just Arc
This commit is contained in:
parent
4c8a4d241a
commit
88b322c5fd
6 changed files with 30 additions and 43 deletions
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
//! Blocking posix-based file I/O
|
||||
|
||||
use alloc::arc::Arc;
|
||||
use libc::{c_int, c_void};
|
||||
use libc;
|
||||
use std::c_str::CString;
|
||||
|
|
@ -17,7 +18,6 @@ use std::io::IoError;
|
|||
use std::io;
|
||||
use std::mem;
|
||||
use std::rt::rtio;
|
||||
use std::sync::arc::UnsafeArc;
|
||||
|
||||
use io::{IoResult, retry, keep_going};
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ struct Inner {
|
|||
}
|
||||
|
||||
pub struct FileDesc {
|
||||
inner: UnsafeArc<Inner>
|
||||
inner: Arc<Inner>
|
||||
}
|
||||
|
||||
impl FileDesc {
|
||||
|
|
@ -42,7 +42,7 @@ impl FileDesc {
|
|||
/// Note that all I/O operations done on this object will be *blocking*, but
|
||||
/// they do not require the runtime to be active.
|
||||
pub fn new(fd: fd_t, close_on_drop: bool) -> FileDesc {
|
||||
FileDesc { inner: UnsafeArc::new(Inner {
|
||||
FileDesc { inner: Arc::new(Inner {
|
||||
fd: fd,
|
||||
close_on_drop: close_on_drop
|
||||
}) }
|
||||
|
|
@ -79,11 +79,7 @@ impl FileDesc {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fd(&self) -> fd_t {
|
||||
// This unsafety is fine because we're just reading off the file
|
||||
// descriptor, no one is modifying this.
|
||||
unsafe { (*self.inner.get()).fd }
|
||||
}
|
||||
pub fn fd(&self) -> fd_t { self.inner.fd }
|
||||
}
|
||||
|
||||
impl io::Reader for FileDesc {
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@
|
|||
|
||||
//! Blocking win32-based file I/O
|
||||
|
||||
use alloc::arc::Arc;
|
||||
use libc::{c_int, c_void};
|
||||
use libc;
|
||||
use std::c_str::CString;
|
||||
use std::io::IoError;
|
||||
use std::io;
|
||||
use libc::{c_int, c_void};
|
||||
use libc;
|
||||
use std::mem;
|
||||
use std::os::win32::{as_utf16_p, fill_utf16_buf_and_decode};
|
||||
use std::ptr;
|
||||
use std::rt::rtio;
|
||||
use std::str;
|
||||
use std::sync::arc::UnsafeArc;
|
||||
use std::vec;
|
||||
|
||||
use io::IoResult;
|
||||
|
|
@ -33,7 +33,7 @@ struct Inner {
|
|||
}
|
||||
|
||||
pub struct FileDesc {
|
||||
inner: UnsafeArc<Inner>
|
||||
inner: Arc<Inner>
|
||||
}
|
||||
|
||||
impl FileDesc {
|
||||
|
|
@ -46,7 +46,7 @@ impl FileDesc {
|
|||
/// Note that all I/O operations done on this object will be *blocking*, but
|
||||
/// they do not require the runtime to be active.
|
||||
pub fn new(fd: fd_t, close_on_drop: bool) -> FileDesc {
|
||||
FileDesc { inner: UnsafeArc::new(Inner {
|
||||
FileDesc { inner: Arc::new(Inner {
|
||||
fd: fd,
|
||||
close_on_drop: close_on_drop
|
||||
}) }
|
||||
|
|
@ -85,11 +85,7 @@ impl FileDesc {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn fd(&self) -> fd_t {
|
||||
// This unsafety is fine because we're just reading off the file
|
||||
// descriptor, no one is modifying this.
|
||||
unsafe { (*self.inner.get()).fd }
|
||||
}
|
||||
pub fn fd(&self) -> fd_t { self.inner.fd }
|
||||
|
||||
pub fn handle(&self) -> libc::HANDLE {
|
||||
unsafe { libc::get_osfhandle(self.fd()) as libc::HANDLE }
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use alloc::arc::Arc;
|
||||
use libc;
|
||||
use std::io::net::ip;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::rt::rtio;
|
||||
use std::sync::arc::UnsafeArc;
|
||||
use std::unstable::mutex;
|
||||
|
||||
use super::{IoResult, retry, keep_going};
|
||||
|
|
@ -235,7 +235,7 @@ pub fn init() {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub struct TcpStream {
|
||||
inner: UnsafeArc<Inner>,
|
||||
inner: Arc<Inner>,
|
||||
read_deadline: u64,
|
||||
write_deadline: u64,
|
||||
}
|
||||
|
|
@ -282,16 +282,13 @@ impl TcpStream {
|
|||
|
||||
fn new(inner: Inner) -> TcpStream {
|
||||
TcpStream {
|
||||
inner: UnsafeArc::new(inner),
|
||||
inner: Arc::new(inner),
|
||||
read_deadline: 0,
|
||||
write_deadline: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fd(&self) -> sock_t {
|
||||
// This unsafety is fine because it's just a read-only arc
|
||||
unsafe { (*self.inner.get()).fd }
|
||||
}
|
||||
pub fn fd(&self) -> sock_t { self.inner.fd }
|
||||
|
||||
fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> {
|
||||
setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_NODELAY,
|
||||
|
|
@ -536,7 +533,7 @@ impl rtio::RtioTcpAcceptor for TcpAcceptor {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub struct UdpSocket {
|
||||
inner: UnsafeArc<Inner>,
|
||||
inner: Arc<Inner>,
|
||||
read_deadline: u64,
|
||||
write_deadline: u64,
|
||||
}
|
||||
|
|
@ -545,7 +542,7 @@ impl UdpSocket {
|
|||
pub fn bind(addr: ip::SocketAddr) -> IoResult<UdpSocket> {
|
||||
let fd = try!(socket(addr, libc::SOCK_DGRAM));
|
||||
let ret = UdpSocket {
|
||||
inner: UnsafeArc::new(Inner::new(fd)),
|
||||
inner: Arc::new(Inner::new(fd)),
|
||||
read_deadline: 0,
|
||||
write_deadline: 0,
|
||||
};
|
||||
|
|
@ -560,10 +557,7 @@ impl UdpSocket {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn fd(&self) -> sock_t {
|
||||
// unsafety is fine because it's just a read-only arc
|
||||
unsafe { (*self.inner.get()).fd }
|
||||
}
|
||||
pub fn fd(&self) -> sock_t { self.inner.fd }
|
||||
|
||||
pub fn set_broadcast(&mut self, on: bool) -> IoResult<()> {
|
||||
setsockopt(self.fd(), libc::SOL_SOCKET, libc::SO_BROADCAST,
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use alloc::arc::Arc;
|
||||
use libc;
|
||||
use std::c_str::CString;
|
||||
use std::intrinsics;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::rt::rtio;
|
||||
use std::sync::arc::UnsafeArc;
|
||||
use std::unstable::mutex;
|
||||
|
||||
use super::{IoResult, retry};
|
||||
|
|
@ -108,7 +108,7 @@ fn bind(addr: &CString, ty: libc::c_int) -> IoResult<Inner> {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub struct UnixStream {
|
||||
inner: UnsafeArc<Inner>,
|
||||
inner: Arc<Inner>,
|
||||
read_deadline: u64,
|
||||
write_deadline: u64,
|
||||
}
|
||||
|
|
@ -117,11 +117,11 @@ impl UnixStream {
|
|||
pub fn connect(addr: &CString,
|
||||
timeout: Option<u64>) -> IoResult<UnixStream> {
|
||||
connect(addr, libc::SOCK_STREAM, timeout).map(|inner| {
|
||||
UnixStream::new(UnsafeArc::new(inner))
|
||||
UnixStream::new(Arc::new(inner))
|
||||
})
|
||||
}
|
||||
|
||||
fn new(inner: UnsafeArc<Inner>) -> UnixStream {
|
||||
fn new(inner: Arc<Inner>) -> UnixStream {
|
||||
UnixStream {
|
||||
inner: inner,
|
||||
read_deadline: 0,
|
||||
|
|
@ -129,7 +129,7 @@ impl UnixStream {
|
|||
}
|
||||
}
|
||||
|
||||
fn fd(&self) -> fd_t { unsafe { (*self.inner.get()).fd } }
|
||||
fn fd(&self) -> fd_t { self.inner.fd }
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn lock_nonblocking(&self) {}
|
||||
|
|
@ -138,7 +138,7 @@ impl UnixStream {
|
|||
fn lock_nonblocking<'a>(&'a self) -> net::Guard<'a> {
|
||||
let ret = net::Guard {
|
||||
fd: self.fd(),
|
||||
guard: unsafe { (*self.inner.get()).lock.lock() },
|
||||
guard: self.inner.lock.lock(),
|
||||
};
|
||||
assert!(util::set_nonblocking(self.fd(), true).is_ok());
|
||||
ret
|
||||
|
|
@ -254,7 +254,7 @@ impl UnixAcceptor {
|
|||
&mut size as *mut libc::socklen_t) as libc::c_int
|
||||
}) {
|
||||
-1 => Err(super::last_error()),
|
||||
fd => Ok(UnixStream::new(UnsafeArc::new(Inner::new(fd))))
|
||||
fd => Ok(UnixStream::new(Arc::new(Inner::new(fd))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@
|
|||
//! the test suite passing (the suite is in libstd), and that's good enough for
|
||||
//! me!
|
||||
|
||||
use alloc::arc::Arc;
|
||||
use libc;
|
||||
use std::c_str::CString;
|
||||
use std::intrinsics;
|
||||
|
|
@ -92,7 +93,6 @@ use std::os::win32::as_utf16_p;
|
|||
use std::os;
|
||||
use std::ptr;
|
||||
use std::rt::rtio;
|
||||
use std::sync::arc::UnsafeArc;
|
||||
use std::sync::atomics;
|
||||
use std::unstable::mutex;
|
||||
|
||||
|
|
@ -195,7 +195,7 @@ pub fn await(handle: libc::HANDLE, deadline: u64,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
pub struct UnixStream {
|
||||
inner: UnsafeArc<Inner>,
|
||||
inner: Arc<Inner>,
|
||||
write: Option<Event>,
|
||||
read: Option<Event>,
|
||||
read_deadline: u64,
|
||||
|
|
@ -273,7 +273,7 @@ impl UnixStream {
|
|||
Err(super::last_error())
|
||||
} else {
|
||||
Ok(UnixStream {
|
||||
inner: UnsafeArc::new(inner),
|
||||
inner: Arc::new(inner),
|
||||
read: None,
|
||||
write: None,
|
||||
read_deadline: 0,
|
||||
|
|
@ -317,7 +317,7 @@ impl UnixStream {
|
|||
})
|
||||
}
|
||||
|
||||
fn handle(&self) -> libc::HANDLE { unsafe { (*self.inner.get()).handle } }
|
||||
fn handle(&self) -> libc::HANDLE { self.inner.handle }
|
||||
|
||||
fn read_closed(&self) -> bool {
|
||||
unsafe { (*self.inner.get()).read_closed.load(atomics::SeqCst) }
|
||||
|
|
@ -683,7 +683,7 @@ impl UnixAcceptor {
|
|||
|
||||
// Transfer ownership of our handle into this stream
|
||||
Ok(UnixStream {
|
||||
inner: UnsafeArc::new(Inner::new(handle)),
|
||||
inner: Arc::new(Inner::new(handle)),
|
||||
read: None,
|
||||
write: None,
|
||||
read_deadline: 0,
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@
|
|||
// answer is that you don't need them)
|
||||
#![feature(macro_rules)]
|
||||
|
||||
extern crate alloc;
|
||||
extern crate libc;
|
||||
|
||||
use std::os;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue