CreatePairSocket() private method

private CreatePairSocket ( ) : PairSocket
return PairSocket
コード例 #1
0
        /// <summary>
        /// Create new NetMQQueue.
        /// </summary>
        /// <param name="context">NetMQContext must be provided to the queue</param>
        /// <param name="capacity">The capacity of the queue, use zero for unlimited</param>
        public NetMQQueue(NetMQContext context, int capacity = 0)
        {
            m_context = context;
            m_queue   = new ConcurrentQueue <T>();
            m_writer  = m_context.CreatePairSocket();
            m_reader  = m_context.CreatePairSocket();

            if (capacity != 0)
            {
                m_writer.Options.SendHighWatermark = m_reader.Options.ReceiveHighWatermark = capacity / 2;
            }
            else
            {
                m_writer.Options.SendHighWatermark = m_reader.Options.ReceiveHighWatermark = 0;
            }

            m_eventDelegator = new EventDelegator <NetMQQueueEventArgs <T> >(() =>
            {
                m_reader.ReceiveReady += OnReceiveReady;
            }, () =>
            {
                m_reader.ReceiveReady -= OnReceiveReady;
            });

            string address = string.Format("inproc://NetMQQueue#{0}", Interlocked.Increment(ref s_sequence));

            m_reader.Bind(address);
            m_writer.Connect(address);

            m_dequeueMsg = new Msg();
            m_dequeueMsg.InitEmpty();
        }
コード例 #2
0
        private NetMQActor([NotNull] NetMQContext context, [NotNull] IShimHandler shimHandler)
        {
            m_shimHandler = shimHandler;

            m_self = context.CreatePairSocket();
            m_shim = context.CreatePairSocket();

            EventHandler <NetMQSocketEventArgs> onReceive = (sender, e) =>
                                                            m_receiveEvent.Fire(this, new NetMQActorEventArgs(this));

            EventHandler <NetMQSocketEventArgs> onSend = (sender, e) =>
                                                         m_sendEvent.Fire(this, new NetMQActorEventArgs(this));

            m_receiveEvent = new EventDelegator <NetMQActorEventArgs>(
                () => m_self.ReceiveReady += onReceive,
                () => m_self.ReceiveReady -= onReceive);

            m_sendEvent = new EventDelegator <NetMQActorEventArgs>(
                () => m_self.SendReady += onSend,
                () => m_self.SendReady -= onSend);

            var random = new Random();

            //now binding and connect pipe ends
            string endPoint;

            while (true)
            {
                try
                {
                    endPoint = string.Format("inproc://NetMQActor-{0}-{1}", random.Next(0, 10000), random.Next(0, 10000));
                    m_self.Bind(endPoint);
                    break;
                }
                catch (AddressAlreadyInUseException)
                {
                    // In case address already in use we continue searching for an address
                }
            }

            m_shim.Connect(endPoint);

            m_shimThread = new Thread(RunShim);
            m_shimThread.Start();

            // Mandatory handshake for new actor so that constructor returns only
            // when actor has also initialised. This eliminates timing issues at
            // application start up.
            m_self.ReceiveSignal();
        }
コード例 #3
0
ファイル: Actor.cs プロジェクト: huoxudong125/ZeroMqDemos
        public Actor(NetMQContext context, IShimHandler shimHandler, object[] args)
        {
            this.self = context.CreatePairSocket();
            this.shim = new Shim(shimHandler, context.CreatePairSocket());
            this.self.Options.SendHighWatermark = 1000;
            this.self.Options.SendHighWatermark = 1000;

            //now binding and connect pipe ends
            string endPoint = string.Empty;
            while (true)
            {
                Action bindAction = () =>
                {
                    endPoint = GetEndPointName();
                    self.Bind(endPoint);
                };

                try
                {
                    bindAction();
                    break;
                }
                catch (NetMQException nex)
                {
                    if (nex.ErrorCode == ErrorCode.EFAULT)
                    {
                        bindAction();
                    }
                }

            }

            shim.Pipe.Connect(endPoint);

            //Create Shim thread handler
            CreateShimThread(args);
        }
コード例 #4
0
ファイル: NetMQActor.cs プロジェクト: newstrading/netmq
 public static NetMQActor Create(NetMQContext context, ShimAction action)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), new ActionShimHandler(action)));
 }
コード例 #5
0
ファイル: NetMQActor.cs プロジェクト: newstrading/netmq
 public static NetMQActor Create <T>(NetMQContext context, ShimAction <T> action, T state)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), new ActionShimHandler <T>(action, state)));
 }
コード例 #6
0
ファイル: NetMQActor.cs プロジェクト: newstrading/netmq
 public static NetMQActor Create(NetMQContext context, IShimHandler shimHandler)
 {
     return(new NetMQActor(context.CreatePairSocket(), context.CreatePairSocket(), shimHandler));
 }