Implement Sync/Send for windows TCP types

This commit is contained in:
Flavio Percoco 2014-12-26 23:01:47 +01:00
parent bb315f25f8
commit f5d619caf9
1 changed files with 12 additions and 0 deletions

View File

@ -24,6 +24,9 @@ pub use sys_common::net::TcpStream;
pub struct Event(c::WSAEVENT);
unsafe impl Send for Event {}
unsafe impl Sync for Event {}
impl Event {
pub fn new() -> IoResult<Event> {
let event = unsafe { c::WSACreateEvent() };
@ -49,6 +52,9 @@ impl Drop for Event {
pub struct TcpListener { sock: sock_t }
unsafe impl Send for TcpListener {}
unsafe impl Sync for TcpListener {}
impl TcpListener {
pub fn bind(addr: ip::SocketAddr) -> IoResult<TcpListener> {
sys::init_net();
@ -109,6 +115,9 @@ pub struct TcpAcceptor {
deadline: u64,
}
unsafe impl Send for TcpAcceptor {}
unsafe impl Sync for TcpAcceptor {}
struct AcceptorInner {
listener: TcpListener,
abort: Event,
@ -116,6 +125,9 @@ struct AcceptorInner {
closed: atomic::AtomicBool,
}
unsafe impl Send for AcceptorInner {}
unsafe impl Sync for AcceptorInner {}
impl TcpAcceptor {
pub fn socket(&self) -> sock_t { self.inner.listener.socket() }