本文整理汇总了C#中Msg.InitEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.InitEmpty方法的具体用法?C# Msg.InitEmpty怎么用?C# Msg.InitEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg.InitEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: V1Encoder
public V1Encoder(int bufferSize, Endianness endian)
: base(bufferSize, endian)
{
m_inProgress = new Msg();
m_inProgress.InitEmpty();
// Write 0 bytes to the batch and go to message_ready state.
NextStep(m_tmpbuf, 0, MessageReadyState, true);
}
示例2: RawEncoder
public RawEncoder(int bufferSize, [NotNull] IMsgSource msgSource, Endianness endianness)
: base(bufferSize, endianness)
{
m_msgSource = msgSource;
m_inProgress = new Msg();
m_inProgress.InitEmpty();
NextStep(null, 0, RawMessageReadyState, true);
}
示例3: CheckTryReceive
public void CheckTryReceive()
{
using (var router = new RouterSocket())
{
router.BindRandomPort("tcp://127.0.0.1");
var msg = new Msg();
msg.InitEmpty();
Assert.IsFalse(router.TryReceive(ref msg, TimeSpan.Zero));
}
}
示例4: V2Encoder
public V2Encoder(int bufsize, IMsgSource session, Endianness endian)
: base(bufsize, endian)
{
m_inProgress = new Msg();
m_inProgress.InitEmpty();
m_tmpbuf = new byte[9];
m_msgSource = session;
// Write 0 bytes to the batch and go to message_ready state.
NextStep(m_tmpbuf, 0, MessageReadyState, true);
}
示例5: V1Decoder
/// <summary>
/// Create a new V1Decoder with the given buffer-size, maximum-message-size and Endian-ness.
/// </summary>
/// <param name="bufsize">the buffer-size to give the contained buffer</param>
/// <param name="maxMessageSize">the maximum message size. -1 indicates no limit.</param>
/// <param name="endian">the Endianness to specify for it - either Big or Little</param>
public V1Decoder(int bufsize, long maxMessageSize, Endianness endian)
: base(bufsize, endian)
{
m_maxMessageSize = maxMessageSize;
m_tmpbuf = new ByteArraySegment(new byte[8]);
// At the beginning, read one byte and go to one_byte_size_ready state.
NextStep(m_tmpbuf, 1, OneByteSizeReadyState);
m_inProgress = new Msg();
m_inProgress.InitEmpty();
}
示例6: V2Decoder
public V2Decoder(int bufsize, long maxmsgsize, IMsgSink session, Endianness endian)
: base(bufsize, endian)
{
m_maxmsgsize = maxmsgsize;
m_msgSink = session;
m_tmpbuf = new byte[8];
// At the beginning, read one byte and go to one_byte_size_ready state.
NextStep(m_tmpbuf, 1, FlagsReadyState);
m_inProgress = new Msg();
m_inProgress.InitEmpty();
}
示例7: Dealer
/// <summary>
/// Create a new Dealer socket that holds the prefetched message.
/// </summary>
public Dealer([NotNull] Ctx parent, int threadId, int socketId)
: base(parent, threadId, socketId)
{
m_prefetched = false;
m_options.SocketType = ZmqSocketType.Dealer;
m_fairQueueing = new FairQueueing();
m_loadBalancer = new LoadBalancer();
m_options.RecvIdentity = true;
m_prefetchedMsg = new Msg();
m_prefetchedMsg.InitEmpty();
}
示例8: ForwardTo
private static void ForwardTo(NetMQSocketEventArgs args, IOutgoingSocket toSocket)
{
var msg = new Msg();
msg.InitEmpty();
bool more;
do
{
args.Socket.Receive(ref msg);
more = msg.HasMore;
toSocket.Send(ref msg, more);
}
while (more);
msg.Close();
}
示例9: BroadcastEnabled
public void BroadcastEnabled()
{
using (var context = NetMQContext.Create())
using (var pub = context.CreateXPublisherSocket())
using (var sub1 = context.CreateXSubscriberSocket())
using (var sub2 = context.CreateXSubscriberSocket())
{
pub.Bind("inproc://manual");
pub.Options.XPubBroadcast = true;
sub1.Connect("inproc://manual");
sub2.Connect("inproc://manual");
sub1.SendFrame(new byte[] {1, (byte) 'A'});
sub2.SendFrame(new byte[] {1, (byte) 'A'});
var payload = new[] {(byte) 42};
var msg = new Msg();
msg.InitEmpty();
// add prefix 2 to the topic, this indicates a broadcast message and it will not be sent to sub1
sub1.SendFrame(new byte[] {2, (byte) 'A'}, true);
sub1.SendFrame(new byte[] {(byte) 42});
var subscription = pub.ReceiveFrameBytes();
var topic = pub.ReceiveFrameBytes();
var message = pub.ReceiveFrameBytes();
Assert.AreEqual(2, topic[0]);
// we must skip the first byte if we have detected a broadcast message
// the sender of this message is already marked for exclusion
// but the match logic in Send should work with normal topic.
topic = topic.Skip(1).ToArray();
pub.SendFrame(topic, true);
pub.SendFrame(message);
var broadcast2 = sub2.ReceiveFrameBytes();
Assert.IsTrue(broadcast2[0] == 65);
broadcast2 = sub2.ReceiveFrameBytes();
Assert.IsTrue(broadcast2.SequenceEqual(payload));
// this message SHOULD NOT be resent to sub1
var received = sub1.TryReceive(ref msg, System.TimeSpan.FromMilliseconds(500));
Assert.IsFalse(received);
}
}
示例10: BroadcastDisabled
public void BroadcastDisabled()
{
using (var context = NetMQContext.Create())
using (var pub = context.CreateXPublisherSocket())
using (var sub1 = context.CreateXSubscriberSocket())
using (var sub2 = context.CreateXSubscriberSocket())
{
pub.Bind("inproc://manual");
pub.Options.XPubBroadcast = false;
sub1.Connect("inproc://manual");
sub2.Connect("inproc://manual");
Thread.Sleep(50);
sub1.SendFrame(new byte[] { 1, (byte)'A' });
sub2.SendFrame(new byte[] { 1, (byte)'A' });
var payload = new[] { (byte)42 };
var msg = new Msg();
msg.InitEmpty();
sub1.SendFrame(new byte[] { (byte)'A' }, true);
sub1.SendFrame(new byte[] { (byte)42 });
var subscription = pub.ReceiveFrameBytes();
var topic = pub.ReceiveFrameBytes();
var message = pub.ReceiveFrameBytes();
pub.SendFrame(topic, true);
pub.SendFrame(message);
var broadcast2 = sub2.ReceiveFrameBytes();
Assert.IsTrue(broadcast2[0] == 65);
broadcast2 = sub2.ReceiveFrameBytes();
Assert.IsTrue(broadcast2.SequenceEqual(payload));
// sub1 should receive a message normally
var broadcast1 = sub1.ReceiveFrameBytes();
Assert.IsTrue(broadcast1[0] == 65);
broadcast1 = sub1.ReceiveFrameBytes();
Assert.IsTrue(broadcast1.SequenceEqual(payload));
}
}
示例11: Read
public static MonitorEvent Read([NotNull] SocketBase s)
{
var msg = new Msg();
msg.InitEmpty();
s.TryRecv(ref msg, SendReceiveConstants.InfiniteTimeout);
int pos = msg.Offset;
ByteArraySegment data = msg.Data;
var @event = (SocketEvents)data.GetInteger(Endianness.Little, pos);
pos += 4;
var len = (int)data[pos++];
string addr = data.GetString(len, pos);
pos += len;
var flag = (int)data[pos++];
object arg = null;
if (flag == ValueInteger)
{
arg = data.GetInteger(Endianness.Little, pos);
}
else if (flag == ValueChannel)
{
IntPtr value = s_sizeOfIntPtr == 4
? new IntPtr(data.GetInteger(Endianness.Little, pos))
: new IntPtr(data.GetLong(Endianness.Little, pos));
GCHandle handle = GCHandle.FromIntPtr(value);
AsyncSocket socket = null;
if (handle.IsAllocated)
{
socket = handle.Target as AsyncSocket;
}
handle.Free();
arg = socket;
}
return new MonitorEvent(@event, addr, arg);
}
示例12: IOObject
void IEngine.Plug(IOThread ioThread, SessionBase session)
{
m_session = session;
m_ioObject = new IOObject(null);
m_ioObject.SetHandler(this);
m_ioObject.Plug(ioThread);
m_ioObject.AddSocket(m_handle);
DropSubscriptions();
var msg = new Msg();
msg.InitEmpty();
// push message to the session because there is no identity message with pgm
session.PushMsg(ref msg);
m_state = State.Receiving;
BeginReceive();
}
示例13: Plug
public void Plug(IOThread ioThread, SessionBase session)
{
m_encoder.SetMsgSource(session);
// get the first message from the session because we don't want to send identities
var msg = new Msg();
msg.InitEmpty();
bool ok = session.PullMsg(ref msg);
if (ok)
{
msg.Close();
}
AddSocket(m_socket);
m_state = State.Connecting;
m_socket.Connect(m_pgmAddress.Address);
}
示例14: XSend
/// <summary>
/// Transmit the given message. The <c>Send</c> method calls this to do the actual sending.
/// </summary>
/// <param name="msg">the message to transmit</param>
/// <returns><c>true</c> if the message was sent successfully</returns>
/// <exception cref="FiniteStateMachineException">Cannot XSend on a Req while awaiting reply.</exception>
protected override bool XSend(ref Msg msg)
{
// If we've sent a request and we still haven't got the reply,
// we can't send another request.
if (m_receivingReply)
throw new FiniteStateMachineException("Req.XSend - cannot send another request");
bool isMessageSent;
// First part of the request is the request identity.
if (m_messageBegins)
{
var bottom = new Msg();
bottom.InitEmpty();
bottom.SetFlags(MsgFlags.More);
isMessageSent = base.XSend(ref bottom);
if (!isMessageSent)
return false;
m_messageBegins = false;
}
bool more = msg.HasMore;
isMessageSent = base.XSend(ref msg);
if (!isMessageSent)
return false;
// If the request was fully sent, flip the FSM into reply-receiving state.
if (!more)
{
m_receivingReply = true;
m_messageBegins = true;
}
return true;
}
示例15: Send
public bool Send(ref Msg msg)
{
// 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();
msg.InitEmpty();
return true;
}
while (m_active > 0)
{
if (m_pipes[m_current].Write(ref msg))
break;
Debug.Assert(!m_more);
m_active--;
if (m_current < m_active)
m_pipes.Swap(m_current, m_active);
else
m_current = 0;
}
// If there are no pipes we cannot send the message.
if (m_active == 0)
{
return false;
}
// If it's part of the message we can flush 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;
}
// Detach the message from the data buffer.
msg.InitEmpty();
return true;
}