本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}