Skip to content

Commit

Permalink
Closing connection when an ABORT message is received
Browse files Browse the repository at this point in the history
  • Loading branch information
darkl committed Sep 2, 2017
1 parent 062cfd1 commit 18d09f2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
18 changes: 18 additions & 0 deletions src/net45/WampSharp/Core/Client/WampServerProxyBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if CASTLE
using System;
using Castle.DynamicProxy;
using WampSharp.Core.Listener;
using WampSharp.Core.Message;
Expand Down Expand Up @@ -46,13 +47,30 @@ public TServer Create(TRawClient client, IWampConnection<TMessage> connection)

var proxyOptions = new ProxyGenerationOptions();

proxyOptions.AddMixinInstance(new DisposableForwarder(connection));

TServer result =
mProxyGenerator.CreateInterfaceProxyWithoutTarget<TServer>
(proxyOptions,
interceptor);

return result;
}

private class DisposableForwarder : IDisposable
{
private readonly IDisposable mDisposable;

public DisposableForwarder(IDisposable disposable)
{
mDisposable = disposable;
}

public void Dispose()
{
mDisposable.Dispose();
}
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void Welcome(long session, WelcomeDetails details)
public void Abort(AbortDetails details, string reason)
{
TrySetCloseEventArgs(SessionCloseType.Abort, details, reason);
mServerProxy.Dispose();
}

public void Goodbye(GoodbyeDetails details, string reason)
Expand All @@ -113,6 +114,10 @@ public void Goodbye(GoodbyeDetails details, string reason)
{
mServerProxy.Goodbye(new GoodbyeDetails(), WampErrors.GoodbyeAndOut);
}
else
{
mServerProxy.Dispose();
}

TrySetCloseEventArgs(SessionCloseType.Goodbye, details, reason);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace WampSharp.V2.Core.Contracts
using System;

namespace WampSharp.V2.Core.Contracts
{
/// <summary>
/// Represents a proxy to a WAMP2 router.
Expand All @@ -14,7 +16,8 @@ public interface IWampServerProxy<TMessage> :
IWampBrokerProxy<TMessage>,
IWampDealerProxy<TMessage>,
IWampSessionProxy,
IWampError<TMessage>
IWampError<TMessage>,
IDisposable
{
}
}
12 changes: 10 additions & 2 deletions src/net45/WampSharp/WAMP2/V2/PCL/ManualWampServerProxyBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if MANUAL_PROXY
using System;
using System.Collections.Generic;
using System.Reflection;
using WampSharp.Core.Client;
Expand Down Expand Up @@ -28,7 +29,7 @@ public IWampServerProxy Create(IWampClient<TMessage> client, IWampConnection<TMe
IWampOutgoingMessageHandler outgoingMessageHandler = mOutgoingHandlerBuilder.Build(client, connection);

WampServerProxy result =
new WampServerProxy(outgoingMessageHandler, mSerializer);
new WampServerProxy(outgoingMessageHandler, mSerializer, connection);

return result;
}
Expand Down Expand Up @@ -56,10 +57,12 @@ private class WampServerProxy : ProxyBase, IWampServerProxy
private static readonly MethodInfo mError4 = Method.Get((IWampServerProxy proxy) => proxy.Error(default(int), default(long), default(object), default(string)));
private static readonly MethodInfo mError5 = Method.Get((IWampServerProxy proxy) => proxy.Error(default(int), default(long), default(object), default(string), default(object[])));
private static readonly MethodInfo mError6 = Method.Get((IWampServerProxy proxy) => proxy.Error(default(int), default(long), default(object), default(string), default(object[]), default(object)));
private readonly IDisposable mDisposable;

public WampServerProxy(IWampOutgoingMessageHandler messageHandler, IWampOutgoingRequestSerializer requestSerializer)
public WampServerProxy(IWampOutgoingMessageHandler messageHandler, IWampOutgoingRequestSerializer requestSerializer, IDisposable disposable)
: base(messageHandler, requestSerializer)
{
mDisposable = disposable;
}

public void Publish(long requestId, PublishOptions options, string topicUri)
Expand Down Expand Up @@ -166,6 +169,11 @@ public void Error(int requestType, long requestId, object details, string error,
{
Send(mError6, requestType, requestId, details, error, arguments, argumentsKeywords);
}

public void Dispose()
{
mDisposable.Dispose();
}
}
}
}
Expand Down

0 comments on commit 18d09f2

Please sign in to comment.