コード例 #1
0
        public void Unsubscribe()
        {
            using (NetMQContext context = NetMQContext.Create())
            {
                using (NetMQBeacon speaker = new NetMQBeacon(context))
                {
                    speaker.Configure(9999);

                    using (NetMQBeacon listener = new NetMQBeacon(context))
                    {
                        listener.Configure(9999);
                        listener.Subscribe("H");

                        // this should send one broadcast message and stop
                        speaker.Publish("Hello");

                        string peerName;
                        string message = listener.ReceiveString(out peerName);

                        listener.Unsubscribe();

                        Assert.AreEqual("Hello", message);

                        ISocketPollable socket = listener;
                        socket.Socket.Options.ReceiveTimeout = TimeSpan.FromSeconds(2);

                        Assert.Throws <AgainException>(() =>
                        {
                            message = listener.ReceiveString(out peerName);
                        });
                    }
                }
            }
        }
コード例 #2
0
ファイル: NetMQMonitorTests.cs プロジェクト: ewin66/Pigeon
        public void Setup()
        {
            poller         = mockPoller.Object;
            sender         = mockSender.Object;
            receiver       = mockReceiver.Object;
            publisher      = mockPublisher.Object;
            subscriber     = mockSubscriber.Object;
            pollableSocket = mockPollableSocket.Object;

            mockSender
            .SetupGet(m => m.PollableSocket)
            .Returns(pollableSocket);

            mockReceiver
            .SetupGet(m => m.PollableSocket)
            .Returns(pollableSocket);

            mockPublisher
            .SetupGet(m => m.PollableSocket)
            .Returns(pollableSocket);

            mockSubscriber
            .SetupGet(m => m.PollableSocket)
            .Returns(pollableSocket);
        }
コード例 #3
0
        public void Remove(ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }
            if (socket.IsDisposed)
            {
                throw new ArgumentException("Must not be disposed.", nameof(socket));
            }
            CheckDisposed();

            Run(() =>
            {
                // Ensure the socket wasn't disposed while this code was waiting to be run on the poller thread
                if (socket.IsDisposed)
                {
                    throw new InvalidOperationException(
                        $"{nameof(NetMQPoller)}.{nameof(Remove)} was called from a non-poller thread, " +
                        "so ran asynchronously. " +
                        $"The {socket.GetType().Name} being removed was disposed while the remove " +
                        $"operation waited to start on the poller thread. Use {nameof(RemoveAndDispose)} " +
                        "instead, which will enqueue the remove and dispose to happen on the poller thread.");
                }

                socket.Socket.EventsChanged -= OnSocketEventsChanged;
                m_sockets.Remove(socket.Socket);
                m_isPollSetDirty = true;
            });
        }
コード例 #4
0
        public Task <bool> ContainsAsync([NotNull] ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }
            CheckDisposed();

            var tcs = new TaskCompletionSource <bool>();

            Run(() => tcs.SetResult(m_sockets.Contains(socket)));
            return(tcs.Task);
        }
コード例 #5
0
ファイル: NetMQPoller.cs プロジェクト: windygu/netmq
        /// <summary>
        /// </summary>
        public void Remove(ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }
            CheckDisposed();

            Run(() =>
            {
                socket.Socket.EventsChanged -= OnSocketEventsChanged;
                m_sockets.Remove(socket.Socket);
                m_isPollSetDirty = true;
            });
        }
コード例 #6
0
ファイル: Poller.cs プロジェクト: xzoth/netmq
        /// <summary>
        /// Delete the given socket from this Poller's list.
        /// </summary>
        /// <param name="socket">the ISocketPollable to remove from the list</param>
        /// <exception cref="ArgumentNullException">socket must not be null.</exception>
        /// <exception cref="ObjectDisposedException">This poller must not have already been disposed.</exception>
        public void RemoveSocket([NotNull] ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            if (m_disposed)
            {
                throw new ObjectDisposedException("Poller is disposed");
            }

            socket.Socket.EventsChanged -= OnSocketEventsChanged;

            m_sockets.Remove(socket.Socket);
            m_isDirty = true;
        }
