Permalink
Browse files

Added server side reconnected event.

  • Loading branch information...
1 parent f97c06e commit 1af47aea142fbf49174747bff7e8a1f76c4dda30 @davidfowl davidfowl committed Feb 2, 2012
@@ -90,6 +90,11 @@ public virtual Task ProcessRequestAsync(HostContext context)
return OnConnectedAsync(context.Request, connectionId);
};
+ _transport.Reconnected = () =>
+ {
+ return OnReconnectedAsync(context.Request, connectionId);
+ };
+
_transport.Received = data =>
{
return OnReceivedAsync(connectionId, data);
@@ -139,6 +144,11 @@ protected virtual Task OnConnectedAsync(IRequest request, string connectionId)
return TaskAsyncHelper.Empty;
}
+ private Task OnReconnectedAsync(IRequest request, string connectionId)
+ {
+ return TaskAsyncHelper.Empty;
+ }
+
protected virtual Task OnReceivedAsync(string connectionId, string data)
{
OnReceiving();
@@ -67,6 +67,8 @@ protected virtual void OnSending(string payload)
public Func<string, Task> Received { get; set; }
public Func<Task> Connected { get; set; }
+
+ public Func<Task> Reconnected { get; set; }
public override Func<Task> Disconnected { get; set; }
@@ -82,9 +84,19 @@ public Task ProcessRequest(IReceivingConnection connection)
}
else
{
- if (IsConnectRequest && Connected != null)
+ if (IsConnectRequest)
{
- return Connected().Then(() => ProcessReceiveRequest(connection)).FastUnwrap();
+ if (Connected != null)
+ {
+ return Connected().Then(() => ProcessReceiveRequest(connection)).FastUnwrap();
+ }
+
+ return ProcessReceiveRequest(connection);
+ }
+
+ if (Reconnected != null)
+ {
+ return Reconnected().Then(() => ProcessReceiveRequest(connection)).FastUnwrap();
}
return ProcessReceiveRequest(connection);
@@ -8,6 +8,7 @@ public interface ITransport
{
Func<string, Task> Received { get; set; }
Func<Task> Connected { get; set; }
+ Func<Task> Reconnected { get; set; }
Func<Task> Disconnected { get; set; }
Func<Exception, Task> Error { get; set; }
string ConnectionId { get; }
@@ -92,6 +92,8 @@ private bool IsSendRequest
public Func<Task> Connected { get; set; }
+ public Func<Task> Reconnected { get; set; }
+
public override Func<Task> Disconnected { get; set; }
public Func<Exception, Task> Error { get; set; }
@@ -112,6 +114,11 @@ public Task ProcessRequest(IReceivingConnection connection)
}
else if (MessageId != null)
{
+ if (Reconnected != null)
+ {
+ return Reconnected().Then(() => ProcessReceiveRequest(connection)).FastUnwrap();
+ }
+
return ProcessReceiveRequest(connection);
}
}

0 comments on commit 1af47ae

Please sign in to comment.