Skip to content

Commit

Permalink
Supports reuseaddr, reuseport, and configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Aug 1, 2023
1 parent db895e5 commit 1297c30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 10 additions & 0 deletions rmqtt-plugins/rmqtt-cluster-raft/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ impl PluginConfig {

#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct RaftConfig {
#[serde(default = "RaftConfig::grpc_reuseaddr_default")]
pub grpc_reuseaddr: bool,
#[serde(default = "RaftConfig::grpc_reuseport_default")]
pub grpc_reuseport: bool,
#[serde(default, deserialize_with = "deserialize_duration_option")]
pub grpc_timeout: Option<Duration>,
Expand Down Expand Up @@ -239,6 +241,14 @@ impl RaftConfig {
ReadOnlyOption::Safe
}

fn grpc_reuseaddr_default() -> bool {
true
}

fn grpc_reuseport_default() -> bool {
false
}

pub fn deserialize_read_only_option<'de, D>(deserializer: D) -> Result<ReadOnlyOption, D::Error>
where
D: Deserializer<'de>,
Expand Down
14 changes: 10 additions & 4 deletions rmqtt/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ pub struct Rpc {
#[serde(default = "Rpc::server_addr_default", deserialize_with = "deserialize_addr")]
pub server_addr: SocketAddr,

#[serde(default)]
#[serde(default = "Rpc::reuseaddr_default")]
pub reuseaddr: bool,

#[serde(default)]
#[serde(default = "Rpc::reuseport_default")]
pub reuseport: bool,

#[serde(default = "Rpc::server_workers_default")]
Expand All @@ -170,8 +170,8 @@ impl Default for Rpc {
#[inline]
fn default() -> Self {
Self {
reuseaddr: false,
reuseport: false,
reuseaddr: Self::reuseaddr_default(),
reuseport: Self::reuseport_default(),
batch_size: Self::batch_size_default(),
server_addr: Self::server_addr_default(),
server_workers: Self::server_workers_default(),
Expand All @@ -182,6 +182,12 @@ impl Default for Rpc {
}

impl Rpc {
fn reuseaddr_default() -> bool {
true
}
fn reuseport_default() -> bool {
false
}
fn batch_size_default() -> usize {
128
}
Expand Down

0 comments on commit 1297c30

Please sign in to comment.