mhowlett / NNanomsg

.NET binding for nanomsg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SubscribeSocket.Unsubscribe does not work

Sergey-Terekhin opened this issue · comments

I've tried to implement client which can subscribe and unsubscribe different topics.
Subscription works well, but client can not unsubscribe (Unsubscribe method does not work).
The source of SubscribeSocket from decompiler is below and it is seems that SocketOption flag is set to the wrong value (probably should be SocketOption.SUB_UNSUBSCRIBE) - and the same bug is present in the source code (see https://github.com/mhowlett/NNanomsg/blob/master/NNanomsg/Protocols/SubscribeSocket.cs)

public class SubscribeSocket : NanomsgSocketBase, IConnectSocket, IReceiveSocket
  {
    public SubscribeSocket()
      : base(Domain.SP, Protocol.SUB)
    {
    }

    public void Subscribe(string topic)
    {
      NanomsgSocketOptions.SetString(this.SocketID, SocketOptionLevel.Subscribe, SocketOption.LINGER, topic);
    }

    public void Subscribe(byte[] topic)
    {
      NanomsgSocketOptions.SetBytes(this.SocketID, SocketOptionLevel.Subscribe, SocketOption.LINGER, topic);
    }

    public void Unsubscribe(string topic)
    {
      NanomsgSocketOptions.SetString(this.SocketID, SocketOptionLevel.Subscribe, SocketOption.LINGER, topic);
    }

    public void Unsubscribe(byte[] topic)
    {
      NanomsgSocketOptions.SetBytes(this.SocketID, SocketOptionLevel.Subscribe, SocketOption.LINGER, topic);
    }

    public NanomsgEndpoint Connect(string address)
    {
      return this.ConnectImpl(address);
    }

    public NanomsgEndpoint Connect(IPAddress address, int port)
    {
      return this.ConnectImpl(address, port);
    }

    public byte[] Receive()
    {
      return this.ReceiveImpl();
    }

    public byte[] ReceiveImmediate()
    {
      return this.ReceiveImmediateImpl();
    }

    public NanomsgReadStream ReceiveStream()
    {
      return this.ReceiveStreamImpl();
    }

    public NanomsgReadStream ReceiveStreamImmediate()
    {
      return this.ReceiveStreamImmediateImpl();
    }
  }