Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new connection error notifier and error field to union #392

Open
wants to merge 1 commit into
base: v6.x.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add new connection error notifier and error field to union
The user provided connection notifier was called on startup only in case
of an successfully established connection or if an error happened while
connecting. This patch adds a new (internal) client connection error
notifier that is called from the ISelectClient `error` method, in that
case the client Connection class. That happens when the ISelectClient is
unregistered from epoll due to a exception thrown in the RequestOnConn
fiber.

The exception is passed to the user by utilizing a new error field in
the ConnNotificationUnion (defined in the ConnectionSet).
matthias-wende-sociomantic committed Apr 24, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit fdecb3a19dd0ecdc42eace604bd9b2f51a92b2ac
32 changes: 28 additions & 4 deletions src/swarm/neo/client/Connection.d
Original file line number Diff line number Diff line change
@@ -166,9 +166,18 @@ public final class Connection: ConnectionBase

***************************************************************************/

public alias void delegate ( Connection connection, Exception e = null ) StartupNotifier;
public alias void delegate ( Connection connection, Exception e = null ) Notifier;

private StartupNotifier startup_notifier = null;
private Notifier startup_notifier = null;

/***************************************************************************

Callback for notification when the an error happened
(`e` then reflects the error).

***************************************************************************/

private Notifier connection_error_notifier = null;

/***************************************************************************

@@ -225,14 +234,16 @@ public final class Connection: ConnectionBase
***************************************************************************/

public this ( Const!(Credentials) credentials, IRequestSet request_set,
EpollSelectDispatcher epoll )
EpollSelectDispatcher epoll,
Notifier connection_error_notifier )
{
this.client_socket = new ClientSocket;

super(this.client_socket.socket, epoll);

this.conn_init = new ClientConnect(credentials);
this.request_set = request_set;
this.connection_error_notifier = connection_error_notifier;
}

/***************************************************************************
@@ -258,7 +269,7 @@ public final class Connection: ConnectionBase

***************************************************************************/

public Status start ( AddrPort node_address, StartupNotifier startup_notifier )
public Status start ( AddrPort node_address, Notifier startup_notifier )
{
debug ( SwarmConn )
{
@@ -287,6 +298,19 @@ public final class Connection: ConnectionBase
return this.status_;
}

/***************************************************************************

Shuts the connection down if epoll reports an error event for the
socket.

***************************************************************************/

override protected void error_ ( Exception exception, Event event )
{
super.error_(exception, event);
connection_error_notifier(this, exception);
}

/***************************************************************************

Shuts the engine down:
28 changes: 27 additions & 1 deletion src/swarm/neo/client/ConnectionSet.d
Original file line number Diff line number Diff line change
@@ -118,6 +118,9 @@ public final class ConnectionSet : RequestOnConn.IConnectionGetter
/// An error (indicated by the `e` field) occurred while connecting. The
/// connection attempt will automatically be retried.
NodeExceptionInfo error_while_connecting;

/// An error (indicated by the `e` field) occurred
NodeExceptionInfo error;
}

/***************************************************************************
@@ -287,7 +290,8 @@ public final class ConnectionSet : RequestOnConn.IConnectionGetter
bool added;
auto connection = this.connections.put(node_address, added,
this.connection_pool.get(new Connection(
this.credentials, this.request_set_, this.epoll
this.credentials, this.request_set_, this.epoll,
&this.notifyConnectionError
))
);

@@ -572,6 +576,28 @@ public final class ConnectionSet : RequestOnConn.IConnectionGetter

this.conn_notifier(info);
}

/***************************************************************************

Connection error notification callback method. Calls the user notifier.

Params:
connection = the connection giving the startup notification
e = information about an error connecting; the
connection will retry connecting in this case

***************************************************************************/

private void notifyConnectionError ( Connection connection,
Exception e )
{
ConnNotification info;

info.error_while_connecting =
NodeExceptionInfo(connection.remote_address, e);

this.conn_notifier(info);
}
}

/*******************************************************************************