-
Notifications
You must be signed in to change notification settings - Fork 720
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move 'read loop to recv_from in quiche-server
- Loading branch information
1 parent
2870838
commit f0620a7
Showing
7 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,5 @@ extern crate log; | |
pub mod args; | ||
pub mod client; | ||
pub mod common; | ||
pub mod recvfrom; | ||
pub mod sendto; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use dgram::RecvData; | ||
|
||
use std::io; | ||
|
||
// TODO: migrate setup code to use [dgram::SocketCapabilities]. | ||
|
||
/// For Linux, try to detect if GRO is available. If it is, the | ||
/// [`UdpGroSegment`] socket option will be set on the passed socket. | ||
/// | ||
/// [`UdpGroSegment`]: https://docs.rs/nix/latest/nix/sys/socket/sockopt/struct.UdpGroSegment.html | ||
#[cfg(target_os = "linux")] | ||
pub fn detect_gro(socket: &mio::net::UdpSocket) -> bool { | ||
use nix::sys::socket::setsockopt; | ||
use nix::sys::socket::sockopt::UdpGroSegment; | ||
use std::os::unix::io::AsRawFd; | ||
|
||
// mio::net::UdpSocket doesn't implement AsFd (yet?). | ||
let fd = unsafe { std::os::fd::BorrowedFd::borrow_raw(socket.as_raw_fd()) }; | ||
|
||
setsockopt(&fd, UdpGroSegment, &true).is_ok() | ||
} | ||
|
||
#[cfg(not(target_os = "linux"))] | ||
pub fn detect_gro(socket: &mio::net::UdpSocket, _segment_size: usize) -> bool { | ||
false | ||
} | ||
|
||
#[cfg(target_os = "linux")] | ||
pub fn recv_from( | ||
socket: &mio::net::UdpSocket, buf: &mut [u8], | ||
) -> io::Result<RecvData> { | ||
use dgram::RecvMsgCmsgSettings; | ||
use std::os::unix::io::AsRawFd; | ||
|
||
let mut recvmsg_cmsg_settings = RecvMsgCmsgSettings { | ||
store_cmsgs: false, | ||
cmsg_space: vec![], | ||
}; | ||
|
||
socket.try_io(|| { | ||
let fd = | ||
unsafe { std::os::fd::BorrowedFd::borrow_raw(socket.as_raw_fd()) }; | ||
|
||
dgram::sync::recv_from(&fd, buf, None, &mut recvmsg_cmsg_settings) | ||
}) | ||
} | ||
|
||
// TODO: shoould it be up to the user to handle blocking errors? | ||
#[cfg(not(target_os = "linux"))] | ||
fn recv_from( | ||
socket: &mio::net::UdpSocket, buf: &mut [u8], | ||
) -> std::io::Result<RecvData> { | ||
match socket.recv_from(buf) { | ||
Ok((read, from)) => Ok(RecvData::new(Some(from), read, 0)), | ||
Err(_) => {}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters