4 Commits

Author SHA1 Message Date
de5d29b3e6 update bindings for more const correctness 2024-07-17 09:49:22 -07:00
e81321d8bf update instructions for running example 2024-07-17 09:09:32 -07:00
0b075e5a97 added csp_socket_close 2024-06-02 00:28:02 +02:00
d49d0affe2 fix link 2024-06-02 00:15:43 +02:00
7 changed files with 42 additions and 21 deletions

28
Cargo.lock generated

@ -4,15 +4,15 @@ version = 3
[[package]]
name = "bitflags"
version = "2.5.0"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "cc"
version = "1.0.98"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f"
checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052"
[[package]]
name = "equivalent"
@ -77,9 +77,9 @@ dependencies = [
[[package]]
name = "memchr"
version = "2.7.2"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "num_enum"
@ -113,9 +113,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.84"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
@ -131,9 +131,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.66"
version = "2.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
dependencies = [
"proc-macro2",
"quote",
@ -142,18 +142,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.61"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709"
checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.61"
version = "1.0.62"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533"
checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c"
dependencies = [
"proc-macro2",
"quote",

@ -3,6 +3,7 @@ members = [
"libcsp-cargo-build",
"examples"
]
default-members = ["examples"]
resolver = "2"
[package]

@ -48,7 +48,7 @@ in Rust. You can run the example using the following steps:
1. Clone/Copy `libcsp` into the `lib` folder, for example by using the provided `lib/clone-csp.sh`
script or adding `libcsp` as a git submodule.
2. You can now use `cargo run -p libcsp-rust-examples` to run the server/client example.
2. You can now use `cargo run` to run the server/client example.
## Compile-time configuration of the `libcsp-sys` library
@ -59,8 +59,8 @@ The user has to provide the path to a directory containing this `autoconfig.rs`
`CSP_CONFIG_DIR` environmental variable.
You can automatically generate this file when using `libcsp-cargo-build` by using the
[`generate_autoconf_rust_file`](here be link soon) method of the Builder object as done in the
example build script.
[`generate_autoconf_rust_file`](https://docs.rs/libcsp-cargo-build/latest/libcsp_cargo_build/fn.generate_autoconf_rust_file.html)
method of the Builder object as done in the example build script.
In this workspace, the `CSP_CONFIG_DIR` variable is hardcoded using the following `.cargo/config.toml`
configuration:

@ -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);

@ -1,3 +1,4 @@
#!/bin/bash
git clone https://github.com/us-irs/libcsp.git
cd libcsp
git checkout const-correctness

@ -483,7 +483,7 @@ extern "C" {
pub fn csp_buffer_get(unused: usize) -> *mut csp_packet_t;
#[doc = " Free buffer (from task context).\n\n @param[in] buffer buffer to free. NULL is handled gracefully."]
pub fn csp_buffer_free(buffer: *mut ::core::ffi::c_void);
pub fn csp_buffer_free(buffer: *const ::core::ffi::c_void);
#[doc = " Print connection table to stdout."]
pub fn csp_conn_print_table();

@ -398,6 +398,21 @@ pub fn csp_accept(socket: &mut CspSocket, timeout: Duration) -> Option<CspConnRe
}))
}
/// Rust wrapper for [ffi::csp_socket_close] which returns the result code directly.
pub fn csp_socket_close_raw(sock: &mut CspSocket) -> 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<CspPacketRef> {
let timeout_millis = timeout.as_millis();
@ -589,7 +604,7 @@ pub fn csp_conn_print_table() {
pub fn csp_buffer_free(packet: impl Into<CspPacketRef>) {
// SAFETY: FFI call and the Rust type system actually ensure the correct type
// is free'd here, while also taking the packet by value.
unsafe { ffi::csp_buffer_free(packet.into().0 as *mut libc::c_void) }
unsafe { ffi::csp_buffer_free(packet.into().0 as *const libc::c_void) }
}
/// Rust wrapper for [ffi::csp_transaction_persistent].