private void QueueReceiveAndReadTimeout(Request request) { if (this.ReceiveTimeout.HasValue) { if (this.ReceiveTimeout.Value > TimeSpan.Zero) { ITimerTask receiveTimeoutTask = new IoThreadBoundTimerTask(this, t => OnReceiveTimeoutFired(request)); ITimeout timeout; try { timeout = _timer.NewTimeout(receiveTimeoutTask, this.ReceiveTimeout.Value); } catch (Exception) { throw new TTransportException(TTransportException.ExceptionType.Unknown, "Unable to schedule request timeout"); } request.ReceiveTimeout = timeout; } } if (this.ReadTimeout != null) { long readTimeoutMills = (long)Math.Floor(this.ReadTimeout.Value.TotalMilliseconds); if (readTimeoutMills > 0) { ITimerTask readTimeoutTask = new IoThreadBoundTimerTask(this, new ReadTimeoutTask(readTimeoutMills, request, this)); ITimeout timeout; try { timeout = _timer.NewTimeout(readTimeoutTask, TimeSpan.FromMilliseconds(readTimeoutMills)); } catch (Exception e) { throw new TTransportException($"Unable to schedule read timeout{Environment.NewLine}{e.Message}"); } request.ReadTimeout = timeout; } } }
private void QueueSendTimeout(Request request) { Interlocked.Increment(ref _invoked); if (this.SendTimeout.HasValue) { if (this.SendTimeout > TimeSpan.Zero) { ITimerTask sendTimeoutTask = new IoThreadBoundTimerTask(this, t => OnSendTimeoutFired(request)); ITimeout sendTimeout; try { sendTimeout = _timer.NewTimeout(sendTimeoutTask, this.SendTimeout.Value); } catch (Exception) { throw new TTransportException(TTransportException.ExceptionType.Unknown, "Unable to schedule send timeout"); } request.SendTimeout = sendTimeout; } } }