protected override void XReadActivated(Pipe pipe) { // There are some subscriptions waiting. Let's process them. Msg sub; while ((sub = pipe.Read()) != null) { // Apply the subscription to the trie. byte[] data = sub.Data; int size = sub.Size; if (size > 0 && (data[0] == 0 || data[0] == 1)) { bool unique; if (data[0] == 0) { unique = m_subscriptions.Remove(data, 1, pipe); } else { unique = m_subscriptions.Add(data, 1, pipe); } // If the subscription is not a duplicate, store it so that it can be // passed to used on next recv call. if (m_options.SocketType == ZmqSocketType.Xpub && (unique || m_verbose)) { m_pending.Enqueue(new Blob(sub.Data)); } } } }
protected bool XRecv(SendReceiveOptions flags, out Msg msg) { // Deallocate old content of the message. msg = null; if (m_pipe == null || (msg = m_pipe.Read()) == null) { return(false); } return(true); }
override protected bool XRecv(SendReceiveOptions flags, ref Msg msg) { // Deallocate old content of the message. msg.Close(); if (m_pipe == null || !m_pipe.Read(ref msg)) { msg.InitEmpty(); return(false); } return(true); }
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); }
public virtual bool PullMsg(ref Msg msg) { // First message to send is identity if (!m_identitySent) { msg.InitPool(m_options.IdentitySize); msg.Put(m_options.Identity, 0, m_options.IdentitySize); m_identitySent = true; m_incompleteIn = false; return(true); } if (m_pipe == null || !m_pipe.Read(ref msg)) { return(false); } m_incompleteIn = msg.HasMore; return(true); }
public virtual Msg PullMsg() { Msg msg; // First message to send is identity if (!m_identitySent) { msg = new Msg(m_options.IdentitySize); msg.Put(m_options.Identity, 0, m_options.IdentitySize); m_identitySent = true; m_incompleteIn = false; return(msg); } if (m_pipe == null || (msg = m_pipe.Read()) == null) { return(null); } m_incompleteIn = msg.HasMore; return(msg); }
protected override void XReadActivated(Pipe pipe) { // There are some subscriptions waiting. Let's process them. Msg sub; while ((sub = pipe.Read()) != null) { // Apply the subscription to the trie. byte[] data = sub.Data; int size = sub.Size; if (size > 0 && (data[0] == 0 || data[0] == 1)) { bool unique; if (data[0] == 0) unique = m_subscriptions.Remove(data, 1, pipe); else unique = m_subscriptions.Add(data, 1, pipe); // If the subscription is not a duplicate, store it so that it can be // passed to used on next recv call. if (m_options.SocketType == ZmqSocketType.Xpub && (unique || m_verbose)) m_pending.Enqueue(new Blob(sub.Data)); } } }
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; }
private bool IdentifyPeer(Pipe pipe) { Blob identity; if (m_options.RawSocket) { // 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, buf.Length); } else { // Pick up handshake cases and also case where next identity is set Msg msg = new Msg(); msg.InitEmpty(); bool ok = pipe.Read(ref msg); if (!ok) { 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, buf.Length); msg.Close(); } else { identity = new Blob(msg.Data, msg.Size); // Ignore peers with duplicate ID. if (m_outpipes.ContainsKey(identity)) { msg.Close(); return(false); } msg.Close(); } } pipe.Identity = identity; // Add the record into output pipes lookup table Outpipe outpipe = new Outpipe(pipe, true); m_outpipes.Add(identity, outpipe); return(true); }