mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
move back SocketConfig to aquatic_http
This commit is contained in:
parent
82378e71f6
commit
b86787ef20
5 changed files with 18 additions and 31 deletions
|
|
@ -2,12 +2,13 @@ pub mod stream;
|
|||
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use anyhow::Context;
|
||||
use native_tls::{Identity, TlsAcceptor};
|
||||
use socket2::{Socket, Domain, Type, Protocol};
|
||||
|
||||
use crate::config::{TlsConfig, SocketConfig};
|
||||
use crate::config::TlsConfig;
|
||||
|
||||
|
||||
pub fn create_tls_acceptor(
|
||||
|
|
@ -36,17 +37,17 @@ pub fn create_tls_acceptor(
|
|||
}
|
||||
|
||||
|
||||
// will be almost identical to ws version
|
||||
pub fn create_listener(
|
||||
config: &SocketConfig
|
||||
address: SocketAddr,
|
||||
ipv6_only: bool
|
||||
) -> ::anyhow::Result<::std::net::TcpListener> {
|
||||
let builder = if config.address.is_ipv4(){
|
||||
let builder = if address.is_ipv4(){
|
||||
Socket::new(Domain::ipv4(), Type::stream(), Some(Protocol::tcp()))
|
||||
} else {
|
||||
Socket::new(Domain::ipv6(), Type::stream(), Some(Protocol::tcp()))
|
||||
}.context("Couldn't create socket2::Socket")?;
|
||||
|
||||
if config.ipv6_only {
|
||||
if ipv6_only {
|
||||
builder.set_only_v6(true)
|
||||
.context("Couldn't put socket in ipv6 only mode")?
|
||||
}
|
||||
|
|
@ -55,8 +56,8 @@ pub fn create_listener(
|
|||
.context("Couldn't put socket in non-blocking mode")?;
|
||||
builder.set_reuse_port(true)
|
||||
.context("Couldn't put socket in reuse_port mode")?;
|
||||
builder.bind(&config.address.into()).with_context(||
|
||||
format!("Couldn't bind socket to address {}", config.address)
|
||||
builder.bind(&address.into()).with_context(||
|
||||
format!("Couldn't bind socket to address {}", address)
|
||||
)?;
|
||||
builder.listen(128)
|
||||
.context("Couldn't listen for connections on socket")?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue