Fix server code generation for unix
This commit is contained in:
parent
2934177373
commit
49cabbed95
10
src/lib.rs
10
src/lib.rs
@ -211,6 +211,14 @@ fn derive_protocol(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Create a struct to implement the communication between the server and the client
|
// Create a struct to implement the communication between the server and the client
|
||||||
|
#[cfg(feature = "tcp")]
|
||||||
|
let listener_statement = quote! {
|
||||||
|
let listener = #listener_type::bind(addr).await?;
|
||||||
|
};
|
||||||
|
#[cfg(feature = "unix")]
|
||||||
|
let listener_statement = quote! {
|
||||||
|
let listener = #listener_type::bind(addr.as_ref())?;
|
||||||
|
};
|
||||||
let sc_struct = quote! {
|
let sc_struct = quote! {
|
||||||
#vis struct #server_connection_struct_name<H: #server_trait_name> {
|
#vis struct #server_connection_struct_name<H: #server_trait_name> {
|
||||||
handler: ::std::sync::Arc<tokio::sync::Mutex<H>>,
|
handler: ::std::sync::Arc<tokio::sync::Mutex<H>>,
|
||||||
@ -218,7 +226,7 @@ fn derive_protocol(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream
|
|||||||
}
|
}
|
||||||
impl<H: #server_trait_name> #server_connection_struct_name<H> {
|
impl<H: #server_trait_name> #server_connection_struct_name<H> {
|
||||||
pub async fn bind<S: #stream_addr_trait>(handler: H, addr: S) -> Result<Self, std::io::Error> {
|
pub async fn bind<S: #stream_addr_trait>(handler: H, addr: S) -> Result<Self, std::io::Error> {
|
||||||
let listener = #listener_type::bind(addr).await?;
|
#listener_statement
|
||||||
let (stream, _) = listener.accept().await?;
|
let (stream, _) = listener.accept().await?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
handler: ::std::sync::Arc::new(tokio::sync::Mutex::new(handler)),
|
handler: ::std::sync::Arc::new(tokio::sync::Mutex::new(handler)),
|
||||||
|
Loading…
Reference in New Issue
Block a user