about summary refs log tree commit diff
path: root/src/libstd/sys/unix/weak.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-02-04 15:22:41 -0800
committerAlex Crichton <alex@alexcrichton.com>2016-02-05 17:11:02 -0800
commit46315184cb74a98dbd10a0d300a0c3ee62b78049 (patch)
tree2a83c03adb395ed5ce803b1db2d216453728f9e5 /src/libstd/sys/unix/weak.rs
parent1a31e1c09f89daeefa06ca9336912e9bcadb0c1d (diff)
downloadrust-46315184cb74a98dbd10a0d300a0c3ee62b78049.tar.gz
rust-46315184cb74a98dbd10a0d300a0c3ee62b78049.zip
std: Add support for accept4 on Linux
This is necessary to atomically accept a socket and set the CLOEXEC flag at the
same time. Support only appeared in Linux 2.6.28 so we have to dynamically
determine which syscall we're supposed to call in this case.
Diffstat (limited to 'src/libstd/sys/unix/weak.rs')
-rw-r--r--src/libstd/sys/unix/weak.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/weak.rs b/src/libstd/sys/unix/weak.rs
index 2cbcd62f533..e6f85c08d12 100644
--- a/src/libstd/sys/unix/weak.rs
+++ b/src/libstd/sys/unix/weak.rs
@@ -61,7 +61,11 @@ impl<F> Weak<F> {
             if self.addr.load(Ordering::SeqCst) == 1 {
                 self.addr.store(fetch(self.name), Ordering::SeqCst);
             }
-            mem::transmute::<&AtomicUsize, Option<&F>>(&self.addr)
+            if self.addr.load(Ordering::SeqCst) == 0 {
+                None
+            } else {
+                mem::transmute::<&AtomicUsize, Option<&F>>(&self.addr)
+            }
         }
     }
 }