lib/nfs/Connection: merge CancelAndClose() into Cancel()
This commit is contained in:
parent
96b61755da
commit
1d35031024
@ -112,7 +112,6 @@ NfsConnection::CancellableCallback::CancelAndScheduleClose(struct nfsfh *fh,
|
|||||||
assert(!open);
|
assert(!open);
|
||||||
assert(close_fh == nullptr);
|
assert(close_fh == nullptr);
|
||||||
assert(!dispose_value);
|
assert(!dispose_value);
|
||||||
assert(fh != nullptr);
|
|
||||||
|
|
||||||
close_fh = fh;
|
close_fh = fh;
|
||||||
dispose_value = std::move(_dispose_value);
|
dispose_value = std::move(_dispose_value);
|
||||||
@ -371,9 +370,12 @@ NfsConnection::Read(struct nfsfh *fh, uint64_t offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NfsConnection::Cancel(NfsCallback &callback) noexcept
|
NfsConnection::Cancel(NfsCallback &callback,
|
||||||
|
struct nfsfh *fh,
|
||||||
|
DisposablePointer dispose_value) noexcept
|
||||||
{
|
{
|
||||||
callbacks.Cancel(callback);
|
CancellableCallback &cancel = callbacks.Get(callback);
|
||||||
|
cancel.CancelAndScheduleClose(fh, std::move(dispose_value));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -399,14 +401,6 @@ NfsConnection::Close(struct nfsfh *fh) noexcept
|
|||||||
ScheduleSocket();
|
ScheduleSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
NfsConnection::CancelAndClose(struct nfsfh *fh, DisposablePointer dispose_value,
|
|
||||||
NfsCallback &callback) noexcept
|
|
||||||
{
|
|
||||||
CancellableCallback &cancel = callbacks.Get(callback);
|
|
||||||
cancel.CancelAndScheduleClose(fh, std::move(dispose_value));
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NfsConnection::PrepareDestroyContext() noexcept
|
NfsConnection::PrepareDestroyContext() noexcept
|
||||||
{
|
{
|
||||||
|
@ -232,8 +232,14 @@ public:
|
|||||||
* #NfsCallback.
|
* #NfsCallback.
|
||||||
*
|
*
|
||||||
* Not thread-safe.
|
* Not thread-safe.
|
||||||
|
*
|
||||||
|
* @param fh if not nullptr, then close this NFS file handle
|
||||||
|
* after cancellation completes
|
||||||
|
* @param dispose_value an arbitrary value that will be
|
||||||
|
* disposed of after cancellation completes
|
||||||
*/
|
*/
|
||||||
void Cancel(NfsCallback &callback) noexcept;
|
void Cancel(NfsCallback &callback,
|
||||||
|
struct nfsfh *fh, DisposablePointer dispose_value) noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the specified file handle asynchronously.
|
* Close the specified file handle asynchronously.
|
||||||
@ -242,16 +248,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void Close(struct nfsfh *fh) noexcept;
|
void Close(struct nfsfh *fh) noexcept;
|
||||||
|
|
||||||
/**
|
|
||||||
* Like Cancel(), but also close the specified NFS file
|
|
||||||
* handle.
|
|
||||||
*
|
|
||||||
* @param dispose_value an arbitrary value that will be
|
|
||||||
* disposed of after cancellation completes
|
|
||||||
*/
|
|
||||||
void CancelAndClose(struct nfsfh *fh, DisposablePointer dispose_value,
|
|
||||||
NfsCallback &callback) noexcept;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnNfsConnectionError(std::exception_ptr e) noexcept = 0;
|
virtual void OnNfsConnectionError(std::exception_ptr e) noexcept = 0;
|
||||||
|
|
||||||
|
@ -56,20 +56,20 @@ NfsFileReader::CancelOrClose() noexcept
|
|||||||
/* no async operation in progress: can close
|
/* no async operation in progress: can close
|
||||||
immediately */
|
immediately */
|
||||||
connection->Close(fh);
|
connection->Close(fh);
|
||||||
else if (state > State::OPEN)
|
else if (state > State::OPEN) {
|
||||||
/* one async operation in progress: cancel it and
|
/* one async operation in progress: cancel it and
|
||||||
defer the nfs_close_async() call */
|
defer the nfs_close_async() call */
|
||||||
connection->CancelAndClose(fh,
|
DisposablePointer dispose_value{};
|
||||||
|
|
||||||
#ifdef LIBNFS_API_2
|
#ifdef LIBNFS_API_2
|
||||||
ToDeleteArray(read_buffer.release()),
|
dispose_value = ToDeleteArray(read_buffer.release());
|
||||||
#else
|
|
||||||
{},
|
|
||||||
#endif
|
#endif
|
||||||
*this);
|
|
||||||
else if (state > State::MOUNT)
|
connection->Cancel(*this, fh, std::move(dispose_value));
|
||||||
|
} else if (state > State::MOUNT)
|
||||||
/* we don't have a file handle yet - just cancel the
|
/* we don't have a file handle yet - just cancel the
|
||||||
async operation */
|
async operation */
|
||||||
connection->Cancel(*this);
|
connection->Cancel(*this, nullptr, {});
|
||||||
|
|
||||||
state = State::INITIAL;
|
state = State::INITIAL;
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ void
|
|||||||
NfsFileReader::CancelRead() noexcept
|
NfsFileReader::CancelRead() noexcept
|
||||||
{
|
{
|
||||||
if (state == State::READ) {
|
if (state == State::READ) {
|
||||||
connection->Cancel(*this);
|
connection->Cancel(*this, nullptr, {});
|
||||||
state = State::IDLE;
|
state = State::IDLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user