コード例 #7
0
ファイル: NetMQPoller.cs プロジェクト: windygu/netmq
        /// <summary>
        /// </summary>
        public void Add(ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }
            CheckDisposed();

            Run(() =>
            {
                if (m_sockets.Contains(socket.Socket))
                {
                    return;
                }

                m_sockets.Add(socket.Socket);

                socket.Socket.EventsChanged += OnSocketEventsChanged;
                m_isPollSetDirty             = true;
            });
        }
コード例 #8
0
 /// <inheritdoc />
 public void Connect(ISocketPollable endpoint)
 {
     if (DispatchedSockets.Contains(endpoint) == false)
     {
         SyncLock.Wait();
         try
         {
             if (DispatchedSockets.Contains(endpoint) == false)
             {
                 DispatchedSockets.Add(endpoint);
                 if (PollingThread?.IsValueCreated == true)
                 {
                     PollingThread.Value.Add(endpoint);
                 }
             }
         }
         finally
         {
             SyncLock.Release();
         }
     }
 }
コード例 #9
0
ファイル: Poller.cs プロジェクト: xzoth/netmq
        /// <summary>
        /// Add the given socket to this Poller's list.
        /// </summary>
        /// <param name="socket">the ISocketPollable to add to the list</param>
        /// <exception cref="ArgumentNullException">socket must not be null.</exception>
        /// <exception cref="ArgumentException">socket must not have already been added to this poller.</exception>
        /// <exception cref="ObjectDisposedException">This poller must not have already been disposed.</exception>
        public void AddSocket([NotNull] ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            if (m_sockets.Contains(socket.Socket))
            {
                throw new ArgumentException("Socket already added to poller");
            }

            if (m_disposed)
            {
                throw new ObjectDisposedException("Poller is disposed");
            }

            m_sockets.Add(socket.Socket);

            socket.Socket.EventsChanged += OnSocketEventsChanged;

            m_isDirty = true;
        }
コード例 #10
0
        public void Add(ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }
            if (socket.IsDisposed)
            {
                throw new ArgumentException("Must not be disposed.", nameof(socket));
            }
            CheckDisposed();

            Run(() =>
            {
                // Ensure the socket wasn't disposed while this code was waiting to be run on the poller thread
                if (socket.IsDisposed)
                {
                    throw new InvalidOperationException(
                        $"{nameof(NetMQPoller)}.{nameof(Add)} was called from a non-poller thread, " +
                        "so ran asynchronously. " +
                        $"The {socket.GetType().Name} being added was disposed while the addition " +
                        "operation waited to start on the poller thread. You must remove a socket " +
                        "before disposing it, or dispose the poller first.");
                }

                if (m_sockets.Contains(socket.Socket))
                {
                    return;
                }

                m_sockets.Add(socket.Socket);

                socket.Socket.EventsChanged += OnSocketEventsChanged;
                m_isPollSetDirty             = true;
            });
        }
コード例 #11
0
 private void CreatePoller(ISocketPollable socket)
 {
     _poller = new NetMQPoller {
         socket
     };
 }
コード例 #12
0
ファイル: Poller.cs プロジェクト: awb99/netmq
        /// <summary>
        /// Delete the given socket from this Poller's list.
        /// </summary>
        /// <param name="socket">the ISocketPollable to remove from the list</param>
        /// <exception cref="ArgumentNullException">socket must not be null.</exception>
        /// <exception cref="ObjectDisposedException">This poller must not have already been disposed.</exception>
        public void RemoveSocket( ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            if (m_disposed)
            {
                throw new ObjectDisposedException("Poller is disposed");
            }

            socket.Socket.EventsChanged -= OnSocketEventsChanged;

            m_sockets.Remove(socket.Socket);
            m_isDirty = true;
        }
