Esempio n. 1
0
        private void recvProc()
        {
            ZMQ.Socket reqs = CTX.Socket(ZMQ.SocketType.PULL);
            reqs.Connect(sub_addr);

            var items = new[] { reqs.CreatePollItem(ZMQ.IOMultiPlex.POLLIN | ZMQ.IOMultiPlex.POLLERR) };

            while (isRunning)
            {
                int res = CTX.Poll(items, 1000 * 1000);
                if (res == 0)
                {
                    continue;
                }
                foreach (byte[] data in reqs.RecvAll(ZMQ.SendRecvOpt.NOBLOCK))
                {
                    if (data == null)
                    {
                        continue;
                    }
                    recvQ.Enqueue(data);
                    itemsReadyToRecv.Set();
                }
            }

            reqs.Dispose();
            itemsReadyToRecv.Close();
            Interlocked.Decrement(ref threadStillRunning);
        }
        public void StopNIDSEvent()
        {
            if (_event != null)
            {
                _event.Set();
            }

            if (_thread == null)
            {
                return;
            }

            if (_thread.Join(3000))
            {
                _thread.Abort();
                _thread = null;
            }

            //将ZMQ的内容,销毁
            foreach (var tag in EventTags)
            {
                _subscriber.Unsubscribe(tag, MsgEncoding);
            }
            _subscriber.Dispose();
            _context.Dispose();
        }
Esempio n. 3
0
 public void Dispose()
 {
     if (_zmqSocket != null)
     {
         _zmqSocket.Dispose();
     }
 }
Esempio n. 4
0
 public void Close()
 {
     if (null != messageProducer)
     {
         messageProducer.Dispose();
         messageProducer = null;
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Clean up
 /// </summary>
 public void Close()
 {
     StopAsyncDelivery();
     if (null != messageSubscriber)
     {
         messageSubscriber.Dispose();
         messageSubscriber = null;
     }
 }
Esempio n. 6
0
        private void sendProc()
        {
            ZMQ.Socket resp = CTX.Socket(ZMQ.SocketType.PUB);
            if (!string.IsNullOrEmpty(SenderId))
            {
                resp.Identity = Encoding.ASCII.GetBytes(SenderId);
            }
            resp.Connect(pub_addr);

            while (isRunning)
            {
                itemsReadyToSend.WaitOne();
                lock (sendQ)
                {
                    while (sendQ.Count != 0)
                    {
                        byte[] stuffToSend = sendQ.Dequeue();

                        bool sentOk = false;
                        while (!sentOk)
                        {
                            try
                            {
                                resp.Send(stuffToSend);
                                sentOk = true;
                            }
                            catch (ZMQ.Exception ex)
                            {
                                if (ex.Errno == (int)ZMQ.ERRNOS.EAGAIN)
                                {
                                    sentOk = false;
                                }
                                else
                                {
                                    throw ex;
                                }
                            }
                        }
                    }
                }
            }

            resp.Dispose();
            itemsReadyToSend.Close();
            Interlocked.Decrement(ref threadStillRunning);
        }