@@ -87,12 +87,15 @@ pub async fn call<Req: ReqMsg>(
8787 // register the call back
8888 let ( wait_tx, wait_rx) = oneshot:: channel ( ) ;
8989 let next_task = NEXT_TASK_ID . fetch_add ( 1 , Ordering :: SeqCst ) ;
90+ tracing:: debug!( "insert into CALL_MAP next_task:{:?}" , next_task. clone( ) ) ;
9091 let _ = CALL_MAP . write ( ) . insert ( next_task, wait_tx) ;
92+ tracing:: debug!( "insert after CALL_MAP.write(): {:?}" , CALL_MAP . write( ) ) ;
9193
9294 // send the request
9395 let mut buf = BytesMut :: with_capacity ( req. encoded_len ( ) + 8 ) ;
9496 buf. put_i32 ( req. encoded_len ( ) as i32 ) ;
9597 buf. put_i32 ( next_task as i32 ) ;
98+ buf. put_i32 ( 2 ) ;
9699 req. encode ( & mut buf) . unwrap ( ) ;
97100
98101 tracing:: debug!( "send request: {:?} with len: {}" , req, buf. len( ) - 8 ) ;
@@ -122,15 +125,16 @@ pub async fn call<Req: ReqMsg>(
122125// Disconnected,
123126// }
124127
125- struct ConnState {
128+ #[ derive( Debug ) ]
129+ pub struct ConnState {
126130 /// record the waiters
127131 // Connecting(Vec<oneshot::Sender<tokio::sync::mpsc::Sender<Vec<u8>>>>),
128- tx : tokio:: sync:: mpsc:: Sender < Vec < u8 > > ,
132+ pub tx : tokio:: sync:: mpsc:: Sender < Vec < u8 > > ,
129133}
130134
131135lazy_static ! {
132136 /// This is an example for using doc comment attributes
133- static ref CONN_MAP : RwLock <HashMap <HashValue , ConnState >> = RwLock :: new( HashMap :: new( ) ) ;
137+ pub static ref CONN_MAP : RwLock <HashMap <HashValue , ConnState >> = RwLock :: new( HashMap :: new( ) ) ;
134138
135139 static ref CALL_MAP : RwLock <HashMap <u32 , oneshot:: Sender <Vec <u8 >>>> = RwLock :: new( HashMap :: new( ) ) ;
136140
@@ -147,13 +151,19 @@ async fn listen_task<R: RpcCustom>(socket: tokio::net::UnixStream) {
147151 let Some ( ( conn, rx) ) =
148152 listen_task_ext:: verify_remote :: < R > ( & mut sockrx, & mut len, & mut buf) . await
149153 else {
150- tracing:: debug !( "verify failed" ) ;
154+ tracing:: warn !( "verify failed" ) ;
151155 return ;
152156 } ;
153157
158+ tracing:: debug!( "verify_remote 结束" ) ;
159+
154160 listen_task_ext:: spawn_send_loop ( rx, socktx) ;
155161
162+ tracing:: debug!( "spawn_send_loop 结束" ) ;
163+
156164 listen_task_ext:: read_loop :: < R > ( conn, & mut sockrx, & mut len, & mut buf) . await ;
165+
166+ tracing:: debug!( "read_loop 结束" ) ;
157167}
158168
159169pub ( super ) mod listen_task_ext {
@@ -172,8 +182,8 @@ pub(super) mod listen_task_ext {
172182
173183 pub ( super ) async fn verify_remote < R : RpcCustom > (
174184 sockrx : & mut OwnedReadHalf ,
175- len : & mut usize ,
176- buf : & mut [ u8 ] ,
185+ len : & mut usize , // 0
186+ buf : & mut [ u8 ] , // 0
177187 ) -> Option < ( HashValue , Receiver < Vec < u8 > > ) > {
178188 async fn verify_remote_inner < R : RpcCustom > (
179189 sockrx : & mut OwnedReadHalf ,
@@ -188,25 +198,33 @@ pub(super) mod listen_task_ext {
188198
189199 let verify_msg_len = consume_i32 ( 0 , buf, len) ;
190200
201+ tracing:: debug!( "len: {}, verify_msg_len: {}" , len, verify_msg_len) ;
202+
191203 // println!("waiting for verify msg {}", verify_msg_len);
192204 if !wait_for_len ( sockrx, len, verify_msg_len, buf) . await {
193205 tracing:: warn!( "failed to read verify msg" ) ;
194206 return None ;
195207 }
196208 // println!("wait done");
197209
210+ tracing:: debug!( "wait_for_len 完成" ) ;
211+
198212 let Some ( id) = R :: verify ( & buf[ 4 ..4 + verify_msg_len] ) . await else {
199- tracing:: warn!( "verify failed" ) ;
213+ tracing:: warn!( "verify failed in verify_remote_inner " ) ;
200214 return None ;
201215 } ;
202216 let ( tx, rx) = tokio:: sync:: mpsc:: channel ( 10 ) ;
203217
218+ // 确定一下为什么 conn_map 里面有上一次连接 id, 需要找这个 conn_map 在哪里都被调用了
204219 let mut write_conn_map = CONN_MAP . write ( ) ;
220+ tracing:: debug!( "write_conn_map: {:?}" , write_conn_map) ;
205221 if write_conn_map. contains_key ( & id) {
206222 tracing:: warn!( "conflict conn id: {:?}" , id) ;
207223 return None ;
208224 }
209225 let _ = write_conn_map. insert ( id. clone ( ) , ConnState { tx } ) ;
226+ tracing:: debug!( "insert into CALL_MAP id:{:?}" , id. clone( ) ) ;
227+ tracing:: debug!( "insert after CALL_MAP.write(): {:?}" , write_conn_map) ;
210228
211229 // println!("verify success");
212230 Some ( ( id, rx) )
@@ -230,6 +248,7 @@ pub(super) mod listen_task_ext {
230248 * len = 0 ;
231249 let mut offset = 0 ;
232250 loop {
251+
233252 let ( msg_len, msg_id, taskid) = {
234253 let buf = & mut buf[ offset..] ;
235254 if !wait_for_len ( socket, len, 9 , buf) . await {
@@ -243,6 +262,8 @@ pub(super) mod listen_task_ext {
243262 consume_i32 ( 5 , buf, len) as u32 ,
244263 )
245264 } ;
265+
266+ tracing:: debug!( "2 len: {}, msg_len: {}, msg_id: {}, taskid: {}" , len, msg_len, msg_id, taskid) ;
246267
247268 {
248269 if buf. len ( ) < offset + msg_len {
@@ -269,12 +290,15 @@ pub(super) mod listen_task_ext {
269290 } ;
270291
271292 let msg = buf[ ..msg_len] . to_vec ( ) ;
293+ tracing:: debug!( "msg: {:?}" , msg) ;
272294 cb. send ( msg) . unwrap ( ) ;
273295 }
274296
275297 // update the buf meta
276298 offset += msg_len;
277299 * len -= msg_len;
300+
301+ tracing:: debug!( "1 len: {}, msg_len: {}, msg_id: {}, taskid: {}" , len, msg_len, msg_id, taskid) ;
278302 }
279303
280304 // match socket.read(buf).await {
@@ -331,6 +355,7 @@ pub(super) mod listen_task_ext {
331355 return false ;
332356 }
333357 // println!("recv: {:?}", buf[..n]);
358+ tracing:: debug!( "len += {}" , n) ;
334359 * len += n;
335360 }
336361 Err ( e) => {
0 commit comments