Skip to content

Commit 3347342

Browse files
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).
1 parent 124c739 commit 3347342

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

src/swarm/neo/client/Connection.d

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,18 @@ public final class Connection: ConnectionBase
166166
167167
***************************************************************************/
168168

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

171-
private StartupNotifier startup_notifier = null;
171+
private Notifier startup_notifier = null;
172+
173+
/***************************************************************************
174+
175+
Callback for notification when the an error happened
176+
(`e` then reflects the error).
177+
178+
***************************************************************************/
179+
180+
private Notifier connection_error_notifier = null;
172181

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

227236
public this ( Const!(Credentials) credentials, IRequestSet request_set,
228-
EpollSelectDispatcher epoll )
237+
EpollSelectDispatcher epoll,
238+
Notifier connection_error_notifier )
229239
{
230240
this.client_socket = new ClientSocket;
231241

232242
super(this.client_socket.socket, epoll);
233243

234244
this.conn_init = new ClientConnect(credentials);
235245
this.request_set = request_set;
246+
this.connection_error_notifier = connection_error_notifier;
236247
}
237248

238249
/***************************************************************************
@@ -258,7 +269,7 @@ public final class Connection: ConnectionBase
258269
259270
***************************************************************************/
260271

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

301+
/***************************************************************************
302+
303+
Shuts the connection down if epoll reports an error event for the
304+
socket.
305+
306+
***************************************************************************/
307+
308+
override protected void error_ ( Exception exception, Event event )
309+
{
310+
super.error_(exception, event);
311+
connection_error_notifier(this, exception);
312+
}
313+
290314
/***************************************************************************
291315
292316
Shuts the engine down:

src/swarm/neo/client/ConnectionSet.d

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ public final class ConnectionSet : RequestOnConn.IConnectionGetter
118118
/// An error (indicated by the `e` field) occurred while connecting. The
119119
/// connection attempt will automatically be retried.
120120
NodeExceptionInfo error_while_connecting;
121+
122+
/// An error (indicated by the `e` field) occurred
123+
NodeExceptionInfo error;
121124
}
122125

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

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

573577
this.conn_notifier(info);
574578
}
579+
580+
/***************************************************************************
581+
582+
Connection error notification callback method. Calls the user notifier.
583+
584+
Params:
585+
connection = the connection giving the startup notification
586+
e = information about an error connecting; the
587+
connection will retry connecting in this case
588+
589+
***************************************************************************/
590+
591+
private void notifyConnectionError ( Connection connection,
592+
Exception e )
593+
{
594+
ConnNotification info;
595+
596+
info.error_while_connecting =
597+
NodeExceptionInfo(connection.remote_address, e);
598+
599+
this.conn_notifier(info);
600+
}
575601
}
576602

577603
/*******************************************************************************

0 commit comments

Comments
 (0)