public static CPacket create() { CPacket packet = CPacketBufferManager.pop(); packet.position = Defines.HEADERSIZE; return(packet); }
public static CPacket create(Int16 protocol_id) { //CPacket packet = new CPacket(); CPacket packet = CPacketBufferManager.pop(); packet.set_protocol(protocol_id); return(packet); }
//-------------------------------------------- // //-------------------------------------------- public static CPacket Create(Int16 _code) { //CPacket packet = new CPacket(); CPacket _packet = CPacketBufferManager.Pop(); _packet.WriteCode(_code); Console.WriteLine(" > 풀링된 CPacket 남은수량:{1}", _code, CPacketBufferManager.GetCount()); return(_packet); }
/// <summary> /// 비동기 전송 완료시 호출되는 콜백 매소드. /// </summary> /// <param name="_argsSend"></param> public void SendProcess(SocketAsyncEventArgs _argsSend) { Console.WriteLine(this + " SendProcess _argsSend:" + _argsSend); if (_argsSend.BytesTransferred <= 0 || _argsSend.SocketError != SocketError.Success) { Console.WriteLine("Failed to send. error {0}, transferred {1}", _argsSend.SocketError, _argsSend.BytesTransferred); return; } lock (this.lockQueue) { // count가 0이하일 경우는 없겠지만... if (this.sendingQueue.Count <= 0) { throw new Exception("Sending queue count is less than zero!"); } //todo:재전송 로직 다시 검토~~ 테스트 안해봤음. // 패킷 하나를 다 못보낸 경우는?? int _size = this.sendingQueue.Peek().position; if (_argsSend.BytesTransferred != _size) { string _error = string.Format("Need to send more! transferred {0}, packet size {1}", _argsSend.BytesTransferred, _size); Console.WriteLine(_error); return; } //System.Threading.Interlocked.Increment(ref sent_count); //Debug영역... lock (cs_count) { ++sent_count; //if (sent_count % 20000 == 0) { Console.WriteLine(" > process send : {0}, transferred {1}, sent count {2}", _argsSend.SocketError, _argsSend.BytesTransferred, sent_count); } } // 전송 완료된 패킷을 큐에서 제거한다. //CPacket packet = this.sending_queue.Dequeue(); //CPacket.destroy(packet); CPacket _packet = this.sendingQueue.Dequeue(); CPacketBufferManager.Push(_packet); Console.WriteLine(" > 사용한 CPacket 다시 넣어줌.. 수량:" + CPacketBufferManager.GetCount()); // 아직 전송하지 않은 대기중인 패킷이 있다면 다시한번 전송을 요청한다. if (this.sendingQueue.Count > 0) { StartSend(); } } }
public static void destroy(CPacket packet) { CPacketBufferManager.push(packet); }
public static void Destroy(CPacket _packet) { CPacketBufferManager.Push(_packet); }