Commit 1f73ae2b authored by nanamicat's avatar nanamicat

BTreeMap

parent dc2030f9
Pipeline #42038 failed with stages
in 2 minutes and 13 seconds
...@@ -2,7 +2,7 @@ mod config; ...@@ -2,7 +2,7 @@ mod config;
mod router; mod router;
use crate::config::{Config, Schema}; use crate::config::{Config, Schema};
use crate::router::{Meta, Router, META_SIZE}; use crate::router::Router;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use crossbeam::epoch::{pin, Owned}; use crossbeam::epoch::{pin, Owned};
use crossbeam_utils::thread; use crossbeam_utils::thread;
...@@ -11,7 +11,7 @@ use std::collections::BTreeMap; ...@@ -11,7 +11,7 @@ use std::collections::BTreeMap;
use std::net::Shutdown; use std::net::Shutdown;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
use std::time::Duration; use std::time::Duration;
use std::{env, mem::MaybeUninit}; use std::env;
fn main() -> Result<()> { fn main() -> Result<()> {
println!("Starting"); println!("Starting");
...@@ -75,16 +75,13 @@ fn main() -> Result<()> { ...@@ -75,16 +75,13 @@ fn main() -> Result<()> {
let (connection, _) = socket.accept().unwrap(); let (connection, _) = socket.accept().unwrap();
s.spawn(move |_| { s.spawn(move |_| {
connection.set_tcp_nodelay(true).unwrap(); connection.set_tcp_nodelay(true).unwrap();
let mut meta_bytes = [0u8; 2];
let mut meta_bytes = [MaybeUninit::uninit(); META_SIZE];
Router::recv_exact_tcp(&connection, &mut meta_bytes).unwrap(); Router::recv_exact_tcp(&connection, &mut meta_bytes).unwrap();
let meta: &Meta = Meta::from_bytes(&meta_bytes); let src_id = meta_bytes[0];
if meta.reversed == 0 let dst_id = meta_bytes[1];
&& let Some(router) = routers.get(&meta.src_id) if let Some(router) = routers.get(&src_id)
&& meta.dst_id == router.config.local_id && dst_id == router.config.local_id
{ {
// let connection = Arc::new(connection);
// tcp listener 只许一个连接,过来新连接就把前一个关掉。 // tcp listener 只许一个连接,过来新连接就把前一个关掉。
{ {
let guard = pin(); let guard = pin();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment