本文整理汇总了C#中NetMQ.zmq.Msg.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.Close方法的具体用法?C# Msg.Close怎么用?C# Msg.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.zmq.Msg
的用法示例。
在下文中一共展示了Msg.Close方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static int Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("usage: remote_lat remote_lat <connect-to> <message-size> <roundtrip-count>");
return 1;
}
string connectTo = args[0];
int messageSize = int.Parse(args[1]);
int roundtripCount = int.Parse(args[2]);
var context = ZMQ.CtxNew();
var reqSocket = ZMQ.Socket(context, ZmqSocketType.Req);
bool connected = reqSocket.Connect(connectTo);
if (!connected)
{
Console.WriteLine("error in zmq_connect");
}
var message = new Msg(messageSize);
var stopWatch = Stopwatch.StartNew();
for (int i = 0; i != roundtripCount; i++)
{
bool sent = reqSocket.Send(message, SendRecieveOptions.None);
if (!sent)
{
Console.WriteLine("error in zmq_sendmsg");
return -1;
}
message = reqSocket.Recv(SendRecieveOptions.None);
if (message.Size != messageSize)
{
Console.WriteLine("message of incorrect size received. Received: " + message.Size + " Expected: " + messageSize);
return -1;
}
}
stopWatch.Stop();
message.Close();
double elapsedMicroseconds = stopWatch.ElapsedTicks * 1000000 / Stopwatch.Frequency;
double latency = elapsedMicroseconds / (roundtripCount * 2);
Console.WriteLine("message size: {0} [B]", messageSize);
Console.WriteLine("roundtrip count: {0}", roundtripCount);
Console.WriteLine("average latency: {0:0.000} [µs]", latency);
reqSocket.Close();
context.Terminate();
return 0;
}
示例2: XSub
static XSub()
{
s_sendSubscription = (data, size, arg) => {
Pipe pipe = (Pipe) arg;
// Create the subsctription message.
Msg msg = new Msg(size + 1);
msg.Put((byte)1);
msg.Put(data,1, size);
// Send it to the pipe.
bool sent = pipe.Write (msg);
// If we reached the SNDHWM, and thus cannot send the subscription, drop
// the subscription message instead. This matches the behaviour of
// zmq_setsockopt(ZMQ_SUBSCRIBE, ...), which also drops subscriptions
// when the SNDHWM is reached.
if (!sent)
msg.Close ();
};
}
示例3: Send
public bool Send(Msg msg, SendRecieveOptions flags)
{
// Drop the message if required. If we are at the end of the message
// switch back to non-dropping mode.
if (m_dropping) {
m_more = msg.HasMore;
m_dropping = m_more;
msg.Close ();
return true;
}
while (m_active > 0) {
if (m_pipes[m_current].Write (msg))
break;
Debug.Assert(!m_more);
m_active--;
if (m_current < m_active)
Utils.Swap (m_pipes, m_current, m_active);
else
m_current = 0;
}
// If there are no pipes we cannot send the message.
if (m_active == 0) {
ZError.ErrorNumber = ErrorNumber.EAGAIN;
return false;
}
// If it's part of the message we can fluch it downstream and
// continue round-robinning (load balance).
m_more = msg.HasMore;
if (!m_more) {
m_pipes[m_current].Flush();
if (m_active > 1)
m_current = (m_current + 1) % m_active;
}
return true;
}
示例4: ProcessPipeTermAck
protected override void ProcessPipeTermAck()
{
// Notify the user that all the references to the pipe should be dropped.
Debug.Assert(m_sink != null);
m_sink.Terminated(this);
// In terminating and double_terminated states there's nothing to do.
// Simply deallocate the pipe. In terminated state we have to ack the
// peer before deallocating this side of the pipe. All the other states
// are invalid.
if (m_state == State.Terminated)
{
m_outboundPipe = null;
SendPipeTermAck(m_peer);
}
else
Debug.Assert(m_state == State.Terminating || m_state == State.DoubleTerminated);
// We'll deallocate the inbound pipe, the peer will deallocate the outbound
// pipe (which is an inbound pipe from its point of view).
// First, delete all the unread messages in the pipe. We have to do it by
// hand because msg_t doesn't have automatic destructor. Then deallocate
// the ypipe itself.
var msg = new Msg();
while (m_inboundPipe.Read(out msg))
{
msg.Close();
}
m_inboundPipe = null;
}
示例5: ProcessHiccup
protected override void ProcessHiccup(object pipe)
{
// Destroy old out-pipe. Note that the read end of the pipe was already
// migrated to this thread.
Debug.Assert(m_outboundPipe != null);
m_outboundPipe.Flush();
var msg = new Msg();
while (m_outboundPipe.Read(out msg))
{
msg.Close();
}
// Plug in the new out-pipe.
Debug.Assert(pipe != null);
m_outboundPipe = (YPipe<Msg>)pipe;
m_outActive = true;
// If appropriate, notify the user about the hiccup.
if (m_state == State.Active)
m_sink.Hiccuped(this);
}
示例6: Rollback
/// <summary>
/// Remove unfinished parts of the outbound message from the pipe.
/// </summary>
public void Rollback()
{
// Remove incomplete message from the outbound pipe.
if (m_outboundPipe != null)
{
var msg = new Msg();
while (m_outboundPipe.Unwrite(ref msg))
{
Debug.Assert(msg.HasMore);
msg.Close();
}
}
}
示例7: CleanPipes
// Remove any half processed messages. Flush unflushed messages.
// Call this function when engine disconnect to get rid of leftovers.
private void CleanPipes()
{
if (m_pipe != null)
{
// Get rid of half-processed messages in the out pipe. Flush any
// unflushed messages upstream.
m_pipe.Rollback();
m_pipe.Flush();
// Remove any half-read message from the in pipe.
while (m_incompleteIn)
{
var msg = new Msg();
msg.InitEmpty();
if (!PullMsg(ref msg))
{
Debug.Assert(!m_incompleteIn);
break;
}
msg.Close();
}
}
}
示例8: PushMsg
public virtual bool PushMsg(ref Msg msg)
{
// First message to receive is identity (if required).
if (!m_identityReceived)
{
msg.SetFlags(MsgFlags.Identity);
m_identityReceived = true;
if (!m_options.RecvIdentity)
{
msg.Close();
msg.InitEmpty();
return true;
}
}
if (m_pipe != null && m_pipe.Write(ref msg))
{
msg.InitEmpty();
return true;
}
return false;
}