diff --git a/clib/bindings.rs b/clib/bindings.rs index 7d0ff16..468b405 100644 --- a/clib/bindings.rs +++ b/clib/bindings.rs @@ -343,9 +343,9 @@ pub const CSP_DBG_ETH_ERR_RX_OUT: u32 = 3; pub const CSP_DBG_ETH_ERR_SHORT_BEGIN: u32 = 4; pub const CSP_DBG_ETH_ERR_INCOMPLETE: u32 = 5; pub const CSP_DBG_ETH_ERR_UNKNOWN: u32 = 6; +pub const __bool_true_false_are_defined: u32 = 1; pub const true_: u32 = 1; pub const false_: u32 = 0; -pub const __bool_true_false_are_defined: u32 = 1; pub const CSP_QUEUE_OK: u32 = 0; pub const CSP_QUEUE_ERROR: i32 = -1; pub const CSP_ANY: u32 = 255; @@ -2411,7 +2411,11 @@ extern "C" { ) -> ::core::ffi::c_int; } extern "C" { - pub fn bcopy(__src: *const ::core::ffi::c_void, __dest: *mut ::core::ffi::c_void, __n: usize); + pub fn bcopy( + __src: *const ::core::ffi::c_void, + __dest: *mut ::core::ffi::c_void, + __n: ::core::ffi::c_ulong, + ); } extern "C" { pub fn bzero(__s: *mut ::core::ffi::c_void, __n: ::core::ffi::c_ulong); diff --git a/clib/clone-csp.sh b/clib/clone-csp.sh index e0b42bb..8d3ab52 100755 --- a/clib/clone-csp.sh +++ b/clib/clone-csp.sh @@ -1,3 +1,4 @@ #!/bin/bash git clone https://github.com/us-irs/libcsp.git +cd libcsp git checkout const-correctness diff --git a/src/lib.rs b/src/lib.rs index 1399aa0..44e9b30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -398,6 +398,21 @@ pub fn csp_accept(socket: &mut CspSocket, timeout: Duration) -> Option i32 { + unsafe { ffi::csp_socket_close(&mut sock.0) } +} + +/// Rust wrapper for [ffi::csp_socket_close]. +/// +/// This function will panic if the error code returned from [ffi::csp_socket_close] is not one of +/// [CspError]. [csp_socket_close_raw] can be used if this is not acceptable. +pub fn csp_socket_close(sock: &mut CspSocket) -> Result<(), CspError> { + let result = unsafe { ffi::csp_socket_close(&mut sock.0) }; + Err(CspError::try_from(result) + .unwrap_or_else(|_| panic!("unexpected error value {} from csp_socket_close", result))) +} + /// Rust wrapper for [ffi::csp_read]. pub fn csp_read(conn: &mut CspConnRef, timeout: Duration) -> Option { let timeout_millis = timeout.as_millis();