public void Send(Packet P) { if (Encryption) { P.Encrypt(); } switch (Settings.ThreadMode) { case Wo1fSocketThreadMode.Async: AsyncSend(P); break; case Wo1fSocketThreadMode.SingleThreaded: Send(P.ToBytes()); break; case Wo1fSocketThreadMode.MultiThreadedEach: //internal tick SQueue.Add(P); break; case Wo1fSocketThreadMode.MultiThreadCount: //wait for external tick SQueue.Add(P); break; } }
private void HandleSends() { if (SQueue.Count == 0) { return; } if (Tcp == null) { return; } if (!Tcp.Client.Connected) { return; } if (SQueue.Count <= 3) { Packet P = SQueue[0]; SQueue.RemoveAt(0); if (P != null) { Send(P.ToBytes()); } } else //backlogged packets, so send faster { CS.SysLog("Backlogged packets. Sending in bulk"); int count = 10; Packet P = SQueue[0]; Packet P2 = SQueue[0]; SQueue.RemoveAt(0); if (P == null) { return; } P.ExtraPacket = true; for (int x = 1; x < count; x++) { if (SQueue.Count == 0) { break; } P.Extras.Add(SQueue[0]); SQueue.RemoveAt(0); } Send(P.ToBytes()); if (P.ExtraPacket) { Stats.packetssent += P.Extras.Count; } } }
private void AsyncSend(Packet P) { if (asyncbusy) { SQueue.Add(P); return; } if (SQueue.Count > 0) { int x = 0; P.ExtraPacket = true; while (x < 10) //x packets at a time or until full(todo: add code to check if full) { if (SQueue.Count == 0) { break; } P.Extras.Add(SQueue[0]); SQueue.RemoveAt(0); x++; } CS.SysLog("Send queue backed up. Sending " + P.Extras.Count + " extra packets."); } asyncbusy = true; byte[] info = P.ToBytes(); try { Tcp.Client.BeginSend(info, 0, info.Length, SocketFlags.None, new AsyncCallback(BeginSendCallback), this); } catch (Exception E) { //OnSendFail CS.SysLog("Packet sending failed"); } asyncbusy = false; this.Stats.packetssent++; if (P.ExtraPacket) { this.Stats.packetssent += P.Extras.Count; } }
private void AsyncSend(Packet P) { if (asyncbusy) { SQueue.Add(P); return; } if (SQueue.Count > 0) { int x = 0; P.ExtraPacket = true; while (x < 10) //x packets at a time or until full(todo: add code to check if full) { if (SQueue.Count == 0) break; P.Extras.Add(SQueue[0]); SQueue.RemoveAt(0); x++; } CS.SysLog("Send queue backed up. Sending " + P.Extras.Count + " extra packets."); } asyncbusy = true; byte[] info = P.ToBytes(); try { Tcp.Client.BeginSend(info, 0, info.Length, SocketFlags.None, new AsyncCallback(BeginSendCallback), this); } catch(Exception E) { //OnSendFail CS.SysLog("Packet sending failed"); } asyncbusy = false; this.Stats.packetssent++; if (P.ExtraPacket) this.Stats.packetssent += P.Extras.Count; }
public void Send(Packet P) { if(Encryption) P.Encrypt(); switch (Settings.ThreadMode) { case Wo1fSocketThreadMode.Async: AsyncSend(P); break; case Wo1fSocketThreadMode.SingleThreaded: Send(P.ToBytes()); break; case Wo1fSocketThreadMode.MultiThreadedEach: //internal tick SQueue.Add(P); break; case Wo1fSocketThreadMode.MultiThreadCount: //wait for external tick SQueue.Add(P); break; } }