示例#1
0
文件: XPub.cs 项目: EugenDueck/netmq
        static XPub()
        {
            s_markAsMatching = (pipe, data, arg) =>
            {
                XPub self = (XPub)arg;
                self.m_dist.Match(pipe);
            };

            s_SendUnsubscription = (pipe, data, arg) =>
            {

                XPub self = (XPub)arg;

                if (self.m_options.SocketType != ZmqSocketType.Pub)
                {

                    //  Place the unsubscription to the queue of pending (un)sunscriptions
                    //  to be retrived by the user later on.
                    Blob unsub = new Blob(data.Length + 1);
                    unsub.Put(0, (byte)0);
                    unsub.Put(1, data);
                    self.m_pending.Enqueue(unsub);

                }
            };
        }
示例#2
0
文件: Stream.cs 项目: hecwow/netmq
        private void IdentifyPeer(Pipe pipe)
        {
            Blob identity;

              // Always assign identity for raw-socket
              byte[] buf = new byte[5];
              buf[0] = 0;

              byte[] result = BitConverter.GetBytes(m_nextPeerId++);

              Buffer.BlockCopy(result, 0, buf, 1, 4);
              identity = new Blob(buf);
              m_options.Identity = buf;
              m_options.IdentitySize = (byte)buf.Length;

              pipe.Identity = identity;
              //  Add the record into output pipes lookup table
              Outpipe outpipe = new Outpipe(pipe, true);
              m_outpipes.Add(identity, outpipe);
        }
示例#3
0
        private bool IdentifyPeer(Pipe pipe)
        {
            Blob identity;

            if (m_options.RawSocket)
            {
                byte[] buf = new byte[5];
                buf[0] = 0;
                byte[] result = BitConverter.GetBytes(m_nextPeerId++);
                Buffer.BlockCopy(result, 0, buf, 1, 4);
                identity = new Blob(buf);
            }
            else
            {
                Msg msg = pipe.Read();
                if (msg == null)
                    return false;

                if (msg.Size == 0)
                {
                    //  Fall back on the auto-generation
                    byte[] buf = new byte[5];

                    buf[0] = 0;

                    byte[] result = BitConverter.GetBytes(m_nextPeerId++);

                    Buffer.BlockCopy(result, 0, buf, 1, 4);
                    identity = new Blob(buf);
                }
                else
                {
                    identity = new Blob(msg.Data);

                    //  Ignore peers with duplicate ID.
                    if (m_outpipes.ContainsKey(identity))
                        return false;
                }
            }

            pipe.Identity = identity;
            //  Add the record into output pipes lookup table
            Outpipe outpipe = new Outpipe(pipe, true);
            m_outpipes.Add(identity, outpipe);

            return true;
        }
示例#4
0
文件: Stream.cs 项目: hecwow/netmq
        protected override bool XSend(Msg msg, SendReceiveOptions flags)
        {
            //  If this is the first part of the message it's the ID of the
              //  peer to send the message to.
              if (!m_moreOut)
              {
            Debug.Assert(m_currentOut == null);

            //  If we have malformed message (prefix with no subsequent message)
            //  then just silently ignore it.
            //  TODO: The connections should be killed instead.
            if (msg.HasMore)
            {
              //  Find the pipe associated with the identity stored in the prefix.
              //  If there's no such pipe just silently ignore the message, unless
              //  mandatory is set.
              Blob identity = new Blob(msg.Data);
              Outpipe op;

              if (m_outpipes.TryGetValue(identity, out op))
              {
            m_currentOut = op.Pipe;
            if (!m_currentOut.CheckWrite())
            {
              op.Active = false;
              m_currentOut = null;
              return false;
            }
              }
              else
              {
            throw NetMQException.Create(ErrorCode.EHOSTUNREACH);
              }
            }

            m_moreOut = true;

            return true;
              }

              //  Ignore the MORE flag
              msg.ResetFlags(MsgFlags.More);

              //  This is the last part of the message.
              m_moreOut = false;

              //  Push the message into the pipe. If there's no out pipe, just drop it.
              if (m_currentOut != null)
              {
            if (msg.Size == 0)
            {
              m_currentOut.Terminate(false);
              m_currentOut = null;
              return true;
            }

            bool ok = m_currentOut.Write(msg);
            if (ok)
            {
              m_currentOut.Flush();
            }

            m_currentOut = null;
              }
              else
              {
              }

              //  Detach the message from the data buffer.

              return true;
        }
示例#5
0
        protected override bool XSend(Msg msg, SendRecieveOptions flags)
        {
            //  If this is the first part of the message it's the ID of the
            //  peer to send the message to.
            if (!m_moreOut) {
                Debug.Assert(m_currentOut == null);

                //  If we have malformed message (prefix with no subsequent message)
                //  then just silently ignore it.
                //  TODO: The connections should be killed instead.
                if (msg.HasMore) {

                    m_moreOut = true;

                    //  Find the pipe associated with the identity stored in the prefix.
                    //  If there's no such pipe just silently ignore the message, unless
                    //  mandatory is set.
                    Blob identity = new Blob(msg.Data);
                    Outpipe op;

                    if (m_outpipes.TryGetValue(identity, out op)) {
                        m_currentOut = op.Pipe;
                        if (!m_currentOut.CheckWrite ()) {
                            op.Active = false;
                            m_currentOut = null;
                            if (m_mandatory)
                            {
                                m_moreOut = false;
                                ZError.ErrorNumber = ErrorNumber.EAGAIN;
                                return false;
                            }
                        }
                    } else if (m_mandatory) {
                        m_moreOut = false;
                        ZError.ErrorNumber = (ErrorNumber.EHOSTUNREACH);
                        return false;
                    }
                }

                return true;
            }

            //  Check whether this is the last part of the message.
            m_moreOut = msg.HasMore;

            //  Push the message into the pipe. If there's no out pipe, just drop it.
            if (m_currentOut != null) {
                bool ok = m_currentOut.Write (msg);
                if (!ok)
                    m_currentOut = null;
                else if (!m_moreOut) {
                    m_currentOut.Flush ();
                    m_currentOut = null;
                }
            }
            else {
            }

            //  Detach the message from the data buffer.

            return true;
        }