diff --git a/nebula-ffi/build.rs b/nebula-ffi/build.rs index bca0dad..f17d04d 100644 --- a/nebula-ffi/build.rs +++ b/nebula-ffi/build.rs @@ -33,7 +33,7 @@ fn main() { let out = out_path.join(out_file); let mut command = process::Command::new(compiler); - command.args(["build", "-buildmode", "c-archive", "-o", out.display().to_string().as_str(), "main.go"]); + command.args(["build", "-buildmode", link_type().as_str(), "-o", out.display().to_string().as_str(), "main.go"]); command.env("CGO_ENABLED", "1"); command.env("CC", c_compiler.path()); command.env("GOARCH", goarch()); @@ -50,7 +50,7 @@ fn main() { println!("Go compile success"); - println!("cargo:rustc-link-lib=static=nebula"); + print_link(); println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap()); //let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); @@ -63,7 +63,7 @@ fn main() { println!("Generating bindings"); let bindings = bindgen::Builder::default() - .header(out_path.join("libnebula.h").display().to_string()) + .header(out_path.join(LIBRARY_PREFIX.to_owned() + "nebula.h").display().to_string()) .parse_callbacks(Box::new(CargoCallbacks)) .generate() .expect("Error generating CFFI bindings"); @@ -80,7 +80,7 @@ const LIBRARY_EXTENSION: & str = ".a"; const LIBRARY_PREFIX: & str = "lib"; #[cfg(target_family = "windows")] -const LIBRARY_EXTENSION: &str = ".lib"; +const LIBRARY_EXTENSION: &str = ".dll"; #[cfg(target_family = "windows")] const LIBRARY_PREFIX: &str = ""; @@ -109,4 +109,21 @@ fn goos() -> String { "netbsd" => "netbsd", os => panic!("unsupported operating system {os}") }.to_string() -} \ No newline at end of file +} + +#[cfg(target_family = "unix")] +fn print_link() { + println!("cargo:rustc-link-lib=static=nebula"); +} +#[cfg(target_family = "unix")] +fn link_type() -> String { + "c-archive".to_string() +} +#[cfg(target_family = "windows")] +fn print_link() { + println!("cargo:rustc-link-lib=dylib=nebula"); +} +#[cfg(target_family = "windows")] +fn link_type() -> String { + "c-shared".to_string() +} diff --git a/tfclient/src/socketworker.rs b/tfclient/src/socketworker.rs index 4927b50..9200439 100644 --- a/tfclient/src/socketworker.rs +++ b/tfclient/src/socketworker.rs @@ -124,6 +124,8 @@ fn handle_client( ) -> Result<(), io::Error> { info!("Handling connection from {}", stream.peer_addr()?); + stream.set_nonblocking(false)?; + let mut client = Client { state: ClientState::WaitHello, reader: BufReader::new(&stream),