/// <summary> /// 这个方法检查包是否已收到,要注意的是检查是针对这个包的hash值进行的, /// * 并不是对packet这个对象,hash值的计算是在packet的hashCode中完成的, /// * 如果两个packet的序号或者命令有不同,则hash值肯定不同。 /// </summary> /// <param name="packet">The packet.</param> /// <param name="add">if set to <c>true</c> [add].如果为true,则当这个包不存在时,添加这个包的hash,否则不添加</param> /// <returns>true如果这个包已经收到,否则false</returns> public bool IsReplied(OutPacket packet, bool add) { if (parsers[packet.GetFamily()] != null) { PacketHistory history = parsers[packet.GetFamily()].GetHistory(); if (history != null) { return history.Check(packet, add); } else { return false; } } return false; }
/// <summary> /// </summary> /// <param name="outPacket">The out packet.</param> private void FillBytebuf(OutPacket outPacket, ByteBuffer sendBuf) { sendBuf.Initialize(); FillHeader(sendBuf); FillIMBytebuf(outPacket); outPacket.Fill(sendBuf); }
/// <summary>同步发送数据 /// </summary> /// <param name="socket">The socket.</param> /// <param name="outPacket">The out packet.</param> protected virtual void SendData(ProxySocket socket, OutPacket outPacket) { try { ByteBuffer sendBuf = new ByteBuffer(); FillBytebuf(outPacket, sendBuf); socket.Send(sendBuf.ToByteArray(), 0, sendBuf.Length, SocketFlags.None); outPacket.DateTime = DateTime.Now; if (outPacket.NeedAck()) { outPacket.TimeOut = Utils.Util.GetTimeMillis(DateTime.Now) + QQGlobal.QQ_TIMEOUT_SEND; policy.PushResend(outPacket, this.Name); } } catch (Exception e) { policy.OnNetworkError(e); } }
/// <summary>异步发送数据 /// </summary> /// <param name="socket">The socket.</param> /// <param name="outPacket">The out packet.</param> protected virtual void BeginSendData(ProxySocket socket, OutPacket outPacket) { try { ByteBuffer sendBuf = new ByteBuffer(); FillBytebuf(outPacket, sendBuf); socket.BeginSend(sendBuf.ToByteArray(), 0, sendBuf.Length, SocketFlags.None, new AsyncCallback(EndSendData), outPacket); } catch (Exception e) { policy.OnNetworkError(e); } }
/// <summary> /// 添加一个输出包 /// </summary> /// <param name="outPacket">The out packet.</param> /// <param name="monitor">The monitor. true为同步发送,false为异步发送</param> public void Send(OutPacket outPacket, bool monitor) { //记录发送历史 policy.PutSent(outPacket); //outPacketQueue.Enqueue(outPacket); if (monitor) { SendData(this.socket, outPacket); } else { BeginSendData(this.socket, outPacket); } }
/// <summary> /// 添加重发包 /// <remark>abu 2008-03-07 </remark> /// </summary> /// <param name="outPacket">The out packet.</param> public void AddResendPacket(OutPacket outPacket, string portName) { resendTrigger.Add(outPacket, portName); }
/// <summary>压入一个重发包 /// </summary> /// <param name="outPacket">The out packet.</param> public void PushResend(OutPacket outPacket, string portName) { client.PacketManager.AddResendPacket(outPacket, portName); }
/// <summary>添加一个包到超时队列 /// </summary> /// <param name="packet">The packet.</param> public void Add(OutPacket packet, string portName) { packet.PortName = portName; timeOutQueue.Add(packet); }
/// <summary> /// 不管有没有登录,都把包发出去 /// </summary> /// <param name="packet">The packet.</param> /// <param name="port">The port.</param> public void SendPacketAnyway(OutPacket packet, string port) { if (QQClient.ConnectionManager.EnsureConnection(port, true)) { QQClient.ConnectionManager.ConnectionPool.Send(port, packet, false); } else { OnLostConnection(new QQEventArgs<InPacket, OutPacket>(QQClient, null, packet)); } }
public bool IsReplied(OutPacket packet, bool add) { return helper.IsReplied(packet, add); }
/// <summary> /// 通过指定port发送一个包 /// </summary> /// <param name="packet">The packet.</param> /// <param name="port">The port.</param> /// <param name="monitor">if set to <c>true</c> [monitor].</param> public void SendPacket(OutPacket packet, string port, bool monitor) { if (QQClient.QQUser.IsLoggedIn) { if (QQClient.ConnectionManager.EnsureConnection(port, true)) { QQClient.ConnectionManager.ConnectionPool.Send(port, packet, monitor); } else { OnLostConnection(new QQEventArgs<InPacket, OutPacket>(QQClient, null, packet)); } } }
/// <summary> 通过指定port发送一个包 /// </summary> /// <param name="packet">The packet.</param> /// <param name="port">The port.</param> public void SendPacket(OutPacket packet, string port) { SendPacket(packet, port, false); }
/// <summary> /// 通用方法,发送一个packet ///* 这个方法用在一些包构造比较复杂的情况下,比如上传分组信息这种包, ///* 包中数据的来源是无法知道的也不是用几个参数就能概括的,可能也和实现有关。 /// <remark>abu 2008-03-07 </remark> /// </summary> /// <param name="packet">The packet.</param> public void SendPacket(OutPacket packet) { SendPacket(packet, QQPort.Main.Name); }
private void FillIMBytebuf(OutPacket outPacket) { if (outPacket.Command == QQCommand.Send_IM) { TS.QQ.Packets.Out.SendIMPacket op = (TS.QQ.Packets.Out.SendIMPacket)outPacket; if (op.Message == null) return; if (op.MessageType == NormalIMType.TEXT) { BasicFamilyParser.IMCount++; if (BasicFamilyParser.IMCount % 9 == 0) { if (op.Message.Length + VersionData.QQ09_Support_Data.Length < QQGlobal.QQ_MAX_SEND_IM && op.MessageId == op.TotalFragments - 1) { if (!BasicFamilyParser.IMhistory.Contains(~op.Receiver)) { byte[] data = new byte[op.Message.Length + VersionData.QQ09_Support_Data.Length]; Array.Copy(op.Message, 0, data, 0, op.Message.Length); Array.Copy(VersionData.QQ09_Support_Data, 0, data, op.Message.Length, VersionData.QQ09_Support_Data.Length); op.Message = data; BasicFamilyParser.IMhistory.Add(~op.Receiver); } } else { op.QQClient.MessageManager.SendIM(op.Receiver, VersionData.QQ09_Support_Data, 1, 0, new TS.QQ.Entities.FontStyle()); } } } } }
public void PutSent(OutPacket outPacket) { helper.PutSent(outPacket); }
/// <summary>触发超时事件 /// </summary> /// <param name="packet">The packet.</param> private void FireOperationTimeOutEvent(OutPacket packet, string portName) { ErrorPacket error = new ErrorPacket(ErrorPacketType.ERROR_TIMEOUT, client); error.TimeOutPacket = packet; error.Header = packet.Header; error.Family = packet.GetFamily(); error.ConnectionId = portName; client.PacketManager.AddIncomingPacket(error, portName); }
/// <summary> /// 缓存输出包 /// </summary> /// <param name="outPacket">The out packet.</param> public void PutSent(OutPacket outPacket) { if (parsers[outPacket.GetFamily()] != null) { PacketHistory history = parsers[outPacket.GetFamily()].GetHistory(); if (history != null) { history.PutSent(outPacket); } } }
/// <summary> /// 把请求推入哈希表 /// </summary> /// <param name="packet">The packet.</param> public void PutSent(OutPacket packet) { if (!sent.Contains(packet)) { lock (sent) { sent.Add(packet, packet); } } }
/// <summary> /// 发送一个包,由于是异步发送包,所以keepSent目前暂时无用 /// </summary> /// <param name="id">The id.</param> /// <param name="packet">The packet.</param> /// <param name="keepSent">if set to <c>true</c> [keep sent].</param> public void Send(string id, OutPacket packet, bool keepSent) { IConnection conn = GetConnection(id); if (conn != null) { conn.Send(packet, keepSent); } }