本文整理汇总了C#中Msg.ResetFlags方法的典型用法代码示例。如果您正苦于以下问题:C# Msg.ResetFlags方法的具体用法?C# Msg.ResetFlags怎么用?C# Msg.ResetFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg.ResetFlags方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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="HostUnreachableException">The receiving host must be identifiable.</exception>
protected override bool XSend(ref Msg msg)
{
// If this is the first part of the message it's the ID of the
// peer to send the message to.
if (!m_moreOut)
{
Debug.Assert(m_currentOut == null);
// If we have malformed message (prefix with no subsequent message)
// then just silently ignore it.
// TODO: The connections should be killed instead.
if (msg.HasMore)
{
m_moreOut = true;
// Find the pipe associated with the identity stored in the prefix.
// If there's no such pipe just silently ignore the message, unless
// mandatory is set.
var identity = msg.Size == msg.Data.Length
? msg.Data
: msg.CloneData();
Outpipe op;
if (m_outpipes.TryGetValue(identity, out op))
{
m_currentOut = op.Pipe;
if (!m_currentOut.CheckWrite())
{
op.Active = false;
m_currentOut = null;
if (m_mandatory)
{
m_moreOut = false;
return false;
}
}
}
else if (m_mandatory)
{
m_moreOut = false;
throw new HostUnreachableException("In Router.XSend");
}
}
// Detach the message from the data buffer.
msg.Close();
msg.InitEmpty();
return true;
}
if (m_options.RawSocket)
{
msg.ResetFlags(MsgFlags.More);
}
// Check whether this is the last part of the message.
m_moreOut = msg.HasMore;
// Push the message into the pipe. If there's no out pipe, just drop it.
if (m_currentOut != null)
{
// Close the remote connection if user has asked to do so
// by sending zero length message.
// Pending messages in the pipe will be dropped (on receiving term-ack)
if (m_rawSocket && msg.Size == 0)
{
m_currentOut.Terminate(false);
msg.Close();
msg.InitEmpty();
m_currentOut = null;
return true;
}
bool ok = m_currentOut.Write(ref msg);
if (!ok)
m_currentOut = null;
else if (!m_moreOut)
{
m_currentOut.Flush();
m_currentOut = null;
}
}
else
{
msg.Close();
}
// Detach the message from the data buffer.
msg.InitEmpty();
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="HostUnreachableException">In Stream.XSend</exception>
protected override bool XSend(ref Msg msg)
{
// If this is the first part of the message it's the ID of the
// peer to send the message to.
if (!m_moreOut)
{
Debug.Assert(m_currentOut == null);
// If we have malformed message (prefix with no subsequent message)
// then just silently ignore it.
// TODO: The connections should be killed instead.
if (msg.HasMore)
{
// Find the pipe associated with the identity stored in the prefix.
// If there's no such pipe just silently ignore the message, unless
// mandatory is set.
var identity = msg.Size == msg.Data.Length
? msg.Data
: msg.CloneData();
Outpipe op;
if (m_outpipes.TryGetValue(identity, out op))
{
m_currentOut = op.Pipe;
if (!m_currentOut.CheckWrite())
{
op.Active = false;
m_currentOut = null;
return false;
}
}
else
{
throw new HostUnreachableException("In Stream.XSend");
}
}
m_moreOut = true;
msg.Close();
msg.InitEmpty();
return true;
}
// Ignore the MORE flag
msg.ResetFlags(MsgFlags.More);
// This is the last part of the message.
m_moreOut = false;
// Push the message into the pipe. If there's no out pipe, just drop it.
if (m_currentOut != null)
{
if (msg.Size == 0)
{
m_currentOut.Terminate(false);
m_currentOut = null;
return true;
}
bool ok = m_currentOut.Write(ref msg);
if (ok)
{
m_currentOut.Flush();
}
m_currentOut = null;
}
// Detach the message from the data buffer.
msg.InitEmpty();
return true;
}
示例5: 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");
}
}