{input,storage}/nfs: use C++ exceptions instead of class Error
This commit is contained in:
@@ -22,11 +22,9 @@
|
||||
#include "Glue.hxx"
|
||||
#include "Base.hxx"
|
||||
#include "Connection.hxx"
|
||||
#include "Domain.hxx"
|
||||
#include "event/Call.hxx"
|
||||
#include "IOThread.hxx"
|
||||
#include "util/StringCompare.hxx"
|
||||
#include "util/Error.hxx"
|
||||
|
||||
#include <utility>
|
||||
|
||||
@@ -128,16 +126,13 @@ NfsFileReader::Open(const char *uri)
|
||||
DeferredMonitor::Schedule();
|
||||
}
|
||||
|
||||
bool
|
||||
NfsFileReader::Read(uint64_t offset, size_t size, Error &error)
|
||||
void
|
||||
NfsFileReader::Read(uint64_t offset, size_t size)
|
||||
{
|
||||
assert(state == State::IDLE);
|
||||
|
||||
if (!connection->Read(fh, offset, size, *this, error))
|
||||
return false;
|
||||
|
||||
connection->Read(fh, offset, size, *this);
|
||||
state = State::READ;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -154,9 +149,10 @@ NfsFileReader::OnNfsConnectionReady()
|
||||
{
|
||||
assert(state == State::MOUNT);
|
||||
|
||||
Error error;
|
||||
if (!connection->Open(path, O_RDONLY, *this, error)) {
|
||||
OnNfsFileError(std::move(error));
|
||||
try {
|
||||
connection->Open(path, O_RDONLY, *this);
|
||||
} catch (...) {
|
||||
OnNfsFileError(std::current_exception());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -164,27 +160,23 @@ NfsFileReader::OnNfsConnectionReady()
|
||||
}
|
||||
|
||||
void
|
||||
NfsFileReader::OnNfsConnectionFailed(const Error &error)
|
||||
NfsFileReader::OnNfsConnectionFailed(std::exception_ptr e)
|
||||
{
|
||||
assert(state == State::MOUNT);
|
||||
|
||||
state = State::INITIAL;
|
||||
|
||||
Error copy;
|
||||
copy.Set(error);
|
||||
OnNfsFileError(std::move(copy));
|
||||
OnNfsFileError(std::move(e));
|
||||
}
|
||||
|
||||
void
|
||||
NfsFileReader::OnNfsConnectionDisconnected(const Error &error)
|
||||
NfsFileReader::OnNfsConnectionDisconnected(std::exception_ptr e)
|
||||
{
|
||||
assert(state > State::MOUNT);
|
||||
|
||||
CancelOrClose();
|
||||
|
||||
Error copy;
|
||||
copy.Set(error);
|
||||
OnNfsFileError(std::move(copy));
|
||||
OnNfsFileError(std::move(e));
|
||||
}
|
||||
|
||||
inline void
|
||||
@@ -196,9 +188,10 @@ NfsFileReader::OpenCallback(nfsfh *_fh)
|
||||
|
||||
fh = _fh;
|
||||
|
||||
Error error;
|
||||
if (!connection->Stat(fh, *this, error)) {
|
||||
OnNfsFileError(std::move(error));
|
||||
try {
|
||||
connection->Stat(fh, *this);
|
||||
} catch (...) {
|
||||
OnNfsFileError(std::current_exception());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -214,7 +207,7 @@ NfsFileReader::StatCallback(const struct stat *st)
|
||||
assert(st != nullptr);
|
||||
|
||||
if (!S_ISREG(st->st_mode)) {
|
||||
OnNfsFileError(Error(nfs_domain, "Not a regular file"));
|
||||
OnNfsFileError(std::make_exception_ptr(std::runtime_error("Not a regular file")));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -250,7 +243,7 @@ NfsFileReader::OnNfsCallback(unsigned status, void *data)
|
||||
}
|
||||
|
||||
void
|
||||
NfsFileReader::OnNfsError(Error &&error)
|
||||
NfsFileReader::OnNfsError(std::exception_ptr &&e)
|
||||
{
|
||||
switch (state) {
|
||||
case State::INITIAL:
|
||||
@@ -276,7 +269,7 @@ NfsFileReader::OnNfsError(Error &&error)
|
||||
break;
|
||||
}
|
||||
|
||||
OnNfsFileError(std::move(error));
|
||||
OnNfsFileError(std::move(e));
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user