本文整理汇总了C#中NetMQ.Msg.InitPool方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.InitPool方法的具体用法?C# Msg.InitPool怎么用?C# Msg.InitPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQ.Msg
的用法示例。
在下文中一共展示了Msg.InitPool方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static int Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("usage: remote_thr <connect-to> <message-size> <message-count>");
return 1;
}
string connectTo = args[0];
int messageSize = int.Parse(args[1]);
int messageCount = int.Parse(args[2]);
using (var context = NetMQContext.Create())
using (var push = context.CreatePushSocket())
{
push.Connect(connectTo);
for (int i = 0; i != messageCount; i++)
{
var msg = new Msg();
msg.InitPool(messageSize);
push.Send(ref msg, SendReceiveOptions.None);
msg.Close();
}
}
return 0;
}
示例2: SendFrame
/// <summary>
/// Transmit a byte-array of data over this socket, block until frame is sent.
/// </summary>
/// <param name="socket">the IOutgoingSocket to transmit on</param>
/// <param name="data">the byte-array of data to send</param>
/// <param name="length">the number of bytes to send from <paramref name="data"/>.</param>
/// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param>
public static void SendFrame( this IOutgoingSocket socket, byte[] data, int length, bool more = false)
{
var msg = new Msg();
msg.InitPool(length);
Buffer.BlockCopy(data, 0, msg.Data, msg.Offset, length);
socket.Send(ref msg, more);
msg.Close();
}
示例3: Send
public static void Send([NotNull] this IOutgoingSocket socket, [NotNull] byte[] data, int length, SendReceiveOptions options)
{
var msg = new Msg();
msg.InitPool(length);
Buffer.BlockCopy(data, 0, msg.Data, 0, length);
socket.Send(ref msg, options);
msg.Close();
}
示例4: SendFrame
/// <summary>
/// Transmit a string over this socket, block until frame is sent.
/// </summary>
/// <param name="socket">the IOutgoingSocket to transmit on</param>
/// <param name="message">the string to send</param>
/// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param>
public static void SendFrame([NotNull] this IOutgoingSocket socket, [NotNull] string message, bool more = false)
{
var msg = new Msg();
// Count the number of bytes required to encode the string.
// Note that non-ASCII strings may not have an equal number of characters
// and bytes. The encoding must be queried for this answer.
// With this number, request a buffer from the pool.
msg.InitPool(SendReceiveConstants.DefaultEncoding.GetByteCount(message));
// Encode the string into the buffer
SendReceiveConstants.DefaultEncoding.GetBytes(message, 0, message.Length, msg.Data, 0);
socket.Send(ref msg, more);
msg.Close();
}
示例5: TrySignal
/// <summary>
/// Attempt to transmit a status-signal over this socket.
/// If signal cannot be sent immediately, return <c>false</c>.
/// </summary>
/// <param name="socket">the IOutgoingSocket to transmit on</param>
/// <param name="status">a byte that contains the status signal to send</param>
private static bool TrySignal([NotNull] this IOutgoingSocket socket, byte status)
{
long signalValue = 0x7766554433221100L + status;
Msg msg = new Msg();
msg.InitPool(8);
NetworkOrderBitsConverter.PutInt64(signalValue, msg.Data);
if (!socket.TrySend(ref msg, TimeSpan.Zero, false))
{
msg.Close();
return false;
}
msg.Close();
return true;
}
示例6: Signal
/// <summary>
/// Transmit a status-signal over this socket.
/// </summary>
/// <param name="socket">the IOutgoingSocket to transmit on</param>
/// <param name="status">a byte that contains the status signal to send</param>
private static void Signal([NotNull] this IOutgoingSocket socket, byte status)
{
long signalValue = 0x7766554433221100L + status;
Msg msg = new Msg();
msg.InitPool(8);
NetworkOrderBitsConverter.PutInt64(signalValue, msg.Data);
socket.Send(ref msg, false);
msg.Close();
}
示例7: TrySendFrame
/// <summary>
/// Attempt to transmit a single frame on <paramref cref="socket"/>.
/// If message cannot be sent within <paramref name="timeout"/>, return <c>false</c>.
/// </summary>
/// <param name="socket">the IOutgoingSocket to transmit on</param>
/// <param name="timeout">The maximum period of time to try to send a message.</param>
/// <param name="data">the byte-array of data to send</param>
/// <param name="length">the number of bytes to send from <paramref name="data"/>.</param>
/// <param name="more">set this flag to true to signal that you will be immediately sending another frame (optional: default is false)</param>
/// <returns><c>true</c> if a message was available, otherwise <c>false</c>.</returns>
public static bool TrySendFrame([NotNull] this IOutgoingSocket socket, TimeSpan timeout, [NotNull] byte[] data, int length, bool more = false)
{
var msg = new Msg();
msg.InitPool(length);
Buffer.BlockCopy(data, 0, msg.Data, 0, length);
if (!socket.TrySend(ref msg, timeout, more))
{
msg.Close();
return false;
}
msg.Close();
return true;
}
示例8: Send
public static void Send( this IOutgoingSocket socket, string message, Encoding encoding, SendReceiveOptions options)
{
var msg = new Msg();
// Count the number of bytes required to encode the string.
// Note that non-ASCII strings may not have an equal number of characters
// and bytes. The encoding must be queried for this answer.
// With this number, request a buffer from the pool.
msg.InitPool(encoding.GetByteCount(message));
// Encode the string into the buffer
encoding.GetBytes(message, 0, message.Length, msg.Data, 0);
socket.Send(ref msg, options);
msg.Close();
}
示例9: Send
/// <summary>
/// Send the Example to the socket.
/// </summary>
public void Send(IOutgoingSocket output)
{
if (output is RouterSocket)
output.SendMore(RoutingId);
int frameSize = 2 + 1; // Signature and message ID
switch (Id)
{
case MessageId.Log:
frameSize += 2; // Sequence
frameSize += 2; // Version
frameSize += 1; // Level
frameSize += 1; // Event
frameSize += 2; // Node
frameSize += 2; // Peer
frameSize += 8; // Time
frameSize += 1 + Host.Length;
frameSize += 4;
if (Data != null)
frameSize += Data.Length;
break;
case MessageId.Structures:
frameSize += 2; // Sequence
frameSize += 4; // Size is 4 octets
if (Aliases != null)
{
foreach(string s in Aliases)
{
frameSize += 4 + s.Length;
}
}
frameSize += 4; // Size is 4 octets
if (Headers != null)
{
int headersSize = 0;
foreach (var pair in Headers)
{
headersSize += 1 + pair.Key.Length;
headersSize += 4 + pair.Value.Length;
}
frameSize += headersSize;
}
break;
case MessageId.Binary:
frameSize += 2; // Sequence
frameSize += 4; // Flags
frameSize += 4; // Size is 4 octets
if (PublicKey != null)
frameSize += PublicKey.Length;
frameSize += 16; // Identifier
break;
case MessageId.Types:
frameSize += 2; // Sequence
frameSize += 1 + ClientForename.Length;
frameSize += 1 + ClientSurname.Length;
frameSize += 1 + ClientMobile.Length;
frameSize += 1 + ClientEmail.Length;
frameSize += 1 + SupplierForename.Length;
frameSize += 1 + SupplierSurname.Length;
frameSize += 1 + SupplierMobile.Length;
frameSize += 1 + SupplierEmail.Length;
break;
}
// Now serialize message into the buffer
Msg msg = new Msg();
msg.InitPool(frameSize);
try
{
m_offset = 0;
m_buffer = msg.Data;
// put signature
PutNumber2(0xAAA0 | 0);
// put message id
PutNumber1((byte)Id);
bool sendContent = false;
int frames = 1; // Total number of frames to send
switch (Id)
{
case MessageId.Log:
PutNumber2(Sequence);
PutNumber2(3); // Version
PutNumber1(Level);
PutNumber1(Event);
PutNumber2(Node);
PutNumber2(Peer);
PutNumber8(Time);
PutString(Host);
if (Data != null)
PutLongString(Data);
//.........这里部分代码省略.........
示例10: Send
/// <summary>
/// Send the ZreMsg to the socket.
/// </summary>
public void Send(IOutgoingSocket output)
{
if (output is RouterSocket)
output.SendMoreFrame(RoutingId);
int frameSize = 2 + 1; // Signature and message ID
switch (Id)
{
case MessageId.Hello:
frameSize += Hello.GetFrameSize();
break;
case MessageId.Whisper:
frameSize += Whisper.GetFrameSize();
break;
case MessageId.Shout:
frameSize += Shout.GetFrameSize();
break;
case MessageId.Join:
frameSize += Join.GetFrameSize();
break;
case MessageId.Leave:
frameSize += Leave.GetFrameSize();
break;
case MessageId.Ping:
frameSize += Ping.GetFrameSize();
break;
case MessageId.PingOk:
frameSize += PingOk.GetFrameSize();
break;
}
// Now serialize message into the buffer
Msg msg = new Msg();
msg.InitPool(frameSize);
try
{
m_offset = 0;
m_buffer = msg.Data;
// put signature
PutNumber2(0xAAA0 | 1);
// put message id
PutNumber1((byte)Id);
switch (Id)
{
case MessageId.Hello:
Hello.Write(this);
break;
case MessageId.Whisper:
Whisper.Write(this);
break;
case MessageId.Shout:
Shout.Write(this);
break;
case MessageId.Join:
Join.Write(this);
break;
case MessageId.Leave:
Leave.Write(this);
break;
case MessageId.Ping:
Ping.Write(this);
break;
case MessageId.PingOk:
PingOk.Write(this);
break;
}
// Send the data frame
output.Send(ref msg, false);
}
finally
{
m_buffer = null;
msg.Close();
}
}
示例11: Send
/// <summary>
/// Send the Codec to the socket.
/// </summary>
public void Send(IOutgoingSocket output)
{
if (output is RouterSocket)
output.SendMoreFrame(RoutingId);
int frameSize = 2 + 1; // Signature and message ID
switch (Id)
{
case MessageId.Message:
frameSize += Message.GetFrameSize();
break;
case MessageId.ServiceRegister:
frameSize += ServiceRegister.GetFrameSize();
break;
case MessageId.Error:
frameSize += Error.GetFrameSize();
break;
}
// Now serialize message into the buffer
Msg msg = new Msg();
msg.InitPool(frameSize);
try
{
m_offset = 0;
m_buffer = msg.Data;
// put signature
PutNumber2(0xAAA0 | 0);
// put message id
PutNumber1((byte)Id);
switch (Id)
{
case MessageId.Message:
Message.Write(this);
break;
case MessageId.ServiceRegister:
ServiceRegister.Write(this);
break;
case MessageId.Error:
Error.Write(this);
break;
}
// Send the data frame
output.Send(ref msg, false);
}
finally
{
m_buffer = null;
msg.Close();
}
}
示例12: Main
private static void Main()
{
const int messageCount = 1000000;
const int dealerCount = 100;
Console.WriteLine("Sending {0} messages to {1} dealers", messageCount, dealerCount);
//BufferPool.SetBufferManagerBufferPool(1024 * 1024 * 10, 1024);
using (var router = new RouterSocket())
{
router.Options.SendHighWatermark = 0;
router.Bind("tcp://*:5555");
var dealers = new List<DealerSocket>();
var identities = new List<Msg>();
var random = new Random();
var identity = new byte[50];
for (var i = 0; i < dealerCount; i++)
{
random.NextBytes(identity);
var dealer = new DealerSocket
{
Options =
{
Identity = identity.Skip(10).ToArray(),
ReceiveHighWatermark = 0
}
};
dealer.Connect("tcp://localhost:5555");
dealers.Add(dealer);
var msg = new Msg();
msg.InitGC(identity, 10, identity.Length); // test offsets
identities.Add(msg);
}
Thread.Sleep(500);
while (!Console.KeyAvailable)
{
Thread.Sleep(500);
var stopwatch = Stopwatch.StartNew();
for (var i = 0; i < messageCount; i++)
{
var msg = identities[i%identities.Count];
router.Send(ref msg, true);
var msg2 = new Msg();
msg2.InitPool(1);
msg2.Put((byte) 'E');
router.Send(ref msg2, false);
}
stopwatch.Stop();
Console.WriteLine("{0:N1} messages sent per second", messageCount/stopwatch.Elapsed.TotalSeconds);
}
foreach (var dealerSocket in dealers)
dealerSocket.Dispose();
}
}
示例13: Send
/// <summary>
/// Send the ZreMsg to the socket.
/// Warning re WHISPER and SHOUT: The 0MQ spec http://rfc.zeromq.org/spec:36
/// says "message content defined as one 0MQ frame. ZRE does not support multi-frame message contents."
/// </summary>
public void Send(IOutgoingSocket output)
{
if (output is RouterSocket)
output.SendMoreFrame(RoutingId);
int frameSize = 2 + 1; // Signature and message ID
switch (Id)
{
case MessageId.Hello:
frameSize += Hello.GetFrameSize();
break;
case MessageId.Whisper:
frameSize += Whisper.GetFrameSize();
break;
case MessageId.Shout:
frameSize += Shout.GetFrameSize();
break;
case MessageId.Join:
frameSize += Join.GetFrameSize();
break;
case MessageId.Leave:
frameSize += Leave.GetFrameSize();
break;
case MessageId.Ping:
frameSize += Ping.GetFrameSize();
break;
case MessageId.PingOk:
frameSize += PingOk.GetFrameSize();
break;
}
// Now serialize message into the buffer
Msg msg = new Msg();
msg.InitPool(frameSize);
try
{
m_offset = 0;
m_buffer = msg.Data;
// put signature
PutNumber2(0xAAA0 | 1);
// put message id
PutNumber1((byte) Id);
switch (Id)
{
case MessageId.Hello:
Hello.Write(this);
break;
case MessageId.Whisper:
Whisper.Write(this);
break;
case MessageId.Shout:
Shout.Write(this);
break;
case MessageId.Join:
Join.Write(this);
break;
case MessageId.Leave:
Leave.Write(this);
break;
case MessageId.Ping:
Ping.Write(this);
break;
case MessageId.PingOk:
PingOk.Write(this);
break;
}
// Send the data frame
var more = Id == MessageId.Whisper || Id == MessageId.Shout;
output.TrySend(ref msg, TimeSpan.Zero, more);
// Send message content for types with content
switch (Id)
{
case MessageId.Whisper:
if (Whisper.Content == null)
{
Whisper.Content = new NetMQMessage();
Whisper.Content.PushEmptyFrame();
}
output.TrySendMultipartMessage(Whisper.Content);
break;
case MessageId.Shout:
if (Shout.Content == null)
{
Shout.Content = new NetMQMessage();
Shout.Content.PushEmptyFrame();
}
output.TrySendMultipartMessage(Shout.Content);
break;
}
//.........这里部分代码省略.........