feat: implement native UDP ping/pong health check pattern
This commit is contained in:
1 parent
0da84c804c
commit
8c6bf05269
1 file changed
+6
-4
+6
-4
@@ -368,11 +368,13 @@ pub async fn run_server(state: Arc<MemoryState>) -> Result<(), Box<dyn std::erro
|
||||
for tx in senders {
|
||||
let _ = tx.try_send(msg_str.clone());
|
||||
}
|
||||
} else if let Ok(gate_wait) = serde_json::from_slice::<serde_json::Value>(&buf[..len]) {
|
||||
if gate_wait.get("type").and_then(|t| t.as_str()) == Some("gate_wait") {
|
||||
} else if let Ok(json_payload) = serde_json::from_slice::<serde_json::Value>(&buf[..len]) {
|
||||
if json_payload.get("type").and_then(|t| t.as_str()) == Some("ping") {
|
||||
let _ = socket.send_to(b"pong", addr).await;
|
||||
} else if json_payload.get("type").and_then(|t| t.as_str()) == Some("gate_wait") {
|
||||
if let (Some(action), Some(target)) = (
|
||||
gate_wait.get("action").and_then(|a| a.as_str()),
|
||||
gate_wait.get("target").and_then(|t| t.as_str())
|
||||
json_payload.get("action").and_then(|a| a.as_str()),
|
||||
json_payload.get("target").and_then(|t| t.as_str())
|
||||
) {
|
||||
subscribers.insert((action.to_string(), target.to_string()), addr);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user