public void Send(Message message, TimeSpan timeout) { ThrowIfDisposedOrNotOpen(); if (!this.sendingDone.WaitOne(TimeoutHelper.ToMilliseconds(timeout), false)) { throw new TimeoutException("Send timed out waiting for the previous message send to complete"); } lock (base.ThisLock) // synchronized state transitions are not allowed while sending { ThrowIfDisposedOrNotOpen(); if (this.operationParams.Contains(message.Headers.Action)) { TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); this.sendingDone.Reset(); ChunkingWriter writer = new ChunkingWriter(message, timeoutHelper, innerChannel); message.WriteBodyContents(writer); this.sendingDone.Set(); } else { //passthrough innerChannel.Send(message, timeout); } } }
public Message Receive(TimeSpan timeout) { ThrowIfDisposedOrNotOpen(); //if we're receiving chunks, wait till that's done TimeoutHelper helper = new TimeoutHelper(timeout); if (!this.currentMessageCompleted.WaitOne(TimeoutHelper.ToMilliseconds(timeout), false)) { throw new TimeoutException("Receive timed out waiting for previous message receive to complete"); } //call receive on inner channel Message message = innerChannel.Receive(helper.RemainingTime()); if (message != null && message.Headers.Action == ChunkingUtils.ChunkAction) { this.currentInputMessage = GetNewChunkingMessage(message, helper); //start receiving chunks again ThreadPool.QueueUserWorkItem(new WaitCallback(this.ReceiveChunkLoop), helper); return(currentInputMessage); } else { this.currentMessageCompleted.Set(); return(message); } }
public virtual bool TryEnqueue(TimeoutHelper timeout, TItem item) { if (this.SpaceAvailableEvent.WaitOne(TimeoutHelper.ToMilliseconds(timeout.RemainingTime()), false)) { this.Enqueue(item); return(true); } else { return(false); } }
public virtual bool TryDequeue(TimeoutHelper timeout, out TItem item) { item = null; if (this.ItemAvailableEvent.WaitOne(TimeoutHelper.ToMilliseconds(timeout.RemainingTime()), false)) { item = this.Dequeue(); return(item != null); } else { return(false); } }
protected override void OnClose(TimeSpan timeout) { //wait for receive to stop so we can have a clean shutdown TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); if (this.receiveStopped.WaitOne(TimeoutHelper.ToMilliseconds(timeoutHelper.RemainingTime()), false)) { innerChannel.Close(timeoutHelper.RemainingTime()); } else { throw new TimeoutException("Close timeout exceeded"); } //we don't call base.OnClose because it does nothing }
public void SetTimer(TimerCallback callback, Object state) { Timer timer = new Timer(callback, state, TimeoutHelper.ToMilliseconds(this.RemainingTime()), Timeout.Infinite); }