Skip to content

Commit 389222c

Browse files
committed
Test stream info
1 parent 10d20f5 commit 389222c

File tree

1 file changed

+15
-3
lines changed
  • fortanix-vme/tests/incoming_connection/src

1 file changed

+15
-3
lines changed

fortanix-vme/tests/incoming_connection/src/main.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::io::{Read, Write};
2-
use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpListener};
1+
#![feature(io_error_uncategorized)]
2+
use std::io::{ErrorKind, Read, Write};
3+
use std::net::{IpAddr, Ipv4Addr, Shutdown, SocketAddr, TcpListener, TcpStream};
34
use std::os::unix::io::{AsRawFd, FromRawFd};
45

56
fn server_run() {
@@ -15,12 +16,23 @@ fn server_run() {
1516
for id in 1..3 {
1617
println!("Waiting for connection {}", id);
1718
match listener.accept() {
18-
Ok((mut stream, addr)) => {
19+
Ok((stream, addr)) => {
1920
println!("# addr = {:?}", addr);
2021
assert_eq!(stream.peer_addr().unwrap().ip(), Ipv4Addr::new(127, 0, 0, 1));
2122
assert!(stream.peer_addr().unwrap().port() != 3400);
2223
assert_eq!(stream.local_addr().unwrap().ip(), Ipv4Addr::new(127, 0, 0, 1));
2324
assert_eq!(stream.local_addr().unwrap().port(), 3400);
25+
26+
let fd = stream.as_raw_fd();
27+
let mut stream = unsafe { TcpStream::from_raw_fd(fd) };
28+
assert_eq!(stream.peer_addr().unwrap().ip(), Ipv4Addr::new(127, 0, 0, 1));
29+
assert!(stream.peer_addr().unwrap().port() != 3400);
30+
assert_eq!(stream.local_addr().unwrap().ip(), Ipv4Addr::new(127, 0, 0, 1));
31+
assert_eq!(stream.local_addr().unwrap().port(), 3400);
32+
33+
let no_stream = unsafe { TcpStream::from_raw_fd(666.into()) };
34+
assert_eq!(no_stream.peer_addr().unwrap_err().kind(), ErrorKind::Uncategorized);
35+
2436
println!("Connection {}: Connected", id);
2537
let mut buff_in = [0u8; 4192];
2638
let n = stream.read(&mut buff_in).unwrap();

0 commit comments

Comments
 (0)