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.
This commit is contained in:
parent
159389164a
commit
e53a4d0a9e
@ -180,14 +180,11 @@ NfsFileReader::OnNfsConnectionDisconnected(std::exception_ptr e) noexcept
|
|||||||
inline void
|
inline void
|
||||||
NfsFileReader::OpenCallback(nfsfh *_fh) noexcept
|
NfsFileReader::OpenCallback(nfsfh *_fh) noexcept
|
||||||
{
|
{
|
||||||
assert(state == State::OPEN);
|
|
||||||
assert(connection != nullptr);
|
assert(connection != nullptr);
|
||||||
assert(_fh != nullptr);
|
assert(_fh != nullptr);
|
||||||
|
|
||||||
fh = _fh;
|
fh = _fh;
|
||||||
|
|
||||||
state = State::IDLE;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection->Stat(fh, *this);
|
connection->Stat(fh, *this);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
@ -201,13 +198,10 @@ NfsFileReader::OpenCallback(nfsfh *_fh) noexcept
|
|||||||
inline void
|
inline void
|
||||||
NfsFileReader::StatCallback(const struct stat *st) noexcept
|
NfsFileReader::StatCallback(const struct stat *st) noexcept
|
||||||
{
|
{
|
||||||
assert(state == State::STAT);
|
|
||||||
assert(connection != nullptr);
|
assert(connection != nullptr);
|
||||||
assert(fh != nullptr);
|
assert(fh != nullptr);
|
||||||
assert(st != nullptr);
|
assert(st != nullptr);
|
||||||
|
|
||||||
state = State::IDLE;
|
|
||||||
|
|
||||||
if (!S_ISREG(st->st_mode)) {
|
if (!S_ISREG(st->st_mode)) {
|
||||||
OnNfsFileError(std::make_exception_ptr(std::runtime_error("Not a regular file")));
|
OnNfsFileError(std::make_exception_ptr(std::runtime_error("Not a regular file")));
|
||||||
return;
|
return;
|
||||||
@ -219,7 +213,7 @@ NfsFileReader::StatCallback(const struct stat *st) noexcept
|
|||||||
void
|
void
|
||||||
NfsFileReader::OnNfsCallback(unsigned status, void *data) noexcept
|
NfsFileReader::OnNfsCallback(unsigned status, void *data) noexcept
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (std::exchange(state, State::IDLE)) {
|
||||||
case State::INITIAL:
|
case State::INITIAL:
|
||||||
case State::DEFER:
|
case State::DEFER:
|
||||||
case State::MOUNT:
|
case State::MOUNT:
|
||||||
@ -236,7 +230,6 @@ NfsFileReader::OnNfsCallback(unsigned status, void *data) noexcept
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case State::READ:
|
case State::READ:
|
||||||
state = State::IDLE;
|
|
||||||
OnNfsFileRead(data, status);
|
OnNfsFileRead(data, status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user