Fix server code generation for unix
All checks were successful
Build library & run tests / build (tcp) (push) Successful in 28s
Build library & run tests / build (unix) (push) Successful in 28s

This commit is contained in:
Kodi Craft 2024-06-24 12:26:33 +02:00
parent 2934177373
commit 49cabbed95
Signed by: kodi
GPG Key ID: 69D9EED60B242822

View File

@ -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
#[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! {
#vis struct #server_connection_struct_name<H: #server_trait_name> {
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> {
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?;
Ok(Self {
handler: ::std::sync::Arc::new(tokio::sync::Mutex::new(handler)),