• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IoSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中IoSession的典型用法代码示例。如果您正苦于以下问题:C# IoSession类的具体用法?C# IoSession怎么用?C# IoSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IoSession类属于命名空间,在下文中一共展示了IoSession类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Decode

 public void Decode(IoSession session, IoBuffer input, IProtocolDecoderOutput output)
 {
     lock (_decoder)
     {
         _decoder.Decode(session, input, output);
     }
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:7,代码来源:SynchronizedProtocolDecoder.cs


示例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;
 }
开发者ID:zesus19,项目名称:c5.v1,代码行数:7,代码来源:KeepAliveMessageFactory.cs


示例3: FinishDecode

 public void FinishDecode(IoSession session, IProtocolDecoderOutput output)
 {
     lock (_decoder)
     {
         _decoder.FinishDecode(session, output);
     }
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:7,代码来源:SynchronizedProtocolDecoder.cs


示例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;
 }
开发者ID:zesus19,项目名称:c5.v1,代码行数:7,代码来源:KeepAliveMessageFactory.cs


示例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;
 }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:7,代码来源:IoFilterEvent.cs


示例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);
     }
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:8,代码来源:IoHandlerAdapter.cs


示例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);
                }
            }
        }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:30,代码来源:DecodingStateProtocolDecoder.cs


示例8: SampleCommand

      public SampleCommand(
          IoSession session,
          TimeoutNotifyProducerConsumer<AbstractAsyncCommand> producer)
          :base(session, CommandCode.Test, producer)
      {
 
      }
开发者ID:zesus19,项目名称:c5.v1,代码行数:7,代码来源:SampleCommand.cs


示例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;
            }
        }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:34,代码来源:ResultMessageDecoder.cs


示例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;
        }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:39,代码来源:ConnectionThrottleFilter.cs


示例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;
        }
开发者ID:AnchoretTeam,项目名称:AppUpdate,代码行数:25,代码来源:TransferingZipFileProtocolDecoder.cs


示例12: Dispose

 public void Dispose(IoSession session)
 {
     lock (_encoder)
     {
         _encoder.Dispose(session);
     }
 }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:7,代码来源:SynchronizedProtocolEncoder.cs


示例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;
        }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:26,代码来源:AbstractMessageDecoder.cs


示例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);
            }
        }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:31,代码来源:BufferedWriteFilter.cs


示例15: Put

 public void Put(IoSession session)
 {
     _sessionMap.StartExpiring();
     EndPoint key = session.RemoteEndPoint;
     if (!_sessionMap.ContainsKey(key))
         _sessionMap.Add(key, session);
 }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:7,代码来源:ExpiringSessionRecycler.cs


示例16: Encode

 public void Encode(IoSession session, Object message, IProtocolEncoderOutput output)
 {
     lock (_encoder)
     {
         _encoder.Encode(session, message, output);
     }
 }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:7,代码来源:SynchronizedProtocolEncoder.cs


示例17: MessageReceived

        /// <inheritdoc/>
        public override void MessageReceived(INextFilter nextFilter, IoSession session, Object message)
        {
            //if (log.IsDebugEnabled)
            //    log.DebugFormat("Processing a MESSAGE_RECEIVED for session {0}", session.Id);

            IoBuffer input = message as IoBuffer;
            if (input == null)
            {
                nextFilter.MessageReceived(session, message);
                return;
            }

            IProtocolDecoder decoder = _factory.GetDecoder(session);
            IProtocolDecoderOutput decoderOutput = GetDecoderOut(session, nextFilter);

            // Loop until we don't have anymore byte in the buffer,
            // or until the decoder throws an unrecoverable exception or
            // can't decoder a message, because there are not enough
            // data in the buffer
            while (input.HasRemaining)
            {
                Int32 oldPos = input.Position;
                try
                {
                    // TODO may not need lock on UDP
                    lock (session)
                    {
                        // Call the decoder with the read bytes
                        decoder.Decode(session, input, decoderOutput);
                    }

                    // Finish decoding if no exception was thrown.
                    decoderOutput.Flush(nextFilter, session);
                }
                catch (Exception ex)
                {
                    ProtocolDecoderException pde = ex as ProtocolDecoderException;
                    if (pde == null)
                        pde = new ProtocolDecoderException(null, ex);
                    if (pde.Hexdump == null)
                    {
                        // Generate a message hex dump
                        Int32 curPos = input.Position;
                        input.Position = oldPos;
                        pde.Hexdump = input.GetHexDump();
                        input.Position = curPos;
                    }

                    decoderOutput.Flush(nextFilter, session);
                    nextFilter.ExceptionCaught(session, pde);

                    // Retry only if the type of the caught exception is
                    // recoverable and the buffer position has changed.
                    // We check buffer position additionally to prevent an
                    // infinite loop.
                    if (!(ex is RecoverableProtocolDecoderException) || input.Position == oldPos)
                        break;
                }
            }
        }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:61,代码来源:ProtocolCodecFilter.cs


示例18: MessageSent

 /// <inheritdoc/>
 public override void MessageSent(INextFilter nextFilter, IoSession session, IWriteRequest writeRequest)
 {
     if (IsBlocked(session))
         BlockSession(session);
     else
         // forward if not blocked
         base.MessageSent(nextFilter, session, writeRequest);
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:9,代码来源:BlacklistFilter.cs


示例19: MessageReceived

 /// <inheritdoc/>
 public override void MessageReceived(INextFilter nextFilter, IoSession session, Object message)
 {
     if (IsBlocked(session))
         BlockSession(session);
     else
         // forward if not blocked
         base.MessageReceived(nextFilter, session, message);
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:9,代码来源:BlacklistFilter.cs


示例20: SessionIdle

 /// <inheritdoc/>
 public override void SessionIdle(INextFilter nextFilter, IoSession session, IdleStatus status)
 {
     if (IsBlocked(session))
         BlockSession(session);
     else
         // forward if not blocked
         base.SessionIdle(nextFilter, session, status);
 }
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:9,代码来源:BlacklistFilter.cs



注:本文中的IoSession类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IocContainer类代码示例发布时间:2022-05-24
下一篇:
C# InvokeOptions类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap