Add function "set_timeout"
This commit is contained in:
parent
e08d8d69a0
commit
e6fa791fd0
1 changed files with 13 additions and 9 deletions
22
src/main.rs
22
src/main.rs
|
@ -39,15 +39,7 @@ fn main() {
|
|||
|
||||
send_request(socket, current_ttl, &host, &request);
|
||||
|
||||
let timeval = libc::timeval { tv_sec: 2, tv_usec: 0 };
|
||||
|
||||
assert_eq!(0, unsafe { libc::setsockopt(
|
||||
socket,
|
||||
libc::SOL_SOCKET,
|
||||
libc::SO_RCVTIMEO,
|
||||
&timeval as *const libc::timeval as *const libc::c_void,
|
||||
std::mem::size_of::<libc::timeval>().try_into().unwrap(),
|
||||
) });
|
||||
set_timeout(socket, 2, 0);
|
||||
|
||||
let mut response: Option<Response> = None;
|
||||
|
||||
|
@ -120,6 +112,18 @@ fn send_request(
|
|||
) });
|
||||
}
|
||||
|
||||
fn set_timeout(socket: libc::c_int, sec: i64, usec: i64) {
|
||||
let timeval = libc::timeval { tv_sec: sec, tv_usec: usec };
|
||||
|
||||
assert_eq!(0, unsafe { libc::setsockopt(
|
||||
socket,
|
||||
libc::SOL_SOCKET,
|
||||
libc::SO_RCVTIMEO,
|
||||
&timeval as *const libc::timeval as *const libc::c_void,
|
||||
std::mem::size_of::<libc::timeval>().try_into().unwrap(),
|
||||
) });
|
||||
}
|
||||
|
||||
fn recv_response(socket: libc::c_int) -> Option<Response> {
|
||||
let response_body_data: [u8; 1024] = [0; 1024];
|
||||
|
||||
|
|
Reference in a new issue