当前位置: 首页>>代码示例>>C#>>正文


C# IConnection.BeginDisconnect方法代码示例

本文整理汇总了C#中IConnection.BeginDisconnect方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.BeginDisconnect方法的具体用法?C# IConnection.BeginDisconnect怎么用?C# IConnection.BeginDisconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConnection的用法示例。


在下文中一共展示了IConnection.BeginDisconnect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectToZookeeper

        /// <summary>
        /// connect to zookeeper
        /// </summary>
        /// <param name="name"></param>
        /// <param name="connection"></param>
        private void ConnectToZookeeper(string name, IConnection connection)
        {
            var connectRequest = new Data.ConnectRequest(this._protocolVersion,
                this._zkClient._lastZxid,
                (int)this._zkClient._sessionTimeout.TotalMilliseconds,
                this._sessionID,
                this._sessionPassword);

            var request = new Request<ZookResponse>(this._zkClient.NextRequestSeqID(), "connect",
                Utils.Marshaller.Serialize(connectRequest, true),
                ex => connection.BeginDisconnect(ex),
                response =>
                {
                    Data.ConnectResponse result = null;
                    try { result = Utils.Marshaller.Deserialize<Data.ConnectResponse>(response.Payload); }
                    catch (Exception ex) { connection.BeginDisconnect(ex); return; }

                    if (result.SessionTimeOut <= 0)//session expired
                    {
                        this._protocolVersion = 0;
                        this._sessionID = 0;
                        this._negotiatedSessionTimeout = 0;
                        this._sessionPassword = new byte[16];

                        connection.BeginDisconnect(new ApplicationException("zookeeper session expired"));
                        this._zkClient.SetKeeperState(Data.KeeperState.Expired); return;
                    }

                    this._protocolVersion = result.ProtocolVersion;
                    this._negotiatedSessionTimeout = result.SessionTimeOut;
                    this._sessionID = result.SessionID;
                    this._sessionPassword = result.SessionPassword;

                    this._currConnection = connection;
                    this._zkClient.SetKeeperState(Data.KeeperState.SyncConnected);
                    this.FireServerAvailable(name, connection);
                }) { Tag = "connect" };

            connection.UserData = request;
            connection.BeginSend(request);
        }
开发者ID:tokenian,项目名称:Zookeeper.Net,代码行数:46,代码来源:ZookServerPool.cs

示例2: OnMessageReceived

        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int readLength;
            RedisResponse response = null;
            try { response = this._protocol.FindResponse(connection, e.Buffer, out readLength); }
            catch (Exception ex)
            {
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            this.OnResponse(response);
            e.SetReadlength(readLength);
        }
开发者ID:dut3062796s,项目名称:Redis.Driver.Net,代码行数:22,代码来源:RedisSubscriber.cs

示例3: listener_Accepted

 /// <summary>
 /// socket accepted handler
 /// </summary>
 /// <param name="listener"></param>
 /// <param name="connection"></param>
 private void listener_Accepted(ISocketListener listener, IConnection connection)
 {
     if (base._listConnections.Count() > this._maxConnections)
     {
         connection.BeginDisconnect(); return;
     }
     base.RegisterConnection(connection);
 }
开发者ID:zhujunxxxxx,项目名称:FastNetwork,代码行数:13,代码来源:SocketServer.cs

示例4: OnMessageReceived

        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int readlength;
            Object response = null;
            ReceivePacket packet = null;
            try
            {
                packet = this._protocol.TryToTranslateMessage(connection, e.Buffer,DefaultConfigure.MaxMessageSize, out readlength);
            }
            catch (Exception ex)
            {
                this.OnError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            if (response != null)
            {
                this.OnResponse(connection, response);
            }
            e.SetReadlength(readlength);
        }
开发者ID:zhujunxxxxx,项目名称:FastNetwork,代码行数:30,代码来源:BaseSocketClient.cs

示例5: OnMessageReceived

        /// <summary>
        /// OnMessageReceived
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="e"></param>
        protected override void OnMessageReceived(IConnection connection, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(connection, e);

            int readlength=0;
            ReceivePacket packet = null;
            Object obj = null;//解析的对象
            try
            {
                packet = this._protocol.TryToTranslateMessage(connection, e.Buffer, this._maxMessageSize, out readlength);
                if (packet == null)
                    return;
                obj = this._decoder.decode(connection, packet.Buffer);
            }
            catch (Exception ex)
            {
                this.OnError(connection, ex);
                connection.BeginDisconnect(ex);
                e.SetReadlength(e.Buffer.Count);
                return;
            }

            if (packet != null)
                ThreadPool.QueueUserWorkItem(_ =>
                {
                    try { this._handler.OnReceived(connection, obj); }
                    catch (Exception ex) { Log.Trace.Error(ex.Message, ex); }
                });
            e.SetReadlength(readlength);
        }
开发者ID:zhujunxxxxx,项目名称:FastNetwork,代码行数:35,代码来源:SocketServer.cs


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