Commit e53a4d0a authored by Max Kellermann's avatar Max Kellermann

lib/nfs/FileReader: reset `state` in OnNfsCallback()

The object's state is `IDLE` when OnNfsCallback() gets invoked, so let's use the start of the method to reset the `state` field.
parent 15938916
......@@ -180,14 +180,11 @@ NfsFileReader::OnNfsConnectionDisconnected(std::exception_ptr e) noexcept
inline void
NfsFileReader::OpenCallback(nfsfh *_fh) noexcept
{
assert(state == State::OPEN);
assert(connection != nullptr);
assert(_fh != nullptr);
fh = _fh;
state = State::IDLE;
try {
connection->Stat(fh, *this);
} catch (...) {
......@@ -201,13 +198,10 @@ NfsFileReader::OpenCallback(nfsfh *_fh) noexcept
inline void
NfsFileReader::StatCallback(const struct stat *st) noexcept
{
assert(state == State::STAT);
assert(connection != nullptr);
assert(fh != nullptr);
assert(st != nullptr);
state = State::IDLE;
if (!S_ISREG(st->st_mode)) {
OnNfsFileError(std::make_exception_ptr(std::runtime_error("Not a regular file")));
return;
......@@ -219,7 +213,7 @@ NfsFileReader::StatCallback(const struct stat *st) noexcept
void
NfsFileReader::OnNfsCallback(unsigned status, void *data) noexcept
{
switch (state) {
switch (std::exchange(state, State::IDLE)) {
case State::INITIAL:
case State::DEFER:
case State::MOUNT:
......@@ -236,7 +230,6 @@ NfsFileReader::OnNfsCallback(unsigned status, void *data) noexcept
break;
case State::READ:
state = State::IDLE;
OnNfsFileRead(data, status);
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment