mirror of
https://github.com/yuzu-emu/liftinstall.git
synced 2024-11-25 19:55:46 +01:00
Bind IPv4 and IPv6 on the same port
This commit is contained in:
parent
55239ec4aa
commit
88ac38defb
16
src/main.rs
16
src/main.rs
@ -49,6 +49,7 @@ use rest::WebServer;
|
||||
|
||||
use std::net::ToSocketAddrs;
|
||||
|
||||
use std::net::TcpListener;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
|
||||
@ -78,6 +79,17 @@ fn main() {
|
||||
InstallerFramework::new(config)
|
||||
};
|
||||
|
||||
// Firstly, allocate us an epidermal port
|
||||
let target_port = {
|
||||
let listener =
|
||||
TcpListener::bind("127.0.0.1:0").expect("At least one local address should be free");
|
||||
listener
|
||||
.local_addr()
|
||||
.expect("Should be able to pull address from listener")
|
||||
.port()
|
||||
};
|
||||
|
||||
// Now, iterate over all ports
|
||||
let addresses = "localhost:0"
|
||||
.to_socket_addrs()
|
||||
.expect("No localhost address found");
|
||||
@ -88,7 +100,9 @@ fn main() {
|
||||
let framework = Arc::new(RwLock::new(framework));
|
||||
|
||||
// Startup HTTP server for handling the web view
|
||||
for address in addresses {
|
||||
for mut address in addresses {
|
||||
address.set_port(target_port);
|
||||
|
||||
let server = WebServer::with_addr(framework.clone(), address).unwrap();
|
||||
|
||||
let addr = server.get_addr();
|
||||
|
@ -17,7 +17,7 @@ use hyper::{self, Error as HyperError, Get, Post, StatusCode};
|
||||
use url::form_urlencoded;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::net::{SocketAddr};
|
||||
use std::process::exit;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::sync::Arc;
|
||||
@ -48,7 +48,10 @@ impl WebServer {
|
||||
}
|
||||
|
||||
/// Creates a new web server with the specified address.
|
||||
pub fn with_addr(framework: Arc<RwLock<InstallerFramework>>, addr: SocketAddr) -> Result<Self, HyperError> {
|
||||
pub fn with_addr(
|
||||
framework: Arc<RwLock<InstallerFramework>>,
|
||||
addr: SocketAddr,
|
||||
) -> Result<Self, HyperError> {
|
||||
let (sender, receiver) = channel();
|
||||
|
||||
let handle = thread::spawn(move || {
|
||||
|
Loading…
Reference in New Issue
Block a user