File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -27,3 +27,39 @@ fn smoke_bind_connect() {
2727 drop ( listener) ;
2828 let _ = std:: fs:: remove_file ( & sock_path) ;
2929}
30+
31+ #[ test]
32+ fn win_uds_echo ( ) {
33+ let tmp = std:: env:: temp_dir ( ) ;
34+ let sock_path = tmp. join ( "rust-test-uds-echo.sock" ) ;
35+ let _ = std:: fs:: remove_file ( & sock_path) ;
36+
37+ let listener = UnixListener :: bind ( & sock_path) . expect ( "bind failed" ) ;
38+ let srv = thread:: spawn ( move || {
39+ let ( mut stream, _) = listener. accept ( ) . expect ( "accept failed" ) ;
40+ let mut buf = [ 0u8 ; 128 ] ;
41+ loop {
42+ let n = match stream. read ( & mut buf) {
43+ Ok ( 0 ) => break , // 对端关闭
44+ Ok ( n) => n,
45+ Err ( e) => panic ! ( "read error: {}" , e) ,
46+ } ;
47+ stream. write_all ( & buf[ ..n] ) . expect ( "write_all failed" ) ;
48+ }
49+ } ) ;
50+
51+ let sock_path_clone = sock_path. clone ( ) ;
52+ let cli = thread:: spawn ( move || {
53+ let mut stream = UnixStream :: connect ( & sock_path_clone) . expect ( "connect failed" ) ;
54+ let req = b"hello windows uds" ;
55+ stream. write_all ( req) . expect ( "write failed" ) ;
56+ let mut resp = vec ! [ 0u8 ; req. len( ) ] ;
57+ stream. read_exact ( & mut resp) . expect ( "read failed" ) ;
58+ assert_eq ! ( resp, req) ;
59+ } ) ;
60+
61+ cli. join ( ) . unwrap ( ) ;
62+ srv. join ( ) . unwrap ( ) ;
63+
64+ let _ = std:: fs:: remove_file ( & sock_path) ;
65+ }
You can’t perform that action at this time.
0 commit comments