コード例 #13
0
ファイル: Poller.cs プロジェクト: sharpe5/netmq
        // NOTE this interface provides an abstraction over the legacy Poller and newer NetMQPoller classes for use in NetMQMonitor

        void ISocketPollableCollection.Add(ISocketPollable socket)
        {
            AddSocket(socket);
        }
コード例 #14
0
ファイル: Poller.cs プロジェクト: sharpe5/netmq
 void ISocketPollableCollection.Remove(ISocketPollable socket)
 {
     RemoveSocket(socket);
 }
コード例 #15
0
ファイル: NetMQPoller.cs プロジェクト: awb99/netmq
        public void Remove(ISocketPollable socket)
        {
            if (socket == null)
                throw new ArgumentNullException("socket");
            CheckDisposed();

            Run(() =>
            {
                socket.Socket.EventsChanged -= OnSocketEventsChanged;
                m_sockets.Remove(socket.Socket);
                m_isPollSetDirty = true;
            });
        }
コード例 #16
0
ファイル: Poller.cs プロジェクト: awb99/netmq
        /// <summary>
        /// Add the given socket to this Poller's list.
        /// </summary>
        /// <param name="socket">the ISocketPollable to add to the list</param>
        /// <exception cref="ArgumentNullException">socket must not be null.</exception>
        /// <exception cref="ArgumentException">socket must not have already been added to this poller.</exception>
        /// <exception cref="ObjectDisposedException">This poller must not have already been disposed.</exception>
        public void AddSocket( ISocketPollable socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            if (m_sockets.Contains(socket.Socket))
            {
                throw new ArgumentException("Socket already added to poller");
            }

            if (m_disposed)
            {
                throw new ObjectDisposedException("Poller is disposed");
            }

            m_sockets.Add(socket.Socket);

            socket.Socket.EventsChanged += OnSocketEventsChanged;

            m_isDirty = true;
        }
コード例 #17
0
ファイル: Poller.cs プロジェクト: sharpe5/netmq
 void INetMQPoller.Add(ISocketPollable socket)
 {
     AddSocket(socket);
 }
コード例 #18
0
ファイル: Poller.cs プロジェクト: SPERONIS/Communication_Mono
 void INetMQPoller.Add(ISocketPollable socket)
 {
     AddSocket(socket);
 }
コード例 #19
0
ファイル: Poller.cs プロジェクト: SPERONIS/Communication_Mono
 void ISocketPollableCollection.Remove(ISocketPollable socket)
 {
     RemoveSocket(socket);
 }
コード例 #20
0
ファイル: Poller.cs プロジェクト: SPERONIS/Communication_Mono
        // NOTE this interface provides an abstraction over the legacy Poller and newer NetMQPoller classes for use in NetMQMonitor

        void ISocketPollableCollection.Add(ISocketPollable socket)
        {
            AddSocket(socket);
        }
コード例 #21
0
ファイル: NetMQPoller.cs プロジェクト: awb99/netmq
        public void Add(ISocketPollable socket)
        {
            if (socket == null)
                throw new ArgumentNullException("socket");
            CheckDisposed();

            Run(() =>
            {
                if (m_sockets.Contains(socket.Socket))
                    return;

                m_sockets.Add(socket.Socket);

                socket.Socket.EventsChanged += OnSocketEventsChanged;
                m_isPollSetDirty = true;
            });
        }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of <see cref="NetMQConnection"/>
 /// </summary>
 /// <param name="pollableSocket">Inner socket connection that is monitored by <see cref="INetMQPoller"/></param>
 /// <param name="messageFactory">Factory for creating <see cref="NetMQMessage"/>s</param>
 public NetMQConnection(ISocketPollable pollableSocket, INetMQMessageFactory messageFactory)
 {
     this.PollableSocket = pollableSocket ?? throw new ArgumentNullException(nameof(pollableSocket));
     this.messageFactory = messageFactory ?? throw new ArgumentNullException(nameof(messageFactory));
 }