瀏覽代碼

Add shutdown, listen, and getpagesize

Jeremy Soller 6 年之前
父節點
當前提交
7aa789575a

+ 8 - 8
src/header/sys_socket/mod.rs

@@ -111,10 +111,10 @@ pub unsafe extern "C" fn getsockopt(
     )
 }
 
-// #[no_mangle]
-// pub unsafe extern "C" fn listen(socket: c_int, backlog: c_int) -> c_int {
-//     Sys::listen(socket, backlog)
-// }
+#[no_mangle]
+pub unsafe extern "C" fn listen(socket: c_int, backlog: c_int) -> c_int {
+    Sys::listen(socket, backlog)
+}
 
 #[no_mangle]
 pub unsafe extern "C" fn recv(
@@ -204,10 +204,10 @@ pub unsafe extern "C" fn setsockopt(
     )
 }
 
-// #[no_mangle]
-// pub unsafe extern "C" fn shutdown(socket: c_int, how: c_int) -> c_int {
-//     Sys::shutdown(socket, how)
-// }
+#[no_mangle]
+pub unsafe extern "C" fn shutdown(socket: c_int, how: c_int) -> c_int {
+    Sys::shutdown(socket, how)
+}
 
 #[no_mangle]
 pub unsafe extern "C" fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {

+ 2 - 2
src/header/unistd/mod.rs

@@ -321,9 +321,9 @@ pub extern "C" fn getlogin_r(name: *mut c_char, namesize: size_t) -> c_int {
     unimplemented!();
 }
 
-// #[no_mangle]
+#[no_mangle]
 pub extern "C" fn getpagesize() -> c_int {
-    unimplemented!();
+    Sys::getpagesize()
 }
 
 // #[no_mangle]

+ 4 - 0
src/platform/linux/mod.rs

@@ -239,6 +239,10 @@ impl Pal for Sys {
         e(unsafe { syscall!(GETGID) }) as gid_t
     }
 
+    fn getpagesize() -> c_int {
+        e(unsafe { syscall!(GETPAGESIZE) }) as c_int
+    }
+
     fn getpgid(pid: pid_t) -> pid_t {
         e(unsafe { syscall!(GETPGID, pid) }) as pid_t
     }

+ 8 - 8
src/platform/linux/socket.rs

@@ -4,14 +4,6 @@ use super::{e, Sys};
 use header::sys_socket::{sockaddr, socklen_t};
 
 impl Sys {
-    fn listen(socket: c_int, backlog: c_int) -> c_int {
-        e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int
-    }
-
-    fn shutdown(socket: c_int, how: c_int) -> c_int {
-        e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int
-    }
-
     fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *mut c_int) -> c_int {
         e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int
     }
@@ -65,6 +57,10 @@ impl PalSocket for Sys {
         }) as c_int
     }
 
+    fn listen(socket: c_int, backlog: c_int) -> c_int {
+        e(unsafe { syscall!(LISTEN, socket, backlog) }) as c_int
+    }
+
     unsafe fn recvfrom(
         socket: c_int,
         buf: *mut c_void,
@@ -116,6 +112,10 @@ impl PalSocket for Sys {
         }) as c_int
     }
 
+    fn shutdown(socket: c_int, how: c_int) -> c_int {
+        e(unsafe { syscall!(SHUTDOWN, socket, how) }) as c_int
+    }
+
     unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int {
         e(syscall!(SOCKET, domain, kind, protocol)) as c_int
     }

+ 2 - 0
src/platform/pal/mod.rs

@@ -75,6 +75,8 @@ pub trait Pal {
 
     fn getgid() -> gid_t;
 
+    fn getpagesize() -> c_int;
+
     fn getpgid(pid: pid_t) -> pid_t;
 
     fn getpid() -> pid_t;

+ 4 - 0
src/platform/pal/socket.rs

@@ -29,6 +29,8 @@ pub trait PalSocket: Pal {
         option_len: *mut socklen_t,
     ) -> c_int;
 
+    fn listen(socket: c_int, backlog: c_int) -> c_int;
+
     unsafe fn recvfrom(
         socket: c_int,
         buf: *mut c_void,
@@ -55,5 +57,7 @@ pub trait PalSocket: Pal {
         option_len: socklen_t,
     ) -> c_int;
 
+    fn shutdown(socket: c_int, how: c_int) -> c_int;
+
     unsafe fn socket(domain: c_int, kind: c_int, protocol: c_int) -> c_int;
 }

+ 4 - 0
src/platform/redox/mod.rs

@@ -545,6 +545,10 @@ impl Pal for Sys {
         e(syscall::getgid()) as gid_t
     }
 
+    fn getpagesize() -> c_int {
+        4096
+    }
+
     fn getpgid(pid: pid_t) -> pid_t {
         e(syscall::getpgid(pid as usize)) as pid_t
     }

+ 9 - 0
src/platform/redox/socket.rs

@@ -144,6 +144,11 @@ impl PalSocket for Sys {
         e(Err(syscall::Error::new(syscall::ENOSYS))) as c_int
     }
 
+    fn listen(socket: c_int, backlog: c_int) -> c_int {
+        // Redox has no need to listen
+        0
+    }
+
     unsafe fn recvfrom(
         socket: c_int,
         buf: *mut c_void,
@@ -206,6 +211,10 @@ impl PalSocket for Sys {
         e(Err(syscall::Error::new(syscall::ENOSYS))) as c_int
     }
 
+    fn shutdown(socket: c_int, how: c_int) -> c_int {
+        e(Err(syscall::Error::new(syscall::ENOSYS))) as c_int
+    }
+
     unsafe fn socket(domain: c_int, mut kind: c_int, protocol: c_int) -> c_int {
         if domain != AF_INET {
             errno = syscall::EAFNOSUPPORT;