mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-05 02:20:19 +00:00
Make nginx work on Linux
This commit is contained in:
parent
552d735daf
commit
33f10e09f9
1
examples/nginx/.gitignore
vendored
1
examples/nginx/.gitignore
vendored
@ -1 +1,2 @@
|
||||
*_temp
|
||||
logs/error.log
|
@ -1 +1 @@
|
||||
96248
|
||||
21011
|
||||
|
@ -68,6 +68,7 @@ use libc::{
|
||||
F_GETFD,
|
||||
F_SETFD,
|
||||
SOL_SOCKET,
|
||||
SO_REUSEADDR,
|
||||
TIOCGWINSZ,
|
||||
};
|
||||
|
||||
@ -335,18 +336,17 @@ pub extern "C" fn ___syscall102(
|
||||
unsafe {
|
||||
ioctl(fd, FIOCLEX);
|
||||
};
|
||||
if cfg!(target_os = "darwin") {
|
||||
type T = u32;
|
||||
let payload = 1 as *const T as *const c_void;
|
||||
unsafe {
|
||||
setsockopt(
|
||||
fd,
|
||||
SOL_SOCKET,
|
||||
SO_NOSIGPIPE,
|
||||
payload,
|
||||
mem::size_of::<T>() as socklen_t,
|
||||
);
|
||||
};
|
||||
|
||||
type T = u32;
|
||||
let payload = 1 as *const T as *const c_void;
|
||||
unsafe {
|
||||
setsockopt(
|
||||
fd,
|
||||
SOL_SOCKET,
|
||||
SO_NOSIGPIPE,
|
||||
payload,
|
||||
mem::size_of::<T>() as socklen_t,
|
||||
);
|
||||
};
|
||||
|
||||
debug!(
|
||||
@ -363,14 +363,6 @@ pub extern "C" fn ___syscall102(
|
||||
let address: u32 = socket_varargs.get(instance);
|
||||
let address_len: u32 = socket_varargs.get(instance);
|
||||
let address = instance.memory_offset_addr(0, address as usize) as *mut sockaddr;
|
||||
// unsafe {
|
||||
// debug!(
|
||||
// "=> address.sin_family: {:?}, address.sin_port: {:?}, address.sin_addr.s_addr: {:?}",
|
||||
// (*address).sin_family, (*address).sin_port, (*address).sin_addr.s_addr
|
||||
// );
|
||||
// }
|
||||
// we convert address as a sockaddr (even if this is incorrect), to bypass the type
|
||||
// issue with libc bind
|
||||
|
||||
// Debug received address
|
||||
unsafe {
|
||||
@ -436,25 +428,14 @@ pub extern "C" fn ___syscall102(
|
||||
(*address_linux).sa_family = (*address).sa_family as u16;
|
||||
(*address_linux).sa_data = (*address).sa_data;
|
||||
};
|
||||
// // Debug received address
|
||||
// unsafe {
|
||||
// let proper_address = address as *const GuestSockaddrIn;
|
||||
// debug!(
|
||||
// "=> address.sin_family: {:?}, address.sin_port: {:?}, address.sin_addr.s_addr: {:?}",
|
||||
// (*proper_address).sin_family, (*proper_address).sin_port, (*proper_address).sin_addr.s_addr
|
||||
// );
|
||||
// debug!(
|
||||
// "=> address.sa_family: {:?}",
|
||||
// (*address).sa_family
|
||||
// );
|
||||
// }
|
||||
|
||||
// set_cloexec
|
||||
unsafe {
|
||||
ioctl(fd, FIOCLEX);
|
||||
};
|
||||
|
||||
debug!("fd: {}", fd);
|
||||
// nix::unistd::write(fd, "Hello, World!".as_bytes()).unwrap();
|
||||
// nix::unistd::fsync(fd).unwrap();
|
||||
|
||||
fd
|
||||
}
|
||||
6 => {
|
||||
@ -514,12 +495,13 @@ pub extern "C" fn ___syscall102(
|
||||
// name: Em passes SO_ACCEPTCONN, but Nginx complains about REUSEADDR
|
||||
// https://github.com/openbsd/src/blob/master/sys/sys/socket.h#L156
|
||||
// setsockopt (socket: c_int, level: c_int, name: c_int, value: *const c_void, option_len: socklen_t) -> c_int
|
||||
|
||||
let socket: i32 = socket_varargs.get(instance);
|
||||
// SOL_SOCKET = 0xffff in BSD
|
||||
let level: i32 = 0xffff;
|
||||
// SOL_SOCKET = 0xffff (BSD, Linux)
|
||||
let level: i32 = SOL_SOCKET;
|
||||
let _: u32 = socket_varargs.get(instance);
|
||||
// SO_ACCEPTCONN = 0x4
|
||||
let name: i32 = 0x4;
|
||||
// SO_REUSEADDR = 0x4 (BSD, Linux)
|
||||
let name: i32 = SO_REUSEADDR;
|
||||
let _: u32 = socket_varargs.get(instance);
|
||||
let value: u32 = socket_varargs.get(instance);
|
||||
let option_len: u32 = socket_varargs.get(instance);
|
||||
|
Loading…
Reference in New Issue
Block a user