public void Send(CommandForClient command) { if (this._IsClosed) { return; } lock (this._QueueLock) { this._Queue.Enqueue(command); if (!_IsSendingData) { this._IsSendingData = true; Write(); } } }
public void SendCommand(QuotationCommand quotationCommand=null,Command command =null) { if (_ClientsProcessor.IsEmpty()) return; var target = new CommandForClient(quotationCommand:quotationCommand,command:command); _CommandTransfer.Send(target); }
private void Write() { try { lock (this._QueueLock) { if (this._Queue.Count == 0) { this._IsSendingData = false; return; } this._CurrentCommand = this._Queue.Dequeue(); if (this._CurrentCommand.CommandType == DataType.Command) { WriteForCommand(); } else if (this._CurrentCommand.CommandType == DataType.Response) { this._CurrentPacket = this._CurrentCommand.Data; this.BeginWrite(this._CurrentPacket, 0, this._CurrentPacket.Length); } else if (this._CurrentCommand.CommandType == DataType.Quotation) { WriteForQuotation(); } else { throw new ArgumentException(string.Format("Unrecognize DataType:{0}", this._CurrentCommand.CommandType)); } } } catch (Exception ex) { _Logger.Error("Write",ex); this.Close(); } }
public void Send(CommandForClient command) { _Commands.Enqueue(command); _SendQuotationEvent.Set(); }