本文整理汇总了C#中NetMQ.zmq.Pipe.Read方法的典型用法代码示例。如果您正苦于以下问题:C# Pipe.Read方法的具体用法?C# Pipe.Read怎么用?C# Pipe.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.zmq.Pipe
的用法示例。
在下文中一共展示了Pipe.Read方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: XReadActivated
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));
}
}
}
示例2: IdentifyPeer
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;
}