public virtual void SendSimulatedPacket(PacketSimulation p) { if (m_Socket == null || m_BlockAllPackets) { return; } byte[] buffer = p.ProcessedBytes; if (buffer != null) { if (buffer.Length <= 0) { return; } try { SendQueue.Gram gram; lock (m_SendQueue) { gram = m_SendQueue.Enqueue(buffer, buffer.Length); } if (gram != null) { #if NewAsyncSockets m_SendEventArgs.SetBuffer(gram.Buffer, 0, gram.Length); Send_Start(); #else try { m_Socket.BeginSend(gram.Buffer, 0, gram.Length, SocketFlags.None, m_OnSend, m_Socket); } catch (Exception ex) { TraceException(ex); Dispose(false); } #endif } } catch (CapacityExceededException) { Console.WriteLine("Client: {0}: Too much data pending, disconnecting...", this); Dispose(false); } } else { Console.WriteLine("Client: {0}: null buffer send, disconnecting...", this); using (StreamWriter op = new StreamWriter("null_send.log", true)) { op.WriteLine("{0} Client: {1}: null buffer send, disconnecting...", DateTime.UtcNow, this); op.WriteLine(new System.Diagnostics.StackTrace()); } Dispose(); } }
public void ReceiveSimulatedPacket(PacketSimulation packetSimulation) { try { byte[] buffer = packetSimulation.ProcessedBytes; if (buffer.Length > 0) { m_NextCheckActivity = DateTime.UtcNow + TimeSpan.FromMinutes(1.2); if (!m_Disposing) { lock (m_Buffer) m_Buffer.Enqueue(buffer, 0, buffer.Length); m_MessagePump.OnReceive(this); lock (m_AsyncLock) { m_AsyncState &= ~AsyncState.Pending; if ((m_AsyncState & AsyncState.Paused) == 0) { try { InternalBeginReceive(); } catch (Exception ex) { TraceException(ex); Dispose(false); } } } } } else { Dispose(false); } } catch { Dispose(false); } }