mirror of
https://github.com/mii443/wasmer.git
synced 2025-08-22 16:35:33 +00:00
Remove address reuse from windows target (not supported by the dependency)
This commit is contained in:
@ -115,6 +115,7 @@ impl VirtualNetworking for LocalNetworking {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
let socket = {
|
||||
let std_sock =
|
||||
Socket::new(Domain::IPV4, Type::DGRAM, None).map_err(io_err_into_net_error)?;
|
||||
@ -127,6 +128,8 @@ impl VirtualNetworking for LocalNetworking {
|
||||
std_sock.bind(&addr.into()).map_err(io_err_into_net_error)?;
|
||||
mio::net::UdpSocket::from_std(std_sock.into())
|
||||
};
|
||||
#[cfg(windows)]
|
||||
let socket = mio::net::UdpSocket::bind(addr).map_err(io_err_into_net_error)?;
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut ret = LocalUdpSocket {
|
||||
|
83
tests/wasix/udp-addr-reuse/main.c
Normal file
83
tests/wasix/udp-addr-reuse/main.c
Normal file
@ -0,0 +1,83 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
/*
|
||||
this is an exemple of address reuse using UDP sockets
|
||||
it set address reuse option to 1 and then bind to the same address
|
||||
it set port reuse option to 1 and then bind to the same port
|
||||
*/
|
||||
//#ifndef SO_REUSEPORT
|
||||
//#define SO_REUSEPORT 15
|
||||
//#endif
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int sock1, sock2;
|
||||
int reuse = 1;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
sock1 = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sock1 < 0)
|
||||
{
|
||||
perror("socket");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (setsockopt(sock1, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0)
|
||||
{
|
||||
perror("setsockopt first socket SO_REUSEADDR failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (setsockopt(sock1, SOL_SOCKET, SO_REUSEPORT, &reuse, sizeof(reuse)) < 0)
|
||||
{
|
||||
perror("setsockopt first socket SO_REUSEPORT failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(12345);
|
||||
addr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
|
||||
if (bind(sock1, (struct sockaddr *)&addr, sizeof(addr)) < 0)
|
||||
{
|
||||
perror("first socket bind failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
sock2 = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (sock2 < 0)
|
||||
{
|
||||
perror("socket");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (setsockopt(sock2, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0)
|
||||
{
|
||||
perror("setsockopt second socket SO_REUSEADDR failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (setsockopt(sock2, SOL_SOCKET, SO_REUSEPORT, &reuse, sizeof(reuse)) < 0)
|
||||
{
|
||||
perror("setsockopt second socket SO_REUSEPORT failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (bind(sock2, (struct sockaddr *)&addr, sizeof(addr)) < 0)
|
||||
{
|
||||
perror("second socket bind failed");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
close(sock1);
|
||||
close(sock2);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
3
tests/wasix/udp-addr-reuse/run.sh
Executable file
3
tests/wasix/udp-addr-reuse/run.sh
Executable file
@ -0,0 +1,3 @@
|
||||
$WASMER -q run main.wasm > output
|
||||
|
||||
printf "0" | diff -u output - 1>/dev/null
|
Reference in New Issue
Block a user