本文整理汇总了C#中Msg.SetFlags方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.SetFlags方法的具体用法?C# Msg.SetFlags怎么用?C# Msg.SetFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg.SetFlags方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Flags
public void Flags()
{
var msg = new Msg();
Assert.AreEqual(MsgFlags.None, msg.Flags);
msg.SetFlags(MsgFlags.Identity);
Assert.IsTrue(msg.IsIdentity);
Assert.IsFalse(msg.HasMore);
Assert.IsFalse(msg.IsShared);
Assert.AreEqual(MsgFlags.Identity, msg.Flags);
msg.SetFlags(MsgFlags.More);
Assert.IsTrue(msg.IsIdentity);
Assert.IsTrue(msg.HasMore);
Assert.IsFalse(msg.IsShared);
Assert.AreEqual(MsgFlags.Identity | MsgFlags.More, msg.Flags);
msg.SetFlags(MsgFlags.Shared);
Assert.IsTrue(msg.IsIdentity);
Assert.IsTrue(msg.HasMore);
Assert.IsTrue(msg.IsShared);
Assert.AreEqual(MsgFlags.Identity | MsgFlags.More | MsgFlags.Shared, msg.Flags);
msg.SetFlags(MsgFlags.Identity);
msg.SetFlags(MsgFlags.More);
msg.SetFlags(MsgFlags.More);
msg.SetFlags(MsgFlags.Shared);
msg.SetFlags(MsgFlags.Shared);
msg.SetFlags(MsgFlags.Shared);
Assert.AreEqual(MsgFlags.Identity | MsgFlags.More | MsgFlags.Shared, msg.Flags);
msg.ResetFlags(MsgFlags.Shared);
Assert.IsTrue(msg.IsIdentity);
Assert.IsTrue(msg.HasMore);
Assert.IsFalse(msg.IsShared);
Assert.AreEqual(MsgFlags.Identity | MsgFlags.More, msg.Flags);
msg.ResetFlags(MsgFlags.More);
Assert.IsTrue(msg.IsIdentity);
Assert.IsFalse(msg.HasMore);
Assert.IsFalse(msg.IsShared);
Assert.AreEqual(MsgFlags.Identity, msg.Flags);
msg.ResetFlags(MsgFlags.Identity);
Assert.IsFalse(msg.IsIdentity);
Assert.IsFalse(msg.HasMore);
Assert.IsFalse(msg.IsShared);
Assert.AreEqual(MsgFlags.None, msg.Flags);
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
示例5: EightByteSizeReady
private bool EightByteSizeReady()
{
m_tmpbuf.Reset();
// The payload size is encoded as 64-bit unsigned integer.
// The most significant byte comes first.
long msg_size = m_tmpbuf.GetLong(0);
// Message size must not exceed the maximum allowed size.
if (m_maxmsgsize >= 0)
if (msg_size > m_maxmsgsize) {
DecodingError ();
return false;
}
// Message size must fit within range of size_t data type.
if (msg_size > int.MaxValue) {
DecodingError ();
return false;
}
// in_progress is initialised at this point so in theory we should
// close it before calling init_size, however, it's a 0-byte
// message and thus we can treat it as uninitialised.
m_inProgress = new Msg ((int) msg_size);
m_inProgress.SetFlags (m_msgFlags);
NextStep (m_inProgress.Data , m_inProgress.Size, MessageReadyState);
return true;
}
示例6: OneByteSizeReady
private bool OneByteSizeReady()
{
m_tmpbuf.Reset();
// Message size must not exceed the maximum allowed size.
if (m_maxmsgsize >= 0)
if (m_tmpbuf [0] > m_maxmsgsize) {
DecodingError ();
return false;
}
// in_progress is initialised at this point so in theory we should
// close it before calling zmq_msg_init_size, however, it's a 0-byte
// message and thus we can treat it as uninitialised...
m_inProgress = new Msg(m_tmpbuf [0]);
m_inProgress.SetFlags (m_msgFlags);
NextStep (m_inProgress.Data , m_inProgress.Size ,MessageReadyState);
return true;
}
示例7: TrySend
/// <summary>
/// Transmit the given Msg across the message-queueing system.
/// </summary>
/// <param name="msg">The <see cref="Msg"/> to send.</param>
/// <param name="timeout">The timeout to wait before returning <c>false</c>. Pass <see cref="SendReceiveConstants.InfiniteTimeout"/> to disable timeout.</param>
/// <param name="more">Whether this message will contain another frame after this one.</param>
/// <exception cref="TerminatingException">The socket has been stopped.</exception>
/// <exception cref="FaultException"><paramref name="msg"/> is not initialised.</exception>
public bool TrySend(ref Msg msg, TimeSpan timeout, bool more)
{
CheckContextTerminated();
// Check whether message passed to the function is valid.
if (!msg.IsInitialised)
throw new FaultException("SocketBase.Send passed an uninitialised Msg.");
// Process pending commands, if any.
ProcessCommands(0, true);
// Clear any user-visible flags that are set on the message.
msg.ResetFlags(MsgFlags.More);
// At this point we impose the flags on the message.
if (more)
msg.SetFlags(MsgFlags.More);
// Try to send the message.
bool isMessageSent = XSend(ref msg);
if (isMessageSent)
return true;
// In case of non-blocking send we'll simply return false
if (timeout == TimeSpan.Zero)
return false;
// Compute the time when the timeout should occur.
// If the timeout is infinite, don't care.
int timeoutMillis = (int)timeout.TotalMilliseconds;
long end = timeoutMillis < 0 ? 0 : (Clock.NowMs() + timeoutMillis);
// Oops, we couldn't send the message. Wait for the next
// command, process it and try to send the message again.
// If timeout is reached in the meantime, return EAGAIN.
while (true)
{
ProcessCommands(timeoutMillis, false);
isMessageSent = XSend(ref msg);
if (isMessageSent)
break;
if (timeoutMillis <= 0)
continue;
timeoutMillis = (int)(end - Clock.NowMs());
if (timeoutMillis <= 0)
return false;
}
return true;
}
示例8: Connect
/// <summary>
/// Connect this socket to the given address.
/// </summary>
/// <param name="addr">a string denoting the endpoint to connect to</param>
/// <exception cref="AddressAlreadyInUseException">The specified address is already in use.</exception>
/// <exception cref="NetMQException">No IO thread was found.</exception>
/// <exception cref="ProtocolNotSupportedException">the specified protocol is not supported</exception>
/// <exception cref="ProtocolNotSupportedException">the socket type and protocol do not match</exception>
/// <exception cref="TerminatingException">The socket has been stopped.</exception>
/// <remarks>
/// The supported protocols are "inproc", "ipc", "tcp", "pgm", and "epgm".
/// If the protocol is either "pgm" or "epgm", then this socket must be of type Pub, Sub, XPub, or XSub.
/// </remarks>
/// <exception cref="EndpointNotFoundException">The given address was not found in the list of endpoints.</exception>
public void Connect([NotNull] string addr)
{
CheckContextTerminated();
// Process pending commands, if any.
ProcessCommands(0, false);
string address;
string protocol;
DecodeAddress(addr, out address, out protocol);
CheckProtocol(protocol);
if (protocol == Address.InProcProtocol)
{
// TODO: inproc connect is specific with respect to creating pipes
// as there's no 'reconnect' functionality implemented. Once that
// is in place we should follow generic pipe creation algorithm.
// Find the peer endpoint.
Ctx.Endpoint peer = FindEndpoint(addr);
// The total HWM for an inproc connection should be the sum of
// the binder's HWM and the connector's HWM.
var sndhwm = m_options.SendHighWatermark != 0 && peer.Options.ReceiveHighWatermark != 0
? m_options.SendHighWatermark + peer.Options.ReceiveHighWatermark
: 0;
var rcvhwm = m_options.ReceiveHighWatermark != 0 && peer.Options.SendHighWatermark != 0
? m_options.ReceiveHighWatermark + peer.Options.SendHighWatermark
: 0;
// The total LWM for an inproc connection should be the sum of
// the binder's LWM and the connector's LWM.
int sndlwm = m_options.SendLowWatermark != 0 && peer.Options.ReceiveLowWatermark != 0
? m_options.SendLowWatermark + peer.Options.ReceiveLowWatermark
: 0;
int rcvlwm = m_options.ReceiveLowWatermark != 0 && peer.Options.SendLowWatermark != 0
? m_options.ReceiveLowWatermark + peer.Options.SendLowWatermark
: 0;
// Create a bi-directional pipe to connect the peers.
ZObject[] parents = { this, peer.Socket };
int[] highWaterMarks = { sndhwm, rcvhwm };
int[] lowWaterMarks = { sndlwm, rcvlwm };
bool[] delays = { m_options.DelayOnDisconnect, m_options.DelayOnClose };
Pipe[] pipes = Pipe.PipePair(parents, highWaterMarks, lowWaterMarks, delays);
// Attach local end of the pipe to this socket object.
AttachPipe(pipes[0]);
// If required, send the identity of the local socket to the peer.
if (peer.Options.RecvIdentity)
{
var id = new Msg();
id.InitPool(m_options.IdentitySize);
id.Put(m_options.Identity, 0, m_options.IdentitySize);
id.SetFlags(MsgFlags.Identity);
bool written = pipes[0].Write(ref id);
Debug.Assert(written);
pipes[0].Flush();
}
// If required, send the identity of the peer to the local socket.
if (m_options.RecvIdentity)
{
var id = new Msg();
id.InitPool(peer.Options.IdentitySize);
id.Put(peer.Options.Identity, 0, peer.Options.IdentitySize);
id.SetFlags(MsgFlags.Identity);
bool written = pipes[1].Write(ref id);
Debug.Assert(written);
pipes[1].Flush();
}
// Attach remote end of the pipe to the peer socket. Note that peer's
// seqnum was incremented in find_endpoint function. We don't need it
// increased here.
SendBind(peer.Socket, pipes[1], false);
// Save last endpoint URI
m_options.LastEndpoint = addr;
// remember inproc connections for disconnect
m_inprocs.Add(addr, pipes[0]);
//.........这里部分代码省略.........
示例9: PushMsg
/// <summary>
/// Write the given Msg to the pipe.
/// </summary>
/// <param name="msg">the Msg to push to the pipe</param>
/// <returns>true if the Msg was successfully sent</returns>
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;
}
示例10: XHasIn
protected override bool XHasIn()
{
// If we are in the middle of reading the messages, there are
// definitely more parts available.
if (m_moreIn)
return true;
// We may already have a message pre-fetched.
if (m_prefetched)
return true;
// Try to read the next message.
// The message, if read, is kept in the pre-fetch buffer.
var pipe = new Pipe[1];
bool isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref m_prefetchedMsg);
// It's possible that we receive peer's identity. That happens
// after reconnection. The current implementation assumes that
// the peer always uses the same identity.
// TODO: handle the situation when the peer changes its identity.
while (isMessageAvailable && m_prefetchedMsg.IsIdentity)
{
isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref m_prefetchedMsg);
}
if (!isMessageAvailable)
return false;
Debug.Assert(pipe[0] != null);
byte[] identity = pipe[0].Identity;
m_prefetchedId = new Msg();
m_prefetchedId.InitPool(identity.Length);
m_prefetchedId.Put(identity, 0, identity.Length);
m_prefetchedId.SetFlags(MsgFlags.More);
m_prefetched = true;
m_identitySent = false;
return true;
}
示例11: XRecv
/// <summary>
/// Receive a message. The <c>Recv</c> method calls this lower-level method to do the actual receiving.
/// </summary>
/// <param name="msg">the <c>Msg</c> to receive the message into</param>
/// <returns><c>true</c> if the message was received successfully, <c>false</c> if there were no messages to receive</returns>
protected override bool XRecv(ref Msg msg)
{
if (m_prefetched)
{
if (!m_identitySent)
{
msg.Move(ref m_prefetchedId);
m_identitySent = true;
}
else
{
msg.Move(ref m_prefetchedMsg);
m_prefetched = false;
}
m_moreIn = msg.HasMore;
return true;
}
var pipe = new Pipe[1];
bool isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref msg);
// It's possible that we receive peer's identity. That happens
// after reconnection. The current implementation assumes that
// the peer always uses the same identity.
while (isMessageAvailable && msg.IsIdentity)
isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref msg);
if (!isMessageAvailable)
{
return false;
}
Debug.Assert(pipe[0] != null);
// If we are in the middle of reading a message, just return the next part.
if (m_moreIn)
m_moreIn = msg.HasMore;
else
{
// We are at the beginning of a message.
// Keep the message part we have in the prefetch buffer
// and return the ID of the peer instead.
m_prefetchedMsg.Move(ref msg);
m_prefetched = true;
byte[] identity = pipe[0].Identity;
msg.InitPool(identity.Length);
msg.Put(identity, 0, identity.Length);
msg.SetFlags(MsgFlags.More);
m_identitySent = true;
}
return true;
}
示例12: XRecv
/// <summary>
/// Receive a message. The <c>Recv</c> method calls this lower-level method to do the actual receiving.
/// </summary>
/// <param name="msg">the <c>Msg</c> to receive the message into</param>
/// <returns><c>true</c> if the message was received successfully, <c>false</c> if there were no messages to receive</returns>
protected override bool XRecv(ref Msg msg)
{
if (m_prefetched)
{
if (!m_identitySent)
{
msg.Move(ref m_prefetchedId);
m_identitySent = true;
}
else
{
msg.Move(ref m_prefetchedMsg);
m_prefetched = false;
}
return true;
}
var pipe = new Pipe[1];
bool isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref m_prefetchedMsg);
if (!isMessageAvailable)
{
return false;
}
Debug.Assert(pipe[0] != null);
Debug.Assert(!m_prefetchedMsg.HasMore);
// We have received a frame with TCP data.
// Rather than sending this frame, we keep it in prefetched
// buffer and send a frame with peer's ID.
byte[] identity = pipe[0].Identity;
msg.InitPool(identity.Length);
msg.Put(identity, 0, identity.Length);
msg.SetFlags(MsgFlags.More);
m_prefetched = true;
m_identitySent = true;
return true;
}
示例13: XHasIn
protected override bool XHasIn()
{
// We may already have a message pre-fetched.
if (m_prefetched)
return true;
// Try to read the next message.
// The message, if read, is kept in the pre-fetch buffer.
var pipe = new Pipe[1];
bool isMessageAvailable = m_fairQueueing.RecvPipe(pipe, ref m_prefetchedMsg);
if (!isMessageAvailable)
{
return false;
}
Debug.Assert(pipe[0] != null);
Debug.Assert(!m_prefetchedMsg.HasMore);
byte[] identity = pipe[0].Identity;
m_prefetchedId = new Msg();
m_prefetchedId.InitPool(identity.Length);
m_prefetchedId.Put(identity, 0, identity.Length);
m_prefetchedId.SetFlags(MsgFlags.More);
m_prefetched = true;
m_identitySent = false;
return true;
}
示例14: Send
/// <summary>
/// Transmit the given Msg across the message-queueing system.
/// If the msg fails to immediately send, then - if DontWait is specified and no SendTimeout was set
/// then throw an AgainException.
/// </summary>
/// <param name="msg">the Msg to transmit</param>
/// <param name="flags">a SendReceiveOptions: either don't specify DontWait, or set a timeout</param>
/// <exception cref="TerminatingException">The socket has been stopped.</exception>
/// <exception cref="FaultException"><paramref name="msg"/> is not initialised.</exception>
/// <exception cref="AgainException">The send operation timed out.</exception>
public void Send(ref Msg msg, SendReceiveOptions flags)
{
CheckContextTerminated();
// Check whether message passed to the function is valid.
if (!msg.IsInitialised)
throw new FaultException("SocketBase.Send passed an uninitialised Msg.");
// Process pending commands, if any.
ProcessCommands(0, true);
// Clear any user-visible flags that are set on the message.
msg.ResetFlags(MsgFlags.More);
// At this point we impose the flags on the message.
if ((flags & SendReceiveOptions.SendMore) > 0)
msg.SetFlags(MsgFlags.More);
// Try to send the message.
bool isMessageSent = XSend(ref msg);
if (isMessageSent)
return;
// In case of non-blocking send we'll simply propagate
// the error - including EAGAIN - up the stack.
bool isDontWaitSet = (flags & SendReceiveOptions.DontWait) > 0;
if (isDontWaitSet || m_options.SendTimeout == 0)
{
#if DEBUG
string xMsg;
if (isDontWaitSet && m_options.SendTimeout == 0)
xMsg = "SocketBase.Send failed, and DontWait is true AND SendTimeout is 0.";
else if (isDontWaitSet)
xMsg = "SocketBase.Send failed and DontWait is specified.";
else
xMsg = "SocketBase.Send failed and no SendTimeout is specified.";
throw new AgainException(innerException: null, message: xMsg);
#else
throw new AgainException(innerException: null, message: "SocketBase.Send failed");
#endif
}
// Compute the time when the timeout should occur.
// If the timeout is infinite, don't care.
int timeout = m_options.SendTimeout;
long end = timeout < 0 ? 0 : (Clock.NowMs() + timeout);
// Oops, we couldn't send the message. Wait for the next
// command, process it and try to send the message again.
// If timeout is reached in the meantime, return EAGAIN.
while (true)
{
ProcessCommands(timeout, false);
isMessageSent = XSend(ref msg);
if (isMessageSent)
break;
if (timeout <= 0)
continue;
timeout = (int)(end - Clock.NowMs());
if (timeout <= 0)
throw new AgainException(innerException: null, message: "SocketBase.Send failed and timeout <= 0");
}
}