diff --git a/Cargo.toml b/Cargo.toml index 01521810e..130903273 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,16 @@ [workspace] members = [ - "deps/ccommon/rust/ccommon-sys", - "deps/ccommon/rust/ccommon-rs", + "deps/ccommon/rust/ccommon-array", + "deps/ccommon/rust/ccommon-backend", + "deps/ccommon/rust/ccommon-buffer", + "deps/ccommon/rust/ccommon-channel", "deps/ccommon/rust/ccommon-derive", + "deps/ccommon/rust/ccommon-log", + "deps/ccommon/rust/ccommon-rs", + "deps/ccommon/rust/ccommon-stats", + "deps/ccommon/rust/ccommon-stream", + "deps/ccommon/rust/ccommon-sys", "src/rust-util/httpencode", "src/rust-util/pelikan", "src/rust-util/pelikan-sys", diff --git a/deps/ccommon/ci/install-check.sh b/deps/ccommon/ci/install-check.sh index 070c4ebea..edddb140e 100755 --- a/deps/ccommon/ci/install-check.sh +++ b/deps/ccommon/ci/install-check.sh @@ -29,8 +29,6 @@ CHECK_LOG="build-check.log" echo "building and installing check" >&2 -echo "building and installing check" >&2 - ( cd "$TEMP" && wget "https://github.com/libcheck/check/releases/download/${CHECK_VERSION}/${CHECK_TARBALL}" && diff --git a/deps/ccommon/include/cc_array.h b/deps/ccommon/include/cc_array.h index b4aa1feb8..0ffd73c94 100644 --- a/deps/ccommon/include/cc_array.h +++ b/deps/ccommon/include/cc_array.h @@ -43,37 +43,43 @@ typedef int (*array_compare_fn)(const void *, const void *); typedef rstatus_i (*array_each_fn)(void *, void *); struct array { - uint32_t nalloc; /* # allocated element */ size_t size; /* element size */ + uint32_t nalloc; /* # allocated element */ uint32_t nelem; /* # element */ uint8_t *data; /* elements */ }; -static inline uint32_t -array_nalloc(const struct array *arr) -{ - return arr->nalloc; -} - static inline size_t array_size(const struct array *arr) { return arr->size; } +static inline uint32_t +array_nalloc(const struct array *arr) +{ + return arr->nalloc; +} + static inline uint32_t array_nelem(const struct array *arr) { return arr->nelem; } +static inline size_t +array_nfree(const struct array *arr) +{ + return arr->nalloc - arr->nelem; +} + /* resets all fields in array to zero w/o freeing up any memory */ static inline void array_reset(struct array *arr) { - arr->nalloc = 0; arr->size = 0; + arr->nalloc = 0; arr->nelem = 0; arr->data = NULL; } @@ -82,8 +88,8 @@ array_reset(struct array *arr) static inline void array_data_assign(struct array *arr, uint32_t nalloc, size_t size, void *data) { - arr->nalloc = nalloc; arr->size = size; + arr->nalloc = nalloc; arr->nelem = 0; arr->data = data; } diff --git a/deps/ccommon/rust/CMakeLists.txt b/deps/ccommon/rust/CMakeLists.txt index 04d8c67a5..37f472807 100644 --- a/deps/ccommon/rust/CMakeLists.txt +++ b/deps/ccommon/rust/CMakeLists.txt @@ -8,9 +8,15 @@ execute_process( ERROR_VARIABLE CARGO_CONFIG_OUT) if(HAVE_RUST) - add_subdirectory(ccommon-backend) - add_subdirectory(ccommon-derive) + add_subdirectory(ccommon-array) + add_subdirectory(ccommon-backend) + add_subdirectory(ccommon-buffer) + add_subdirectory(ccommon-channel) + add_subdirectory(ccommon-derive) + add_subdirectory(ccommon-log) add_subdirectory(ccommon-rs) + add_subdirectory(ccommon-stats) + add_subdirectory(ccommon-stream) add_subdirectory(ccommon-sys) endif() diff --git a/deps/ccommon/rust/ccommon-array/CMakeLists.txt b/deps/ccommon/rust/ccommon-array/CMakeLists.txt new file mode 100644 index 000000000..5bdbec3ee --- /dev/null +++ b/deps/ccommon/rust/ccommon-array/CMakeLists.txt @@ -0,0 +1,2 @@ + +cargo_build(NAME ccommon-array) diff --git a/deps/ccommon/rust/ccommon-array/Cargo.toml b/deps/ccommon/rust/ccommon-array/Cargo.toml new file mode 100644 index 000000000..fe3f66754 --- /dev/null +++ b/deps/ccommon/rust/ccommon-array/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ccommon-array" +version = "0.1.0" +authors = ["Brian Martin "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.110", features = ["derive"], optional = true } + +[features] +default = [ "serde/derive" ] diff --git a/deps/ccommon/rust/ccommon-array/src/lib.rs b/deps/ccommon/rust/ccommon-array/src/lib.rs new file mode 100644 index 000000000..772ab6675 --- /dev/null +++ b/deps/ccommon/rust/ccommon-array/src/lib.rs @@ -0,0 +1,38 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +// constants to define default values +const NELEM_DELTA: usize = 16; + +// helper functions +fn nelem_delta() -> usize { + NELEM_DELTA +} + +// definitions +#[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct ArrayConfig { + #[cfg_attr(feature = "serde", serde(default = "nelem_delta"))] + nelem_delta: usize, +} + +// implementation +impl ArrayConfig { + pub fn nelem_delta(&self) -> usize { + self.nelem_delta + } +} + +// trait implementations +impl Default for ArrayConfig { + fn default() -> Self { + Self { + nelem_delta: nelem_delta(), + } + } +} diff --git a/deps/ccommon/rust/ccommon-buffer/CMakeLists.txt b/deps/ccommon/rust/ccommon-buffer/CMakeLists.txt new file mode 100644 index 000000000..ccc692e49 --- /dev/null +++ b/deps/ccommon/rust/ccommon-buffer/CMakeLists.txt @@ -0,0 +1,2 @@ + +cargo_build(NAME ccommon-buffer) diff --git a/deps/ccommon/rust/ccommon-buffer/Cargo.toml b/deps/ccommon/rust/ccommon-buffer/Cargo.toml new file mode 100644 index 000000000..d85403041 --- /dev/null +++ b/deps/ccommon/rust/ccommon-buffer/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ccommon-buffer" +version = "0.1.0" +authors = ["Brian Martin "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.110", features = ["derive"], optional = true } + +[features] +default = [ "serde/derive" ] + diff --git a/deps/ccommon/rust/ccommon-buffer/src/buf/mod.rs b/deps/ccommon/rust/ccommon-buffer/src/buf/mod.rs new file mode 100644 index 000000000..fd8da24d5 --- /dev/null +++ b/deps/ccommon/rust/ccommon-buffer/src/buf/mod.rs @@ -0,0 +1,50 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +// constants to define default values +const BUF_DEFAULT_SIZE: usize = 16 * 1024; +const BUF_POOLSIZE: usize = 0; + +// helper functions +fn size() -> usize { + BUF_DEFAULT_SIZE +} + +fn poolsize() -> usize { + BUF_POOLSIZE +} + +// struct definitions +#[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct BufConfig { + #[cfg_attr(feature = "serde", serde(default = "size"))] + size: usize, + #[cfg_attr(feature = "serde", serde(default = "poolsize"))] + poolsize: usize, +} + +// implementation +impl BufConfig { + pub fn size(&self) -> usize { + self.size + } + + pub fn poolsize(&self) -> usize { + self.poolsize + } +} + +// trait implementations +impl Default for BufConfig { + fn default() -> Self { + Self { + size: size(), + poolsize: poolsize(), + } + } +} diff --git a/deps/ccommon/rust/ccommon-buffer/src/dbuf/mod.rs b/deps/ccommon/rust/ccommon-buffer/src/dbuf/mod.rs new file mode 100644 index 000000000..db2724e74 --- /dev/null +++ b/deps/ccommon/rust/ccommon-buffer/src/dbuf/mod.rs @@ -0,0 +1,38 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +// constants to define default values +const DBUF_DEFAULT_MAX: usize = 8; + +// helper functions +fn max_power() -> usize { + DBUF_DEFAULT_MAX +} + +// struct definitions +#[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct DbufConfig { + #[cfg_attr(feature = "serde", serde(default = "max_power"))] + max_power: usize, +} + +// implementation +impl DbufConfig { + pub fn max_power(&self) -> usize { + self.max_power + } +} + +// trait implementations +impl Default for DbufConfig { + fn default() -> Self { + Self { + max_power: max_power(), + } + } +} diff --git a/deps/ccommon/rust/ccommon-buffer/src/lib.rs b/deps/ccommon/rust/ccommon-buffer/src/lib.rs new file mode 100644 index 000000000..00489b149 --- /dev/null +++ b/deps/ccommon/rust/ccommon-buffer/src/lib.rs @@ -0,0 +1,9 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +mod buf; +mod dbuf; + +pub use buf::*; +pub use dbuf::*; diff --git a/deps/ccommon/rust/ccommon-channel/CMakeLists.txt b/deps/ccommon/rust/ccommon-channel/CMakeLists.txt new file mode 100644 index 000000000..dc47008ce --- /dev/null +++ b/deps/ccommon/rust/ccommon-channel/CMakeLists.txt @@ -0,0 +1,2 @@ + +cargo_build(NAME ccommon-channel) diff --git a/deps/ccommon/rust/ccommon-channel/Cargo.toml b/deps/ccommon/rust/ccommon-channel/Cargo.toml new file mode 100644 index 000000000..6bceed653 --- /dev/null +++ b/deps/ccommon/rust/ccommon-channel/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "ccommon-channel" +version = "0.1.0" +authors = ["Brian Martin "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.110", features = ["derive"], optional = true } + +[features] +default = [ "serde/derive" ] diff --git a/deps/ccommon/rust/ccommon-channel/src/lib.rs b/deps/ccommon/rust/ccommon-channel/src/lib.rs new file mode 100644 index 000000000..d57a6bc9c --- /dev/null +++ b/deps/ccommon/rust/ccommon-channel/src/lib.rs @@ -0,0 +1,9 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +mod pipe; +mod tcp; + +pub use pipe::*; +pub use tcp::*; diff --git a/deps/ccommon/rust/ccommon-channel/src/pipe/mod.rs b/deps/ccommon/rust/ccommon-channel/src/pipe/mod.rs new file mode 100644 index 000000000..946f90f38 --- /dev/null +++ b/deps/ccommon/rust/ccommon-channel/src/pipe/mod.rs @@ -0,0 +1,38 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +// constants to define default values +const PIPE_POOLSIZE: usize = 0; + +// helper functions +fn poolsize() -> usize { + PIPE_POOLSIZE +} + +// definitions +#[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct PipeConfig { + #[cfg_attr(feature = "serde", serde(default = "poolsize"))] + poolsize: usize, +} + +// implementation +impl PipeConfig { + pub fn poolsize(&self) -> usize { + self.poolsize + } +} + +// trait implementations +impl Default for PipeConfig { + fn default() -> Self { + Self { + poolsize: poolsize(), + } + } +} diff --git a/deps/ccommon/rust/ccommon-channel/src/tcp/mod.rs b/deps/ccommon/rust/ccommon-channel/src/tcp/mod.rs new file mode 100644 index 000000000..125910583 --- /dev/null +++ b/deps/ccommon/rust/ccommon-channel/src/tcp/mod.rs @@ -0,0 +1,50 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +// constants to define default values +const TCP_BACKLOG: usize = 128; +const TCP_POOLSIZE: usize = 0; + +// helper functions +fn backlog() -> usize { + TCP_BACKLOG +} + +fn poolsize() -> usize { + TCP_POOLSIZE +} + +// definitions +#[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct TcpConfig { + #[cfg_attr(feature = "serde", serde(default = "backlog"))] + backlog: usize, + #[cfg_attr(feature = "serde", serde(default = "poolsize"))] + poolsize: usize, +} + +// implementation +impl TcpConfig { + pub fn backlog(&self) -> usize { + self.backlog + } + + pub fn poolsize(&self) -> usize { + self.poolsize + } +} + +// trait implementations +impl Default for TcpConfig { + fn default() -> Self { + Self { + backlog: backlog(), + poolsize: poolsize(), + } + } +} diff --git a/deps/ccommon/rust/ccommon-log/CMakeLists.txt b/deps/ccommon/rust/ccommon-log/CMakeLists.txt new file mode 100644 index 000000000..b1495ec15 --- /dev/null +++ b/deps/ccommon/rust/ccommon-log/CMakeLists.txt @@ -0,0 +1,2 @@ + +cargo_build(NAME ccommon-log) diff --git a/deps/ccommon/rust/ccommon-log/Cargo.toml b/deps/ccommon/rust/ccommon-log/Cargo.toml new file mode 100644 index 000000000..2aa19dcad --- /dev/null +++ b/deps/ccommon/rust/ccommon-log/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ccommon-log" +version = "0.1.0" +authors = ["Brian Martin "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.110", features = ["derive"], optional = true } + +[features] +default = [ "serde/derive" ] + diff --git a/deps/ccommon/rust/ccommon-log/src/lib.rs b/deps/ccommon/rust/ccommon-log/src/lib.rs new file mode 100644 index 000000000..d2bf804ba --- /dev/null +++ b/deps/ccommon/rust/ccommon-log/src/lib.rs @@ -0,0 +1,62 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +// constants to define default values +const DEBUG_LOG_LEVEL: usize = 4; +const DEBUG_LOG_FILE: Option = None; +const DEBUG_LOG_NBUF: usize = 0; + +// helper functions +fn log_level() -> usize { + DEBUG_LOG_LEVEL +} + +fn log_file() -> Option { + DEBUG_LOG_FILE +} + +fn log_nbuf() -> usize { + DEBUG_LOG_NBUF +} + +// struct definitions +#[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct DebugConfig { + #[cfg_attr(feature = "serde", serde(default = "log_level"))] + log_level: usize, + #[cfg_attr(feature = "serde", serde(default = "log_file"))] + log_file: Option, + #[cfg_attr(feature = "serde", serde(default = "log_nbuf"))] + log_nbuf: usize, +} + +// implementation +impl DebugConfig { + pub fn log_level(&self) -> usize { + self.log_level + } + + pub fn log_file(&self) -> Option { + self.log_file.clone() + } + + pub fn log_nbuf(&self) -> usize { + self.log_nbuf + } +} + +// trait implementations +impl Default for DebugConfig { + fn default() -> Self { + Self { + log_level: log_level(), + log_file: log_file(), + log_nbuf: log_nbuf(), + } + } +} diff --git a/deps/ccommon/rust/ccommon-stats/CMakeLists.txt b/deps/ccommon/rust/ccommon-stats/CMakeLists.txt new file mode 100644 index 000000000..f35d0e554 --- /dev/null +++ b/deps/ccommon/rust/ccommon-stats/CMakeLists.txt @@ -0,0 +1,2 @@ + +cargo_build(NAME ccommon-stats) diff --git a/deps/ccommon/rust/ccommon-stats/Cargo.toml b/deps/ccommon/rust/ccommon-stats/Cargo.toml new file mode 100644 index 000000000..1956778b4 --- /dev/null +++ b/deps/ccommon/rust/ccommon-stats/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ccommon-stats" +version = "0.1.0" +authors = ["Brian Martin "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.110", features = ["derive"], optional = true } + +[features] +default = [ "serde/derive" ] + diff --git a/deps/ccommon/rust/ccommon-stats/src/lib.rs b/deps/ccommon/rust/ccommon-stats/src/lib.rs new file mode 100644 index 000000000..182f3a4ad --- /dev/null +++ b/deps/ccommon/rust/ccommon-stats/src/lib.rs @@ -0,0 +1,50 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +// constants to define default values +const STATS_LOG_FILE: Option = None; +const STATS_LOG_NBUF: usize = 0; + +// helper functions +fn file() -> Option { + STATS_LOG_FILE +} + +fn nbuf() -> usize { + STATS_LOG_NBUF +} + +// definitions +#[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct StatsLogConfig { + #[cfg_attr(feature = "serde", serde(default = "file"))] + file: Option, + #[cfg_attr(feature = "serde", serde(default = "nbuf"))] + nbuf: usize, +} + +// implementation +impl StatsLogConfig { + pub fn log_file(&self) -> Option { + self.file.clone() + } + + pub fn log_nbuf(&self) -> usize { + self.nbuf + } +} + +// trait implementations +impl Default for StatsLogConfig { + fn default() -> Self { + Self { + file: file(), + nbuf: nbuf(), + } + } +} diff --git a/deps/ccommon/rust/ccommon-stream/CMakeLists.txt b/deps/ccommon/rust/ccommon-stream/CMakeLists.txt new file mode 100644 index 000000000..ec65970df --- /dev/null +++ b/deps/ccommon/rust/ccommon-stream/CMakeLists.txt @@ -0,0 +1,2 @@ + +cargo_build(NAME ccommon-stream) diff --git a/deps/ccommon/rust/ccommon-stream/Cargo.toml b/deps/ccommon/rust/ccommon-stream/Cargo.toml new file mode 100644 index 000000000..fd2067678 --- /dev/null +++ b/deps/ccommon/rust/ccommon-stream/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ccommon-stream" +version = "0.1.0" +authors = ["Brian Martin "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +serde = { version = "1.0.110", features = ["derive"], optional = true } + +[features] +default = [ "serde/derive" ] + diff --git a/deps/ccommon/rust/ccommon-stream/src/lib.rs b/deps/ccommon/rust/ccommon-stream/src/lib.rs new file mode 100644 index 000000000..ad1451406 --- /dev/null +++ b/deps/ccommon/rust/ccommon-stream/src/lib.rs @@ -0,0 +1,38 @@ +// Copyright 2020 Twitter, Inc. +// Licensed under the Apache License, Version 2.0 +// http://www.apache.org/licenses/LICENSE-2.0 + +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + +// constants to define default values +const BUFSOCK_POOLSIZE: usize = 0; + +// helper functions +fn buf_sock_poolsize() -> usize { + BUFSOCK_POOLSIZE +} + +// definitions +#[derive(Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct SockioConfig { + #[cfg_attr(feature = "serde", serde(default = "buf_sock_poolsize"))] + buf_sock_poolsize: usize, +} + +// implementation +impl SockioConfig { + pub fn buf_sock_poolsize(&self) -> usize { + self.buf_sock_poolsize + } +} + +// trait implementations +impl Default for SockioConfig { + fn default() -> Self { + Self { + buf_sock_poolsize: buf_sock_poolsize(), + } + } +}