本文整理汇总了C#中NetMQ.Msg.CloneData方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.CloneData方法的具体用法?C# Msg.CloneData怎么用?C# Msg.CloneData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.Msg
的用法示例。
在下文中一共展示了Msg.CloneData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveFrameBytes
public static byte[] ReceiveFrameBytes([NotNull] this IReceivingSocket socket, out bool more)
{
var msg = new Msg();
msg.InitEmpty();
socket.Receive(ref msg);
var data = msg.CloneData();
more = msg.HasMore;
msg.Close();
return data;
}
示例2: Receive
public static byte[] Receive([NotNull] this IReceivingSocket socket, SendReceiveOptions options, out bool hasMore)
{
var msg = new Msg();
msg.InitEmpty();
socket.Receive(ref msg, options);
var data = msg.CloneData();
hasMore = msg.HasMore;
msg.Close();
return data;
}
示例3: TryReceiveMultipartBytes
/// <summary>
/// Attempt to receive all frames of the next message from <paramref cref="socket"/>.
/// If no message is available within <paramref name="timeout"/>, return <c>false</c>.
/// </summary>
/// <param name="socket">The socket to receive from.</param>
/// <param name="timeout">The maximum period of time to wait for a message to become available.</param>
/// <param name="frames">Reference to a list for return values. If <c>null</c> a new instance will be assigned, otherwise the provided list will be cleared and populated.</param>
/// <param name="expectedFrameCount">Optional initial <see cref="List{T}.Capacity"/> for the returned <see cref="List{T}"/>.</param>
public static bool TryReceiveMultipartBytes([NotNull] this IReceivingSocket socket, TimeSpan timeout, ref List<byte[]> frames, int expectedFrameCount = 4)
{
var msg = new Msg();
msg.InitEmpty();
// Try to read the first frame
if (!socket.TryReceive(ref msg, timeout))
{
msg.Close();
return false;
}
// We have one, so prepare the container
if (frames == null)
frames = new List<byte[]>(expectedFrameCount);
else
frames.Clear();
// Add the frame
frames.Add(msg.CloneData());
// Rinse and repeat...
while (msg.HasMore)
{
socket.Receive(ref msg);
frames.Add(msg.CloneData());
}
msg.Close();
return true;
}
示例4: ReceiveMultipartBytes
/// <summary>
/// Receive all frames of the next message from <paramref cref="socket"/>, blocking until a message arrives.
/// </summary>
/// <param name="socket">The socket to receive from.</param>
/// <param name="frames">Reference to a list for return values. If <c>null</c> a new instance will be assigned, otherwise the provided list will be cleared and populated.</param>
/// <param name="expectedFrameCount">Optional initial <see cref="List{T}.Capacity"/> for the returned <see cref="List{T}"/>.</param>
public static void ReceiveMultipartBytes([NotNull] this IReceivingSocket socket, ref List<byte[]> frames, int expectedFrameCount = 4)
{
if (frames == null)
frames = new List<byte[]>(expectedFrameCount);
else
frames.Clear();
var msg = new Msg();
msg.InitEmpty();
do
{
socket.Receive(ref msg);
frames.Add(msg.CloneData());
}
while (msg.HasMore);
msg.Close();
}
示例5: TryReceiveFrameBytes
/// <summary>
/// Attempt to receive a single frame from <paramref cref="socket"/>.
/// If no message is available within <paramref name="timeout"/>, return <c>false</c>.
/// Indicate whether further frames exist via <paramref name="more"/>.
/// </summary>
/// <param name="socket">The socket to receive from.</param>
/// <param name="more"><c>true</c> if another frame of the same message follows, otherwise <c>false</c>.</param>
/// <param name="timeout">The maximum period of time to wait for a message to become available.</param>
/// <param name="bytes">The content of the received message frame, or <c>null</c> if no message was available.</param>
/// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns>
public static bool TryReceiveFrameBytes([NotNull] this IReceivingSocket socket, TimeSpan timeout, out byte[] bytes, out bool more)
{
var msg = new Msg();
msg.InitEmpty();
if (!socket.TryReceive(ref msg, timeout))
{
msg.Close();
bytes = null;
more = false;
return false;
}
bytes = msg.CloneData();
more = msg.HasMore;
msg.Close();
return true;
}
示例6: ReceiveMessage
public static void ReceiveMessage([NotNull] this IReceivingSocket socket, [NotNull] NetMQMessage message, bool dontWait = false)
{
message.Clear();
var msg = new Msg();
msg.InitEmpty();
do
{
socket.Receive(ref msg, dontWait ? SendReceiveOptions.DontWait : SendReceiveOptions.None);
message.Append(msg.CloneData());
}
while (msg.HasMore);
msg.Close();
}
示例7: TryReceiveMultipartMessage
/// <summary>
/// Attempt to receive all frames of the next message from <paramref cref="socket"/>.
/// If no message is available within <paramref name="timeout"/>, return <c>false</c>.
/// </summary>
/// <param name="socket">The socket to receive from.</param>
/// <param name="timeout">The maximum period of time to wait for a message to become available.</param>
/// <param name="message">The received message. Untouched if no message was available.</param>
/// <param name="expectedFrameCount">Specifies the initial capacity of the <see cref="List{T}"/> used
/// to buffer results. If the number of frames is known, set it here. If more frames arrive than expected,
/// an extra allocation will occur, but the result will still be correct.</param>
/// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns>
public static bool TryReceiveMultipartMessage([NotNull] this IReceivingSocket socket, TimeSpan timeout, [CanBeNull] ref NetMQMessage message, int expectedFrameCount = 4)
{
var msg = new Msg();
msg.InitEmpty();
// Try to read the first frame
if (!socket.TryReceive(ref msg, timeout))
{
msg.Close();
return false;
}
// We have one, so prepare the container
if (message == null)
message = new NetMQMessage(expectedFrameCount);
else
message.Clear();
// Add the frame
message.Append(new NetMQFrame(msg.CloneData()));
// Rinse and repeat...
while (msg.HasMore)
{
socket.Receive(ref msg);
message.Append(new NetMQFrame(msg.CloneData()));
}
msg.Close();
return true;
}
示例8: ReceiveMultipartMessage
public static NetMQMessage ReceiveMultipartMessage([NotNull] this IReceivingSocket socket, int expectedFrameCount = 4)
{
var msg = new Msg();
msg.InitEmpty();
var message = new NetMQMessage(expectedFrameCount);
do
{
socket.Receive(ref msg);
message.Append(msg.CloneData());
}
while (msg.HasMore);
msg.Close();
return message;
}