本文整理汇总了C#中Msg.InitGC方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.InitGC方法的具体用法?C# Msg.InitGC怎么用?C# Msg.InitGC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg.InitGC方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Receive
public void Receive(ref Msg msg, SendReceiveOptions options)
{
LastOptions = options;
byte[] bytes = m_frames.Dequeue();
msg.InitGC(bytes, bytes.Length);
if (m_frames.Count != 0)
msg.SetFlags(MsgFlags.More);
}
示例2: TryReceive
public bool TryReceive(ref Msg msg, TimeSpan timeout)
{
LastTimeout = timeout;
if (m_frames.Count == 0)
return false;
byte[] bytes = m_frames.Dequeue();
msg.InitGC(bytes, bytes.Length);
if (m_frames.Count != 0)
msg.SetFlags(MsgFlags.More);
return true;
}
示例3: Write
public void Write([NotNull] SocketBase s)
{
int size = 4 + 1 + m_addr.Length + 1; // event + len(addr) + addr + flag
if (m_flag == ValueInteger)
size += 4;
else if (m_flag == ValueChannel)
size += s_sizeOfIntPtr;
int pos = 0;
ByteArraySegment buffer = new byte[size];
buffer.PutInteger(Endianness.Little, (int)m_monitorEvent, pos);
pos += 4;
buffer[pos++] = (byte)m_addr.Length;
// was not here originally
buffer.PutString(m_addr, pos);
pos += m_addr.Length;
buffer[pos++] = ((byte)m_flag);
if (m_flag == ValueInteger)
{
buffer.PutInteger(Endianness.Little, (int)m_arg, pos);
}
else if (m_flag == ValueChannel)
{
GCHandle handle = GCHandle.Alloc(m_arg, GCHandleType.Weak);
if (s_sizeOfIntPtr == 4)
buffer.PutInteger(Endianness.Little, GCHandle.ToIntPtr(handle).ToInt32(), pos);
else
buffer.PutLong(Endianness.Little, GCHandle.ToIntPtr(handle).ToInt64(), pos);
}
var msg = new Msg();
msg.InitGC((byte[])buffer, buffer.Size);
s.TrySend(ref msg, SendReceiveConstants.InfiniteTimeout, false);
}
示例4: Produce
protected override void Produce(PushSocket socket, int messageSize)
{
var msg = new Msg();
for (int i = 0; i < MsgCount; i++)
{
msg.InitGC(new byte[messageSize], messageSize);
msg.Data[messageSize / 2] = 0x42;
socket.Send(ref msg, more: false);
msg.Close();
}
}
示例5: InitGC
public void InitGC()
{
var msg = new Msg();
var bytes = new byte[200];
msg.InitGC(bytes, 100);
Assert.AreEqual(100, msg.Size);
Assert.AreEqual(MsgType.GC, msg.MsgType);
Assert.AreEqual(MsgFlags.None, msg.Flags);
Assert.AreSame(bytes, msg.Data);
Assert.IsFalse(msg.HasMore);
Assert.IsFalse(msg.IsDelimiter);
Assert.IsFalse(msg.IsIdentity);
Assert.IsTrue(msg.IsInitialised);
msg.Close();
Assert.AreEqual(MsgType.Uninitialised, msg.MsgType);
Assert.IsNull(msg.Data);
}
示例6: Write
public void Write([NotNull] SocketBase s)
{
int size = 4 + 1 + (m_addr?.Length ?? 0) + 1; // event + len(addr) + addr + flag
if (m_flag == ValueInteger)
size += 4;
else if (m_flag == ValueChannel)
size += s_sizeOfIntPtr;
int pos = 0;
ByteArraySegment buffer = new byte[size];
buffer.PutInteger(Endianness.Little, (int)m_monitorEvent, pos);
pos += 4;
if (m_addr != null)
{
buffer[pos++] = (byte)m_addr.Length;
// was not here originally
buffer.PutString(m_addr, pos);
pos += m_addr.Length;
}
else
buffer[pos++] = 0;
buffer[pos++] = ((byte)m_flag);
if (m_flag == ValueInteger)
{
buffer.PutInteger(Endianness.Little, (int)m_arg, pos);
}
else if (m_flag == ValueChannel)
{
GCHandle handle = GCHandle.Alloc(m_arg, GCHandleType.Weak);
if (s_sizeOfIntPtr == 4)
buffer.PutInteger(Endianness.Little, GCHandle.ToIntPtr(handle).ToInt32(), pos);
else
buffer.PutLong(Endianness.Little, GCHandle.ToIntPtr(handle).ToInt64(), pos);
}
var msg = new Msg();
msg.InitGC((byte[])buffer, buffer.Size);
// An infinite timeout here can cause the IO thread to hang
// see https://github.com/zeromq/netmq/issues/539
s.TrySend(ref msg, TimeSpan.Zero, false);
}
示例7: InitGCOffset
public void InitGCOffset()
{
var msg = new Msg();
var bytes = new byte[200];
msg.InitGC(bytes, 100, 50);
Assert.AreEqual(50, msg.Size);
Assert.AreEqual(MsgType.GC, msg.MsgType);
Assert.AreEqual(MsgFlags.None, msg.Flags);
Assert.AreSame(bytes, msg.Data);
Assert.IsFalse(msg.HasMore);
Assert.IsFalse(msg.IsDelimiter);
Assert.IsFalse(msg.IsIdentity);
Assert.IsTrue(msg.IsInitialised);
var src = new byte[100];
for (int i = 50; i < 100; i++) {
src[i] = (byte)i;
}
msg.Put(src[50]);
msg.Put(src[51], 1);
msg.Put(src, 52, 2, 48);
for (int i = 0; i < 50; i++) {
msg[i] = (byte)(i + 50);
}
msg.Close();
Assert.AreEqual(MsgType.Uninitialised, msg.MsgType);
Assert.IsNull(msg.Data);
}
示例8: DoClient
protected override long DoClient(NetMQSocket socket, int messageSize)
{
var msg = new Msg();
var watch = Stopwatch.StartNew();
for (int i = 0; i < Iterations; i++)
{
msg.InitGC(new byte[messageSize], messageSize);
socket.Send(ref msg, more: false);
socket.Receive(ref msg);
msg.Close();
}
return watch.ElapsedTicks;
}