diff options
| author | Jorge Aparicio <japaricious@gmail.com> | 2014-12-07 14:15:25 -0500 |
|---|---|---|
| committer | Jorge Aparicio <japaricious@gmail.com> | 2014-12-13 17:03:47 -0500 |
| commit | cdbb3ca9b776b066e2c93acfb60da8537d2b1c9b (patch) | |
| tree | 18a305205c51df4501a5e5e73c4b275242fb5a25 /src/libstd/sys/common | |
| parent | be53d619f874cbe8e4d87f900060561d16405d53 (diff) | |
| download | rust-cdbb3ca9b776b066e2c93acfb60da8537d2b1c9b.tar.gz rust-cdbb3ca9b776b066e2c93acfb60da8537d2b1c9b.zip | |
libstd: use unboxed closures
Diffstat (limited to 'src/libstd/sys/common')
| -rw-r--r-- | src/libstd/sys/common/helper_thread.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sys/common/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/common/net.rs | 37 |
3 files changed, 27 insertions, 21 deletions
diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs index c0018c5d970..6c5fc3005ed 100644 --- a/src/libstd/sys/common/helper_thread.rs +++ b/src/libstd/sys/common/helper_thread.rs @@ -70,9 +70,10 @@ impl<M: Send> Helper<M> { /// passed to the helper thread in a separate task. /// /// This function is safe to be called many times. - pub fn boot<T: Send>(&'static self, - f: || -> T, - helper: fn(helper_signal::signal, Receiver<M>, T)) { + pub fn boot<T, F>(&'static self, f: F, helper: fn(helper_signal::signal, Receiver<M>, T)) where + T: Send, + F: FnOnce() -> T, + { unsafe { let _guard = self.lock.lock(); if !*self.initialized.get() { diff --git a/src/libstd/sys/common/mod.rs b/src/libstd/sys/common/mod.rs index f8861c20464..73e1c7bd9e5 100644 --- a/src/libstd/sys/common/mod.rs +++ b/src/libstd/sys/common/mod.rs @@ -69,7 +69,9 @@ pub fn mkerr_libc<T: Int>(ret: T) -> IoResult<()> { } } -pub fn keep_going(data: &[u8], f: |*const u8, uint| -> i64) -> i64 { +pub fn keep_going<F>(data: &[u8], mut f: F) -> i64 where + F: FnMut(*const u8, uint) -> i64, +{ let origamt = data.len(); let mut data = data.as_ptr(); let mut amt = origamt; diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index ddc6dd021c3..73da200e162 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -344,10 +344,10 @@ pub fn get_host_addresses(host: Option<&str>, servname: Option<&str>, // [1] http://twistedmatrix.com/pipermail/twisted-commits/2012-April/034692.html // [2] http://stackoverflow.com/questions/19819198/does-send-msg-dontwait -pub fn read<T>(fd: sock_t, - deadline: u64, - lock: || -> T, - read: |bool| -> libc::c_int) -> IoResult<uint> { +pub fn read<T, L, R>(fd: sock_t, deadline: u64, mut lock: L, mut read: R) -> IoResult<uint> where + L: FnMut() -> T, + R: FnMut(bool) -> libc::c_int, +{ let mut ret = -1; if deadline == 0 { ret = retry(|| read(false)); @@ -386,12 +386,15 @@ pub fn read<T>(fd: sock_t, } } -pub fn write<T>(fd: sock_t, - deadline: u64, - buf: &[u8], - write_everything: bool, - lock: || -> T, - write: |bool, *const u8, uint| -> i64) -> IoResult<uint> { +pub fn write<T, L, W>(fd: sock_t, + deadline: u64, + buf: &[u8], + write_everything: bool, + mut lock: L, + mut write: W) -> IoResult<uint> where + L: FnMut() -> T, + W: FnMut(bool, *const u8, uint) -> i64, +{ let mut ret = -1; let mut written = 0; if deadline == 0 { @@ -674,8 +677,8 @@ impl TcpStream { pub fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { let fd = self.fd(); - let dolock = || self.lock_nonblocking(); - let doread = |nb| unsafe { + let dolock = |&:| self.lock_nonblocking(); + let doread = |&mut: nb| unsafe { let flags = if nb {c::MSG_DONTWAIT} else {0}; libc::recv(fd, buf.as_mut_ptr() as *mut libc::c_void, @@ -687,8 +690,8 @@ impl TcpStream { pub fn write(&mut self, buf: &[u8]) -> IoResult<()> { let fd = self.fd(); - let dolock = || self.lock_nonblocking(); - let dowrite = |nb: bool, buf: *const u8, len: uint| unsafe { + let dolock = |&:| self.lock_nonblocking(); + let dowrite = |&: nb: bool, buf: *const u8, len: uint| unsafe { let flags = if nb {c::MSG_DONTWAIT} else {0}; libc::send(fd, buf as *const _, @@ -822,7 +825,7 @@ impl UdpSocket { let mut addrlen: libc::socklen_t = mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t; - let dolock = || self.lock_nonblocking(); + let dolock = |&:| self.lock_nonblocking(); let n = try!(read(fd, self.read_deadline, dolock, |nb| unsafe { let flags = if nb {c::MSG_DONTWAIT} else {0}; libc::recvfrom(fd, @@ -843,8 +846,8 @@ impl UdpSocket { let dstp = &storage as *const _ as *const libc::sockaddr; let fd = self.fd(); - let dolock = || self.lock_nonblocking(); - let dowrite = |nb, buf: *const u8, len: uint| unsafe { + let dolock = |&: | self.lock_nonblocking(); + let dowrite = |&mut: nb, buf: *const u8, len: uint| unsafe { let flags = if nb {c::MSG_DONTWAIT} else {0}; libc::sendto(fd, buf as *const libc::c_void, |
