lib/nfs/Connection: simplify error handling in OnSocketReady()
This commit is contained in:
parent
e6b1cf540b
commit
56bb1dddd7
@ -473,6 +473,7 @@ NfsConnection::OnSocketReady(unsigned flags) noexcept
|
|||||||
assert(GetEventLoop().IsInside());
|
assert(GetEventLoop().IsInside());
|
||||||
assert(deferred_close.empty());
|
assert(deferred_close.empty());
|
||||||
assert(mount_state >= MountState::WAITING);
|
assert(mount_state >= MountState::WAITING);
|
||||||
|
assert(!postponed_mount_error);
|
||||||
|
|
||||||
const bool was_mounted = mount_state >= MountState::FINISHED;
|
const bool was_mounted = mount_state >= MountState::FINISHED;
|
||||||
if (!was_mounted || (flags & SocketEvent::HANGUP) != 0)
|
if (!was_mounted || (flags & SocketEvent::HANGUP) != 0)
|
||||||
@ -492,36 +493,33 @@ NfsConnection::OnSocketReady(unsigned flags) noexcept
|
|||||||
deferred_close.pop_front();
|
deferred_close.pop_front();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!was_mounted && mount_state >= MountState::FINISHED) {
|
try {
|
||||||
if (postponed_mount_error) {
|
if (postponed_mount_error)
|
||||||
PrepareDestroyContext();
|
std::rethrow_exception(postponed_mount_error);
|
||||||
BroadcastMountError(std::move(postponed_mount_error));
|
|
||||||
return;
|
|
||||||
} else if (result == 0)
|
|
||||||
BroadcastMountSuccess();
|
|
||||||
} else if (result < 0) {
|
|
||||||
/* the connection has failed */
|
|
||||||
|
|
||||||
auto e = NfsClientError(context, "NFS connection has failed");
|
if (result < 0)
|
||||||
BroadcastError(std::make_exception_ptr(e));
|
throw NfsClientError(context, "NFS connection has failed");
|
||||||
|
|
||||||
PrepareDestroyContext();
|
|
||||||
return;
|
|
||||||
} else if (nfs_get_fd(context) < 0) {
|
|
||||||
/* this happens when rpc_reconnect_requeue() is called
|
|
||||||
after the connection broke, but autoreconnect was
|
|
||||||
disabled - nfs_service() returns 0 */
|
|
||||||
|
|
||||||
auto e = NfsClientError(context, "NFS socket disappeared");
|
|
||||||
|
|
||||||
BroadcastError(std::make_exception_ptr(e));
|
|
||||||
|
|
||||||
|
if (nfs_get_fd(context) < 0)
|
||||||
|
/* this happens when rpc_reconnect_requeue()
|
||||||
|
is called after the connection broke, but
|
||||||
|
autoreconnect was disabled - nfs_service()
|
||||||
|
returns 0 */
|
||||||
|
throw NfsClientError(context, "NFS socket disappeared");
|
||||||
|
} catch (...) {
|
||||||
PrepareDestroyContext();
|
PrepareDestroyContext();
|
||||||
|
if (was_mounted)
|
||||||
|
BroadcastError(std::current_exception());
|
||||||
|
else
|
||||||
|
BroadcastMountError(std::current_exception());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(nfs_get_fd(context) >= 0);
|
assert(nfs_get_fd(context) >= 0);
|
||||||
|
|
||||||
|
if (!was_mounted && mount_state >= MountState::FINISHED)
|
||||||
|
BroadcastMountSuccess();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
assert(in_event);
|
assert(in_event);
|
||||||
in_event = false;
|
in_event = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user