InitGC() public method

Initialise this Msg to be of MsgType.GC with the given data-buffer value.
public InitGC ( [ data, int size ) : void
data [ the byte-array of data to assign to the Msg's Data property
size int the number of bytes that are in the data byte-array
return void
コード例 #1
0
 public void Heartbeat()
 {
     if (DateTime.Now - _lastHeart > TimeSpan.FromMilliseconds(100))
     {
         NetMQ.Msg msg = new NetMQ.Msg();
         msg.InitGC(new byte[] { 2 }, 1);
         _socket.TrySend(ref msg, TimeSpan.FromMilliseconds(100), false);
         _lastHeart = DateTime.Now;
     }
 }
コード例 #2
0
        public void Register()
        {
            NetMQ.Msg msg = new NetMQ.Msg();
            msg.InitGC(new byte[] { 1 }, 1);
            _socket.TrySend(ref msg, TimeSpan.FromMilliseconds(100), false);
            _state = MachineState.Registered;
#if DEBUG
            //GetProgramData();
#endif
        }
コード例 #3
0
ファイル: NetMQQueue.cs プロジェクト: r618/netmq
        /// <summary>
        /// Enqueue an item to the queue, will block if the queue is full.
        /// </summary>
        /// <param name="value"></param>
        public void Enqueue(T value)
        {
            m_queue.Enqueue(value);

            var msg = new Msg();

            msg.InitGC(EmptyArray <byte> .Instance, 0);

            lock (m_writer)
                m_writer.TrySend(ref msg, SendReceiveConstants.InfiniteTimeout, false);

            msg.Close();
        }
コード例 #4
0
        /// <summary>
        /// Enqueue an item to the queue, will block if the queue is full.
        /// </summary>
        /// <param name="value"></param>
        public void Enqueue(T value)
        {
            m_queue.Enqueue(value);

            Msg msg = new Msg();

            msg.InitGC(s_empty, 0);

            lock (m_writer)
            {
                m_writer.TrySend(ref msg, SendReceiveConstants.InfiniteTimeout, false);
            }
            msg.Close();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: GrabCAD/netmq
        private static void Main()
        {
            const int messageCount = 1000000;
            const int dealerCount = 100;

            Console.WriteLine("Sending {0} messages to {1} dealers", messageCount, dealerCount);

            //BufferPool.SetBufferManagerBufferPool(1024 * 1024 * 10, 1024);

            using (var router = new RouterSocket())
            {
                router.Options.SendHighWatermark = 0;
                router.Bind("tcp://*:5555");

                var dealers = new List<DealerSocket>();
                var identities = new List<Msg>();
                var random = new Random();
                var identity = new byte[50];

                for (var i = 0; i < dealerCount; i++)
                {
                    random.NextBytes(identity);
                    var dealer = new DealerSocket
                    {
                        Options =
                        {
                            Identity = identity.Skip(10).ToArray(),
                            ReceiveHighWatermark = 0
                        }
                    };

                    dealer.Connect("tcp://localhost:5555");

                    dealers.Add(dealer);
                    var msg = new Msg();
                    msg.InitGC(identity, 10, identity.Length); // test offsets
                    identities.Add(msg);
                }

                Thread.Sleep(500);

                while (!Console.KeyAvailable)
                {
                    Thread.Sleep(500);

                    var stopwatch = Stopwatch.StartNew();

                    for (var i = 0; i < messageCount; i++)
                    {
                        var msg = identities[i%identities.Count];
                        router.Send(ref msg, true);
                        var msg2 = new Msg();
                        msg2.InitPool(1);
                        msg2.Put((byte) 'E');
                        router.Send(ref msg2, false);
                    }

                    stopwatch.Stop();

                    Console.WriteLine("{0:N1} messages sent per second", messageCount/stopwatch.Elapsed.TotalSeconds);
                }

                foreach (var dealerSocket in dealers)
                    dealerSocket.Dispose();
            }
        }