本文整理汇总了C#中IoSession.SetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# IoSession.SetAttribute方法的具体用法?C# IoSession.SetAttribute怎么用?C# IoSession.SetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IoSession
的用法示例。
在下文中一共展示了IoSession.SetAttribute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SessionOpened
/// <inheritdoc/>
public override void SessionOpened(IoSession session)
{
// Set timeouts
session.Config.WriteTimeout = _writeTimeout;
session.Config.SetIdleTime(IdleStatus.ReaderIdle, _readTimeout);
// Create streams
IoSessionStream input = new IoSessionStream();
IoSessionStream output = new IoSessionStream(session);
session.SetAttribute(KEY_IN, input);
session.SetAttribute(KEY_OUT, output);
ProcessStreamIo(session, input, output);
}
示例2: SessionCreated
public override void SessionCreated(INextFilter nextFilter, IoSession session)
{
foreach (KeyValuePair<String, Object> pair in _attributes)
{
session.SetAttribute(pair.Key, pair.Value);
}
base.SessionCreated(nextFilter, session);
}
示例3: ExceptionCaught
public override void ExceptionCaught(INextFilter nextFilter, IoSession session, Exception cause)
{
Log.Error(ErrorCode.UnhandledExceptionCaught, cause);
var counter = session.GetAttribute<int>(KeyName.SESSION_ERROR_COUNTER);
if (counter >= MAX_UNCAUGHT_SESSION_ERROR_COUNT) session.Close(true);
else
{
session.SetAttribute(KeyName.SESSION_ERROR_COUNTER, ++counter);
base.ExceptionCaught(nextFilter, session, cause);
}
}
示例4: MessageReceived
public override void MessageReceived(INextFilter nextFilter, IoSession session, object message)
{
List<String> phrases = session.GetAttribute<List<String>>("phrases");
if (null == phrases)
{
phrases = new List<String>();
session.SetAttribute("phrases", phrases);
}
phrases.Add((String)message);
if (phrases.Count == 3)
{
session.RemoveAttribute("phrases");
base.MessageReceived(nextFilter, session, new Haiku(phrases
.ToArray()));
}
}
示例5: MarkStatus
private void MarkStatus(IoSession session)
{
session.Config.SetIdleTime(_interestedIdleStatus, 0);
session.Config.ReaderIdleTime = RequestTimeout;
session.SetAttribute(WAITING_FOR_RESPONSE);
}
示例6: SessionIdle
/// <inheritdoc/>
public override void SessionIdle(INextFilter nextFilter, IoSession session, IdleStatus status)
{
if (status == _interestedIdleStatus)
{
if (!session.ContainsAttribute(WAITING_FOR_RESPONSE))
{
Object pingMessage = _messageFactory.GetRequest(session);
if (pingMessage != null)
{
nextFilter.FilterWrite(session, new DefaultWriteRequest(pingMessage));
//session.Write(pingMessage);
// If policy is OFF, there's no need to wait for
// the response.
if (_requestTimeoutHandler != KeepAliveRequestTimeoutHandler.DeafSpeaker)
{
MarkStatus(session);
if (_interestedIdleStatus == IdleStatus.BothIdle)
{
session.SetAttribute(IGNORE_READER_IDLE_ONCE);
}
}
else
{
ResetStatus(session);
}
}
}
else
{
HandlePingTimeout(session);
}
}
else if (status == IdleStatus.ReaderIdle)
{
if (session.RemoveAttribute(IGNORE_READER_IDLE_ONCE) == null)
{
if (session.ContainsAttribute(WAITING_FOR_RESPONSE))
{
HandlePingTimeout(session);
}
}
}
if (_forwardEvent)
nextFilter.SessionIdle(session, status);
}
示例7: GetContext
private Context GetContext(IoSession session)
{
Context ctx = session.GetAttribute<Context>(CONTEXT);
if (ctx == null)
{
ctx = new Context(this);
session.SetAttribute(CONTEXT, ctx);
}
return ctx;
}
示例8: Decode
/// <inheritdoc/>
public override void Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
if (!session.TransportMetadata.HasFragmentation)
{
while (input.HasRemaining)
{
if (!DoDecode(session, input, output))
break;
}
return;
}
Boolean usingSessionBuffer = true;
IoBuffer buf = session.GetAttribute<IoBuffer>(BUFFER);
// If we have a session buffer, append data to that; otherwise
// use the buffer read from the network directly.
if (buf == null)
{
buf = input;
usingSessionBuffer = false;
}
else
{
Boolean appended = false;
// Make sure that the buffer is auto-expanded.
if (buf.AutoExpand)
{
try
{
buf.Put(input);
appended = true;
}
catch (InvalidOperationException)
{
// A user called derivation method (e.g. slice()),
// which disables auto-expansion of the parent buffer.
}
catch (OverflowException)
{
// A user disabled auto-expansion.
}
}
if (appended)
{
buf.Flip();
}
else
{
// Reallocate the buffer if append operation failed due to
// derivation or disabled auto-expansion.
buf.Flip();
IoBuffer newBuf = IoBuffer.Allocate(buf.Remaining + input.Remaining);
newBuf.AutoExpand = true;
newBuf.Order = buf.Order;
newBuf.Put(buf);
newBuf.Put(input);
newBuf.Flip();
buf = newBuf;
// Update the session attribute.
session.SetAttribute(BUFFER, buf);
}
}
while (true)
{
Int32 oldPos = buf.Position;
Boolean decoded = DoDecode(session, buf, output);
if (decoded)
{
if (buf.Position == oldPos)
throw new InvalidOperationException("DoDecode() can't return true when buffer is not consumed.");
if (!buf.HasRemaining)
break;
}
else
{
break;
}
}
// if there is any data left that cannot be decoded, we store
// it in a buffer in the session and next time this decoder is
// invoked the session buffer gets appended to
if (buf.HasRemaining)
{
if (usingSessionBuffer && buf.AutoExpand)
{
buf.Compact();
}
else
{
StoreRemainingInSession(buf, session);
}
}
//.........这里部分代码省略.........
示例9: StoreRemainingInSession
private void StoreRemainingInSession(IoBuffer buf, IoSession session)
{
IoBuffer remainingBuf = IoBuffer.Allocate(buf.Capacity);
remainingBuf.AutoExpand = true;
remainingBuf.Order = buf.Order;
remainingBuf.Put(buf);
session.SetAttribute(BUFFER, remainingBuf);
}
示例10: SessionCreated
public override void SessionCreated(IoSession session)
{
session.SetAttribute("pos", 0);
session.SetAttribute("received", new StringBuilder());
session.SetAttribute("sent", new StringBuilder());
session.SetAttribute("lock", new Object());
}
示例11: Read
private Char Read(IoSession session)
{
Int32 pos = session.GetAttribute<Int32>("pos");
for (Int32 i = 0; i < 10 && pos == GetReceived(session).Length; i++)
{
Object sync = session.GetAttribute("lock");
lock (sync)
{
Monitor.Wait(sync, 200);
}
}
session.SetAttribute("pos", pos + 1);
String received = GetReceived(session);
Assert.IsTrue(received.Length > pos);
return GetReceived(session)[pos];
}
示例12: GetEncoderOut
private IProtocolEncoderOutput GetEncoderOut(IoSession session, INextFilter nextFilter, IWriteRequest writeRequest)
{
IProtocolEncoderOutput output = session.GetAttribute<IProtocolEncoderOutput>(ENCODER_OUT);
if (output == null)
{
// Create a new instance, and stores it into the session
output = new ProtocolEncoderOutputImpl(session, nextFilter, writeRequest);
session.SetAttribute(ENCODER_OUT, output);
}
return output;
}
示例13: GetDecoderOut
private IProtocolDecoderOutput GetDecoderOut(IoSession session, INextFilter nextFilter)
{
IProtocolDecoderOutput output = session.GetAttribute<IProtocolDecoderOutput>(DECODER_OUT);
if (output == null)
{
// Create a new instance, and stores it into the session
output = new ProtocolDecoderOutputImpl();
session.SetAttribute(DECODER_OUT, output);
}
return output;
}
示例14: MessageReceived
public override void MessageReceived(INextFilter nextFilter, IoSession session, object message)
{
base.MessageReceived(nextFilter, session, message);
session.SetAttribute(KeyName.SESSION_ERROR_COUNTER, 0);
}