Skip to content

Commit

Permalink
Handle CURL_POLL_INOUT correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Oct 27, 2020
1 parent 2db3c5e commit 6515329
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions benchmarks/benches/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn benchmark(c: &mut Criterion) {

transfer.perform().unwrap();
},
BatchSize::SmallInput,
BatchSize::LargeInput,
)
});

Expand All @@ -45,7 +45,7 @@ fn benchmark(c: &mut Criterion) {
|client| {
client.get(&endpoint).unwrap().copy_to(sink()).unwrap();
},
BatchSize::SmallInput,
BatchSize::LargeInput,
)
});
}
Expand Down
18 changes: 12 additions & 6 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,28 +599,34 @@ impl AgentContext {
// This is a new socket, at least from curl's perspective. Set up a new
// socket context for it, and then register it with the poller.
else if key == 0 {
let readable = events.input() || events.input_and_output();
let writable = events.output() || events.input_and_output();

let key = self.sockets.insert(SocketContext {
socket,
readable: events.input(),
writable: events.output(),
readable,
writable,
}) + 1;

// Tell curl about our chosen key for this socket.
self.multi.assign(socket, key)?;

// Add the socket to our poller.
self.poller_add(socket, key, events.input(), events.output())?;
self.poller_add(socket, key, readable, writable)?;
}

// This is a socket we've seen before and are already managing.
else {
if let Some(socket_ctx) = self.sockets.get_mut(key - 1) {
let readable = events.input() || events.input_and_output();
let writable = events.output() || events.input_and_output();

// Update the interest we have recorded for this socket.
socket_ctx.readable = events.input();
socket_ctx.writable = events.output();
socket_ctx.readable = readable;
socket_ctx.writable = writable;

// Update the socket interests with our poller.
self.poller_modify(socket, key, events.input(), events.output())?;
self.poller_modify(socket, key, readable, writable)?;
} else {
// Curl should never give us a key that we did not first give to
// curl!
Expand Down

0 comments on commit 6515329

Please sign in to comment.