private void OnSendComplete(object o) { if (this.IsDisposed) { throw new Exception("TChannel已经被Dispose, 不能发送消息"); } SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; UserTokenInfo userTokenInfo = (UserTokenInfo)e.UserToken; if (userTokenInfo.InstanceId != this.InstanceId) { Log.Error($"session disposed!"); return; } if (e.SocketError != SocketError.Success) { this.OnError((int)e.SocketError); return; } this.sendBuffer.FirstIndex += e.BytesTransferred; if (this.sendBuffer.FirstIndex == this.sendBuffer.ChunkSize) { this.sendBuffer.FirstIndex = 0; this.sendBuffer.RemoveFirst(); } this.StartSend(); }
private void OnConnectComplete(object o) { if (this.IsDisposed) { throw new Exception("TChannel已经被Dispose, 不能发送消息"); } SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; UserTokenInfo userTokenInfo = (UserTokenInfo)e.UserToken; if (userTokenInfo.InstanceId != this.InstanceId) { Log.Error($"session disposed!"); return; } if (e.SocketError != SocketError.Success) { this.OnError((int)e.SocketError); return; } e.RemoteEndPoint = null; this.isConnected = true; this.Start(); }
private void OnAcceptComplete(object sender, SocketAsyncEventArgs o) { SocketAsyncEventArgs e = o; UserTokenInfo userTokenInfo = (UserTokenInfo)e.UserToken; if (userTokenInfo.InstanceId != this.InstanceId) { return; } if (e.SocketError != SocketError.Success) { Log.Error($"accept error {e.SocketError}"); return; } TChannel channel = new TChannel(e.AcceptSocket, this); this.idChannels[channel.Id] = channel; try { this.OnAccept(channel); } catch (Exception exception) { Log.Error(exception); } if (userTokenInfo.InstanceId != this.InstanceId) { return; } this.AcceptAsync(); }
private void OnRecvComplete(object o) { if (this.IsDisposed) { throw new Exception("TChannel已经被Dispose, 不能发送消息"); } SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; UserTokenInfo userTokenInfo = (UserTokenInfo)e.UserToken; if (userTokenInfo.InstanceId != this.InstanceId) { Log.Error($"session disposed!"); return; } if (e.SocketError != SocketError.Success) { this.OnError((int)e.SocketError); return; } if (e.BytesTransferred == 0) { this.OnError((int)e.SocketError); return; } this.recvBuffer.LastIndex += e.BytesTransferred; if (this.recvBuffer.LastIndex == this.recvBuffer.ChunkSize) { this.recvBuffer.AddLast(); this.recvBuffer.LastIndex = 0; } // 收到消息回调 while (true) { if (!this.parser.Parse()) { break; } Packet packet = this.parser.GetPacket(); try { this.OnRead(packet); } catch (Exception exception) { Log.Error(exception); } } if (userTokenInfo.InstanceId != this.InstanceId) { return; } this.StartRecv(); }
private void OnConnectComplete(object o) { SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; UserTokenInfo userTokenInfo = (UserTokenInfo)e.UserToken; if (userTokenInfo.InstanceId != this.InstanceId) { return; } if (e.SocketError != SocketError.Success) { Log.Debug("err:%v" + e.SocketError); this.OnError((int)e.SocketError); return; } this.isConnected = true; this.StartSend(); this.StartRecv(); }
private void OnConnectComplete(object o) { SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; UserTokenInfo userTokenInfo = (UserTokenInfo)e.UserToken; if (userTokenInfo.InstanceId != this.InstanceId) { return; } if (e.SocketError != SocketError.Success) { this.OnError((int)e.SocketError); return; } e.RemoteEndPoint = null; this.isConnected = true; this.Start(); }
private void OnSendComplete(object o) { SocketAsyncEventArgs e = (SocketAsyncEventArgs)o; UserTokenInfo userTokenInfo = (UserTokenInfo)e.UserToken; if (userTokenInfo.InstanceId != this.InstanceId) { return; } if (e.SocketError != SocketError.Success) { this.OnError((int)e.SocketError); return; } this.sendBuffer.FirstIndex += e.BytesTransferred; if (this.sendBuffer.FirstIndex == this.sendBuffer.ChunkSize) { this.sendBuffer.FirstIndex = 0; this.sendBuffer.RemoveFirst(); } this.StartSend(); }