本文整理汇总了C#中NetMQ.zmq.SocketBase.Recv方法的典型用法代码示例。如果您正苦于以下问题:C# SocketBase.Recv方法的具体用法?C# SocketBase.Recv怎么用?C# SocketBase.Recv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.zmq.SocketBase
的用法示例。
在下文中一共展示了SocketBase.Recv方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public static MonitorEvent Read(SocketBase s)
{
Msg msg = s.Recv(0);
if (msg == null)
return null;
int pos = 0;
ByteArraySegment data = msg.Data;
SocketEvent @event =(SocketEvent) data.GetInteger(pos);
pos += 4;
int len = (int)data[pos++];
string addr = data.GetString(len, pos);
pos += len;
int flag = (int)data[pos++];
Object arg = null;
if (flag == ValueInteger)
{
arg = data.GetInteger(pos);
}
else if (flag == ValueChannel)
{
if (SizeOfIntPtr == 4)
{
arg = new IntPtr(data.GetInteger(pos));
}
else
{
arg = new IntPtr(data.GetLong(pos));
}
}
return new MonitorEvent(@event, addr, arg);
}
示例2: Read
public static MonitorEvent Read(SocketBase s)
{
Msg msg = s.Recv(0);
if (msg == null)
return null;
int pos = 0;
ByteArraySegment data = msg.Data;
SocketEvent @event = (SocketEvent)data.GetInteger(Endianness.Little, pos);
pos += 4;
int len = (int)data[pos++];
string addr = data.GetString(len, pos);
pos += len;
int flag = (int)data[pos++];
Object arg = null;
if (flag == ValueInteger)
{
arg = data.GetInteger(Endianness.Little, pos);
}
else if (flag == ValueChannel)
{
IntPtr value;
if (SizeOfIntPtr == 4)
{
value = new IntPtr(data.GetInteger(Endianness.Little, pos));
}
else
{
value = new IntPtr(data.GetLong(Endianness.Little, pos));
}
GCHandle handle = GCHandle.FromIntPtr(value);
Socket socket = null;
if (handle.IsAllocated)
{
socket = handle.Target as Socket;
}
handle.Free();
arg = socket;
}
return new MonitorEvent(@event, addr, arg);
}
示例3: RecvMsg
public static Msg RecvMsg(SocketBase s, SendReceiveOptions flags)
{
return s.Recv(flags);
}
示例4: CreateProxy
public static bool CreateProxy(SocketBase frontend,
SocketBase backend, SocketBase capture)
{
// The algorithm below assumes ratio of requests and replies processed
// under full load to be 1:1.
int more;
int rc;
Msg msg;
PollItem[] items = new PollItem[2];
items[0] = new PollItem(frontend, PollEvents.PollIn);
items[1] = new PollItem(backend, PollEvents.PollIn);
while (true)
{
// Wait while there are either requests or replies to process.
rc = ZMQ.Poll(items, -1);
if (rc < 0)
return false;
// Process a request.
if ((items[0].ResultEvent & PollEvents.PollIn) == PollEvents.PollIn)
{
while (true)
{
try
{
msg = frontend.Recv(0);
}
catch (TerminatingException)
{
return false;
}
if (msg == null)
{
return false;
}
more = frontend.GetSocketOption(ZmqSocketOptions.ReceiveMore);
if (more < 0)
return false;
// Copy message to capture socket if any
if (capture != null)
{
Msg ctrl = new Msg(msg);
capture.Send(ctrl, more > 0 ? SendReceiveOptions.SendMore : 0);
}
backend.Send(msg, more > 0 ? SendReceiveOptions.SendMore : 0);
if (more == 0)
break;
}
}
// Process a reply.
if ((items[1].ResultEvent & PollEvents.PollIn) == PollEvents.PollIn)
{
while (true)
{
try
{
msg = backend.Recv(0);
}
catch (TerminatingException)
{
return false;
}
if (msg == null)
{
return false;
}
more = backend.GetSocketOption(ZmqSocketOptions.ReceiveMore);
if (more < 0)
return false;
// Copy message to capture socket if any
if (capture != null)
{
Msg ctrl = new Msg(msg);
capture.Send(ctrl, more > 0 ? SendReceiveOptions.SendMore : 0);
}
frontend.Send(msg, more > 0 ? SendReceiveOptions.SendMore : 0);
if (more == 0)
break;
}
}
}
}