Skip to content

Commit c694607

Browse files
committed
Do better to make cancellation idempotent
1 parent f37305b commit c694607

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/aur/client.cc

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,16 @@ int ClientImpl::OnCancel(sd_event_source*, void* userdata) {
322322
aur->Cancel(*aur->active_requests_.begin());
323323
}
324324

325-
aur->cancelled_ = true;
326-
327325
return 0;
328326
}
329327

330328
void ClientImpl::CancelAll() {
329+
if (cancelled_) {
330+
return;
331+
}
332+
333+
cancelled_ = true;
334+
331335
sd_event_source* cancel;
332336
sd_event_add_defer(event_, &cancel, &ClientImpl::OnCancel, this);
333337
active_requests_.insert(cancel);
@@ -348,18 +352,13 @@ int ClientImpl::DispatchSocketCallback(curl_socket_t s, int action,
348352
return CheckFinished();
349353
}
350354

351-
auto events = [action]() -> std::uint32_t {
352-
switch (action) {
353-
case CURL_POLL_IN:
354-
return EPOLLIN;
355-
case CURL_POLL_OUT:
356-
return EPOLLOUT;
357-
case CURL_POLL_INOUT:
358-
return EPOLLIN | EPOLLOUT;
359-
default:
360-
return 0;
361-
}
362-
}();
355+
uint32_t events = 0;
356+
if (action & CURL_CSELECT_IN) {
357+
events |= EPOLLIN;
358+
}
359+
if (action & CURL_CSELECT_OUT) {
360+
events |= EPOLLOUT;
361+
}
363362

364363
if (io != nullptr) {
365364
if (sd_event_source_set_io_events(io, events) < 0) {

0 commit comments

Comments
 (0)