Skip to content

Commit

Permalink
msg/async: implement ECONNREFUSED detection
Browse files Browse the repository at this point in the history
This commit adds code that detects ECONNREFUSED and dispatches appropriate
event further in Async messenger.

Signed-off-by: Piotr Dałek <git@predictor.org.pl>
  • Loading branch information
branch-predictor committed May 22, 2016
1 parent 70ddd0e commit 470cf9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/msg/async/AsyncConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ class C_handle_remote_reset : public EventCallback {
}
};

class C_handle_connection_refused : public EventCallback {
AsyncMessenger *msgr;
AsyncConnectionRef conn;

public:
C_handle_connection_refused(AsyncMessenger *m, AsyncConnectionRef c): msgr(m), conn(c) {}
void do_request(int id) {
msgr->ms_deliver_handle_refused(conn.get());
}
};

class C_handle_dispatch : public EventCallback {
AsyncMessenger *msgr;
Message *m;
Expand Down Expand Up @@ -189,6 +200,7 @@ AsyncConnection::AsyncConnection(CephContext *cct, AsyncMessenger *m, EventCente
reset_handler = new C_handle_reset(async_msgr, this);
remote_reset_handler = new C_handle_remote_reset(async_msgr, this);
connect_handler = new C_deliver_connect(async_msgr, this);
connection_refused_handler = new C_handle_connection_refused(async_msgr, this);
local_deliver_handler = new C_local_deliver(this);
wakeup_handler = new C_time_wakeup(this);
memset(msgvec, 0, sizeof(msgvec));
Expand Down Expand Up @@ -1074,6 +1086,10 @@ ssize_t AsyncConnection::_process_connection()
r = net.reconnect(get_peer_addr(), sd);
if (r < 0) {
ldout(async_msgr->cct, 1) << __func__ << " reconnect failed " << dendl;
if (r == -ECONNREFUSED) {
ldout(async_msgr->cct, 2) << __func__ << " connection refused!" << dendl;
center->dispatch_event_external(connection_refused_handler);
}
goto fail;
} else if (r > 0) {
break;
Expand Down
2 changes: 2 additions & 0 deletions src/msg/async/AsyncConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ class AsyncConnection : public Connection {
EventCallbackRef write_handler;
EventCallbackRef reset_handler;
EventCallbackRef remote_reset_handler;
EventCallbackRef connection_refused_handler;
EventCallbackRef connect_handler;
EventCallbackRef local_deliver_handler;
EventCallbackRef wakeup_handler;
Expand Down Expand Up @@ -375,6 +376,7 @@ class AsyncConnection : public Connection {
delete write_handler;
delete reset_handler;
delete remote_reset_handler;
delete connection_refused_handler;
delete connect_handler;
delete local_deliver_handler;
delete wakeup_handler;
Expand Down

0 comments on commit 470cf9c

Please sign in to comment.