]> git.lizzy.rs Git - rust.git/blobdiff - src/libnative/io/net.rs
auto merge of #15999 : Kimundi/rust/fix_folder, r=nikomatsakis
[rust.git] / src / libnative / io / net.rs
index 23fd607aafeef74b05bedb4b57c8704fecf605b3..7a90ede8ca863283f79dd1f75666b4465cd2c76a 100644 (file)
 #[cfg(unix)]    pub type sock_t = super::file::fd_t;
 
 pub fn htons(u: u16) -> u16 {
-    u.to_big_endian()
+    u.to_be()
 }
 pub fn ntohs(u: u16) -> u16 {
-    Int::from_big_endian(u)
+    Int::from_be(u)
 }
 
 enum InAddr {
@@ -46,7 +46,7 @@ fn ip_to_inaddr(ip: rtio::IpAddr) -> InAddr {
                      (c as u32 <<  8) |
                      (d as u32 <<  0);
             InAddr(libc::in_addr {
-                s_addr: Int::from_big_endian(ip)
+                s_addr: Int::from_be(ip)
             })
         }
         rtio::Ipv6Addr(a, b, c, d, e, f, g, h) => {
@@ -105,7 +105,7 @@ fn socket(addr: rtio::SocketAddr, ty: libc::c_int) -> IoResult<sock_t> {
 fn setsockopt<T>(fd: sock_t, opt: libc::c_int, val: libc::c_int,
                  payload: T) -> IoResult<()> {
     unsafe {
-        let payload = &payload as *T as *libc::c_void;
+        let payload = &payload as *const T as *const libc::c_void;
         let ret = libc::setsockopt(fd, opt, val,
                                    payload,
                                    mem::size_of::<T>() as libc::socklen_t);
@@ -180,7 +180,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
             let storage: &libc::sockaddr_in = unsafe {
                 mem::transmute(storage)
             };
-            let ip = (storage.sin_addr.s_addr as u32).to_big_endian();
+            let ip = (storage.sin_addr.s_addr as u32).to_be();
             let a = (ip >> 24) as u8;
             let b = (ip >> 16) as u8;
             let c = (ip >>  8) as u8;
@@ -278,7 +278,7 @@ pub fn connect(addr: rtio::SocketAddr,
         let ret = TcpStream::new(Inner::new(fd));
 
         let (addr, len) = addr_to_sockaddr(addr);
-        let addrp = &addr as *_ as *libc::sockaddr;
+        let addrp = &addr as *const _ as *const libc::sockaddr;
         let len = len as libc::socklen_t;
 
         match timeout {
@@ -326,11 +326,13 @@ fn set_tcp_keepalive(&mut self, seconds: uint) -> IoResult<()> {
                    seconds as libc::c_int)
     }
     #[cfg(target_os = "freebsd")]
+    #[cfg(target_os = "dragonfly")]
     fn set_tcp_keepalive(&mut self, seconds: uint) -> IoResult<()> {
         setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_KEEPIDLE,
                    seconds as libc::c_int)
     }
-    #[cfg(not(target_os = "macos"), not(target_os = "ios"), not(target_os = "freebsd"))]
+    #[cfg(not(target_os = "macos"), not(target_os = "ios"), not(target_os = "freebsd"),
+      not(target_os = "dragonfly"))]
     fn set_tcp_keepalive(&mut self, _seconds: uint) -> IoResult<()> {
         Ok(())
     }
@@ -369,7 +371,7 @@ fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
     fn write(&mut self, buf: &[u8]) -> IoResult<()> {
         let fd = self.fd();
         let dolock = || self.lock_nonblocking();
-        let dowrite = |nb: bool, buf: *u8, len: uint| unsafe {
+        let dowrite = |nb: bool, buf: *const u8, len: uint| unsafe {
             let flags = if nb {c::MSG_DONTWAIT} else {0};
             libc::send(fd,
                        buf as *mut libc::c_void,
@@ -456,7 +458,7 @@ pub fn bind(addr: rtio::SocketAddr) -> IoResult<TcpListener> {
         let ret = TcpListener { inner: Inner::new(fd) };
 
         let (addr, len) = addr_to_sockaddr(addr);
-        let addrp = &addr as *_ as *libc::sockaddr;
+        let addrp = &addr as *const _ as *const libc::sockaddr;
         let len = len as libc::socklen_t;
 
         // On platforms with Berkeley-derived sockets, this allows
@@ -484,7 +486,8 @@ pub fn native_listen(self, backlog: int) -> IoResult<TcpAcceptor> {
 }
 
 impl rtio::RtioTcpListener for TcpListener {
-    fn listen(~self) -> IoResult<Box<rtio::RtioTcpAcceptor + Send>> {
+    fn listen(self: Box<TcpListener>)
+              -> IoResult<Box<rtio::RtioTcpAcceptor + Send>> {
         self.native_listen(128).map(|a| {
             box a as Box<rtio::RtioTcpAcceptor + Send>
         })
@@ -564,7 +567,7 @@ pub fn bind(addr: rtio::SocketAddr) -> IoResult<UdpSocket> {
         };
 
         let (addr, len) = addr_to_sockaddr(addr);
-        let addrp = &addr as *_ as *libc::sockaddr;
+        let addrp = &addr as *const _ as *const libc::sockaddr;
         let len = len as libc::socklen_t;
 
         match unsafe { libc::bind(fd, addrp, len) } {
@@ -630,7 +633,7 @@ fn socket_name(&mut self) -> IoResult<rtio::SocketAddr> {
 #[cfg(unix)]    type msglen_t = libc::size_t;
 
 impl rtio::RtioUdpSocket for UdpSocket {
-    fn recvfrom(&mut self, buf: &mut [u8]) -> IoResult<(uint, rtio::SocketAddr)> {
+    fn recv_from(&mut self, buf: &mut [u8]) -> IoResult<(uint, rtio::SocketAddr)> {
         let fd = self.fd();
         let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() };
         let storagep = &mut storage as *mut _ as *mut libc::sockaddr;
@@ -652,17 +655,17 @@ fn recvfrom(&mut self, buf: &mut [u8]) -> IoResult<(uint, rtio::SocketAddr)> {
         })
     }
 
-    fn sendto(&mut self, buf: &[u8], dst: rtio::SocketAddr) -> IoResult<()> {
+    fn send_to(&mut self, buf: &[u8], dst: rtio::SocketAddr) -> IoResult<()> {
         let (dst, dstlen) = addr_to_sockaddr(dst);
-        let dstp = &dst as *_ as *libc::sockaddr;
+        let dstp = &dst as *const _ as *const libc::sockaddr;
         let dstlen = dstlen as libc::socklen_t;
 
         let fd = self.fd();
         let dolock = || self.lock_nonblocking();
-        let dowrite = |nb, buf: *u8, len: uint| unsafe {
+        let dowrite = |nb, buf: *const u8, len: uint| unsafe {
             let flags = if nb {c::MSG_DONTWAIT} else {0};
             libc::sendto(fd,
-                         buf as *libc::c_void,
+                         buf as *const libc::c_void,
                          len as msglen_t,
                          flags,
                          dstp,
@@ -842,7 +845,7 @@ pub fn write<T>(fd: sock_t,
                 buf: &[u8],
                 write_everything: bool,
                 lock: || -> T,
-                write: |bool, *u8, uint| -> i64) -> IoResult<uint> {
+                write: |bool, *const u8, uint| -> i64) -> IoResult<uint> {
     let mut ret = -1;
     let mut written = 0;
     if deadline == 0 {
@@ -877,7 +880,7 @@ pub fn write<T>(fd: sock_t,
             }
 
             // Also as with read(), we use MSG_DONTWAIT to guard ourselves
-            // against unforseen circumstances.
+            // against unforeseen circumstances.
             let _guard = lock();
             let ptr = buf.slice_from(written).as_ptr();
             let len = buf.len() - written;