Skip to content

Commit

Permalink
When constructing a *Listener socket, check that it's actually listening
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Dec 14, 2023
1 parent 789a3ce commit 89d1d10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ default = []
capsicum = { version = "0.3.0", features = ["casper"] }
casper-sys = { version = "0.1.1" }
cstr = "0.2.0"
libc = "0.2.147"
nix = { version = "0.27.0", features = [ "net", "socket" ] }
libc = "0.2.150"
nix = { version = "0.27.1", features = [ "net", "socket" ] }
tokio = { version = "1.27.0", default-features = false, features = ["net"], optional = true}

[dev-dependencies]
ctor = "0.2.3"
libc = "0.2.147"
tempfile = "3.4"
tokio = { version = "1.27.0", features = ["macros", "rt"] }

Expand All @@ -41,3 +40,5 @@ path = "tests/functional/mod.rs"
[patch.crates-io]
capsicum = { git = "https://github.com/asomers/capsicum-rs", rev = "f5fd1e6"}
casper-sys = { git = "https://github.com/asomers/capsicum-rs", rev = "f5fd1e6"}
libc = { git = "https://github.com/rust-lang/libc", rev = "f37806e499409eab8cfa897280a869bc5e2623a9" }
nix = { git = "https://github.com/asomers/nix", rev = "34eec97" }
4 changes: 4 additions & 0 deletions tests/functional/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use capsicum_net::{
UnixDatagramExt,
UnixListenerExt,
};
use nix::sys::socket::{getsockopt, sockopt::ListenQLimit};
use tempfile::TempDir;

use crate::CASPER;
Expand Down Expand Up @@ -65,6 +66,7 @@ mod bind {
let socket = TcpListener::cap_bind(&mut cap_net, want).unwrap();
let bound = socket.local_addr().unwrap();
assert_eq!(want, bound);
assert!(getsockopt(&socket, ListenQLimit).unwrap() > 0);
}

#[test]
Expand All @@ -76,6 +78,7 @@ mod bind {
let socket = TcpListener::cap_bind(&mut cap_net, want).unwrap();
let bound = socket.local_addr().unwrap();
assert_eq!(want, bound);
assert!(getsockopt(&socket, ListenQLimit).unwrap() > 0);
}
}

Expand Down Expand Up @@ -172,6 +175,7 @@ mod bind {
let bound: nix::sys::socket::UnixAddr =
nix::sys::socket::getsockname(socket.as_raw_fd()).unwrap();
assert_eq!(path, bound.path().unwrap());
assert!(getsockopt(&socket, ListenQLimit).unwrap() > 0);
}
}
}

0 comments on commit 89d1d10

Please sign in to comment.