Skip to content

Commit

Permalink
use fcntl to set the O_NONBLOCK flag
Browse files Browse the repository at this point in the history
  • Loading branch information
brianshih1 committed Oct 9, 2023
1 parent a77dce9 commit 67c278b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
ahash = "0.8.3"
futures-lite = "1.13.0"
iou = "0.3.3"
nix = { version = "0.27.1", features = ["sched"] }
nix = { version = "0.27.1", features = ["sched", "fs"] }

polling = "2.8.0"
scoped-tls = "1.0.1"
1 change: 1 addition & 0 deletions src/executor/local_executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn simple_spawn() {

#[test]
fn local_executor_builder_placement() {
// The LocalExecutor will now only run on Cpu 0
let builder = LocalExecutorBuilder::new(Placement::Fixed(0));
let local_ex = builder.build();
let res = local_ex.run(async {
Expand Down
1 change: 0 additions & 1 deletion src/net/async_networking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ impl Async<TcpListener> {
pub fn bind<A: Into<SocketAddr>>(addr: A) -> io::Result<Async<TcpListener>> {
let addr = addr.into();
let listener = TcpListener::bind(addr)?;
listener.set_nonblocking(true).unwrap();
Ok(Async::new(listener)?)
}

Expand Down
3 changes: 3 additions & 0 deletions src/reactor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{io, os::fd::RawFd};

use nix::fcntl::{self, fcntl, FcntlArg, OFlag};

use crate::{
executor::executor,
sys::{self, source::Source, SourceType},
Expand Down Expand Up @@ -29,6 +31,7 @@ impl Reactor {
}

pub fn insert_pollable_io(&self, raw: RawFd) -> Source {
fcntl(raw, FcntlArg::F_SETFL(OFlag::O_NONBLOCK)).unwrap();
self.new_source(raw, SourceType::PollableFd)
}

Expand Down

0 comments on commit 67c278b

Please sign in to comment.