Skip to content

Commit

Permalink
AsyncUDPSocket to invoke readCallback only at the end of the calling …
Browse files Browse the repository at this point in the history
…function

Summary: Moving the readCallback to the end of the calling function maintains the same behavior, and should not impact anything.

Reviewed By: yfeldblum

Differential Revision: D57012214

fbshipit-source-id: c7fbe1c5445b1622be332bd42c5f5f0d2982b087
  • Loading branch information
Siming Li authored and facebook-github-bot committed May 8, 2024
1 parent dca5b83 commit 9499b83
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions folly/io/async/AsyncUDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,13 +1070,6 @@ void AsyncUDPSocket::pauseRead() {
void AsyncUDPSocket::close() {
eventBase_->dcheckIsInEventBaseThread();

if (readCallback_) {
auto cob = readCallback_;
readCallback_ = nullptr;

cob->onReadClosed();
}

// Unregister any events we are registered for
unregisterHandler();

Expand All @@ -1085,6 +1078,12 @@ void AsyncUDPSocket::close() {
}

fd_ = NetworkSocket();

if (readCallback_) {
auto cob = readCallback_;
readCallback_ = nullptr;
cob->onReadClosed();
}
}

void AsyncUDPSocket::handlerReady(uint16_t events) noexcept {
Expand Down Expand Up @@ -1238,9 +1237,8 @@ void AsyncUDPSocket::handleRead() noexcept {

auto cob = readCallback_;
readCallback_ = nullptr;

cob->onReadError(ex);
updateRegistration();
cob->onReadError(ex);
return;
}

Expand Down Expand Up @@ -1347,10 +1345,8 @@ void AsyncUDPSocket::handleRead() noexcept {
// so that he can do some logging/stats collection if he wants.
auto cob = readCallback_;
readCallback_ = nullptr;

cob->onReadError(ex);
updateRegistration();

cob->onReadError(ex);
return;
}
}
Expand Down

0 comments on commit 9499b83

Please sign in to comment.