本文整理汇总了C#中IoSession类的典型用法代码示例。如果您正苦于以下问题:C# IoSession类的具体用法?C# IoSession怎么用?C# IoSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IoSession类属于命名空间,在下文中一共展示了IoSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decode
public void Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
lock (_decoder)
{
_decoder.Decode(session, input, output);
}
}
示例2: IsResponse
public bool IsResponse(IoSession session, object message)
{
var isResponse = false;
var heartbeat = message as DuplexMessage;
if (heartbeat != null) isResponse = heartbeat.Header.MessageType == MessageType.Heartbeat;
return isResponse;
}
示例3: FinishDecode
public void FinishDecode(IoSession session, IProtocolDecoderOutput output)
{
lock (_decoder)
{
_decoder.FinishDecode(session, output);
}
}
示例4: IsRequest
public bool IsRequest(IoSession session, object message)
{
var isRequest = false;
var heartbeat = message as DuplexMessage;
if (heartbeat != null) isRequest = heartbeat.Header.CommandCode == CommandCode.Heartbeat;
return isRequest;
}
示例5: IoFilterEvent
public IoFilterEvent(INextFilter nextFilter, IoEventType eventType, IoSession session, Object parameter)
: base(eventType, session, parameter)
{
if (nextFilter == null)
throw new ArgumentNullException("nextFilter");
_nextFilter = nextFilter;
}
示例6: ExceptionCaught
/// <inheritdoc/>
public virtual void ExceptionCaught(IoSession session, Exception cause)
{
if (log.IsWarnEnabled)
{
log.WarnFormat("EXCEPTION, please implement {0}.ExceptionCaught() for proper handling: {1}", GetType().Name, cause);
}
}
示例7: Decode
public void Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
if (_session == null)
_session = session;
else if (_session != session)
throw new InvalidOperationException(GetType().Name + " is a stateful decoder. "
+ "You have to create one per session.");
_undecodedBuffers.Enqueue(input);
while (true)
{
IoBuffer b;
if (!_undecodedBuffers.TryPeek(out b))
break;
Int32 oldRemaining = b.Remaining;
_state.Decode(b, output);
Int32 newRemaining = b.Remaining;
if (newRemaining != 0)
{
if (oldRemaining == newRemaining)
throw new InvalidOperationException(_state.GetType().Name
+ " must consume at least one byte per decode().");
}
else
{
_undecodedBuffers.TryDequeue(out b);
}
}
}
示例8: SampleCommand
public SampleCommand(
IoSession session,
TimeoutNotifyProducerConsumer<AbstractAsyncCommand> producer)
:base(session, CommandCode.Test, producer)
{
}
示例9: DecodeBody
protected override AbstractMessage DecodeBody(IoSession session, IoBuffer input)
{
if (!_readCode)
{
if (input.Remaining < Constants.RESULT_CODE_LEN)
{
return null; // Need more data.
}
_code = input.GetInt16();
_readCode = true;
}
if (_code == Constants.RESULT_OK)
{
if (input.Remaining < Constants.RESULT_VALUE_LEN)
{
return null;
}
ResultMessage m = new ResultMessage();
m.OK = true;
m.Value = input.GetInt32();
_readCode = false;
return m;
}
else
{
ResultMessage m = new ResultMessage();
m.OK = false;
_readCode = false;
return m;
}
}
示例10: IsConnectionOk
/// <summary>
/// Method responsible for deciding if a connection is OK to continue.
/// </summary>
/// <param name="session">the new session that will be verified</param>
/// <returns>true if the session meets the criteria, otherwise false</returns>
public Boolean IsConnectionOk(IoSession session)
{
IPEndPoint ep = session.RemoteEndPoint as IPEndPoint;
if (ep != null)
{
String addr = ep.Address.ToString();
DateTime now = DateTime.Now;
DateTime? lastConnTime = null;
_clients.AddOrUpdate(addr, now, (k, v) =>
{
if (log.IsDebugEnabled)
log.Debug("This is not a new client");
lastConnTime = v;
return now;
});
if (lastConnTime.HasValue)
{
// if the interval between now and the last connection is
// less than the allowed interval, return false
if ((now - lastConnTime.Value).TotalMilliseconds < _allowedInterval)
{
if (log.IsWarnEnabled)
log.Warn("Session connection interval too short");
return false;
}
}
return true;
}
return false;
}
示例11: Decodable
public MessageDecoderResult Decodable(IoSession session, IoBuffer input)
{
if ((MessageType)input.Get() != MessageType.Update_ZipFiles)
{
return MessageDecoderResult.NotOK;
}
var zipFileInfo = JsonConvert.DeserializeObject<TransferingZipFileInfo>(input.GetString(Encoding.UTF8));
var fileSize = zipFileInfo.FileSize;
var hashBytes = zipFileInfo.HashBytes;
if (input.Remaining < fileSize)
{
return MessageDecoderResult.NeedData;
}
var filesBytes = new byte[fileSize];
input.Get(filesBytes, 0, (int)fileSize);
if (FileHashHelper.CompareHashValue(FileHashHelper.ComputeFileHash(filesBytes), hashBytes))
{
_zipFileInfoMessage = new TransferingZipFile(filesBytes);
return MessageDecoderResult.OK;
}
return MessageDecoderResult.NotOK;
}
示例12: Dispose
public void Dispose(IoSession session)
{
lock (_encoder)
{
_encoder.Dispose(session);
}
}
示例13: Decode
public MessageDecoderResult Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
{
// Try to skip header if not read.
if (!_readHeader)
{
input.GetInt16(); // Skip 'type'.
_sequence = input.GetInt32(); // Get 'sequence'.
_readHeader = true;
}
// Try to decode body
AbstractMessage m = DecodeBody(session, input);
// Return NEED_DATA if the body is not fully read.
if (m == null)
{
return MessageDecoderResult.NeedData;
}
else
{
_readHeader = false; // reset readHeader for the next decode
}
m.Sequence = _sequence;
output.Write(m);
return MessageDecoderResult.OK;
}
示例14: Write
private void Write(IoSession session, IoBuffer data, IoBuffer buf)
{
try
{
Int32 len = data.Remaining;
if (len >= buf.Capacity)
{
/*
* If the request length exceeds the size of the output buffer,
* flush the output buffer and then write the data directly.
*/
INextFilter nextFilter = session.FilterChain.GetNextFilter(this);
InternalFlush(nextFilter, session, buf);
nextFilter.FilterWrite(session, new DefaultWriteRequest(data));
return;
}
if (len > (buf.Limit - buf.Position))
{
InternalFlush(session.FilterChain.GetNextFilter(this), session, buf);
}
lock (buf)
{
buf.Put(data);
}
}
catch (Exception e)
{
session.FilterChain.FireExceptionCaught(e);
}
}
示例15: Put
public void Put(IoSession session)
{
_sessionMap.StartExpiring();
EndPoint key = session.RemoteEndPoint;
if (!_sessionMap.ContainsKey(key))
_sessionMap.Add(key, session);
}