bool HandleUpgrade(IAsyncResult result) { connection = ConnectionUpgradeHelper.EndInitiateUpgrade(result); if (this.channelBindingProvider != null && this.channelBindingProvider.IsChannelBindingSupportEnabled) { this.channel.channelBindingToken = this.channelBindingProvider.GetChannelBinding(this.upgradeInitiator, ChannelBindingKind.Endpoint); } this.remoteSecurity = StreamSecurityUpgradeInitiator.GetRemoteSecurity(this.upgradeInitiator); this.upgradeInitiator = null; // we're done with the initiator if (onWritePreambleEnd == null) { onWritePreambleEnd = Fx.ThunkCallback(new WaitCallback(OnWritePreambleEnd)); } AsyncCompletionResult writePreambleResult = connection.BeginWrite( ClientSingletonEncoder.PreambleEndBytes, 0, ClientSingletonEncoder.PreambleEndBytes.Length, true, timeoutHelper.RemainingTime(), onWritePreambleEnd, this); if (writePreambleResult == AsyncCompletionResult.Queued) { return(false); } connection.EndWrite(); return(ReadPreambleAck()); }
public WriteAsyncResult(IConnection connection, byte[] buffer, int offset, int count, bool immediate, TimeSpan timeout, AsyncCallback callback, object state) : base(connection, callback, state) { AsyncCompletionResult writeResult = connection.BeginWrite(buffer, offset, count, immediate, timeout, GetWaitCompletion(), this); if (writeResult == AsyncCompletionResult.Completed) { HandleIO(connection); base.Complete(true); } }
bool ReadPreambleAck() { AsyncCompletionResult readAckResult = connection.BeginRead(0, 1, timeoutHelper.RemainingTime(), onReadPreambleAck, this); if (readAckResult == AsyncCompletionResult.Queued) { return(false); } return(HandlePreambleAck()); }
public override Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource <int>(this); AsyncCompletionResult asyncCompletionResult = _connection.BeginRead(0, Math.Min(count, _connection.AsyncReadBufferSize), TimeoutHelper.FromMilliseconds(this.ReadTimeout), s_onReadComplete, tcs); if (asyncCompletionResult == AsyncCompletionResult.Completed) { tcs.TrySetResult(_connection.EndRead()); } return(tcs.Task); }
protected override async Task CloseOutputSessionCoreAsync(TimeSpan timeout) { var tcs = new TaskCompletionSource <bool>(); AsyncCompletionResult result = Connection.BeginWrite(SessionEncoder.EndBytes, 0, SessionEncoder.EndBytes.Length, true, timeout, OnIoComplete, tcs); if (result == AsyncCompletionResult.Completed) { tcs.TrySetResult(true); } await tcs.Task; Connection.EndWrite(); }
public ReadAsyncResult(IConnection connection, byte[] buffer, int offset, int count, TimeSpan timeout, AsyncCallback callback, object state) : base(connection, callback, state) { this.buffer = buffer; this.offset = offset; AsyncCompletionResult readResult = connection.BeginRead(0, Math.Min(count, connection.AsyncReadBufferSize), timeout, GetWaitCompletion(), this); if (readResult == AsyncCompletionResult.Completed) { HandleIO(connection); base.Complete(true); } }
public override async Task <int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource <int>(this); AsyncCompletionResult asyncCompletionResult = connection.BeginRead(0, Math.Min(count, connection.AsyncReadBufferSize), TimeoutHelper.FromMilliseconds(ReadTimeout), s_onReadComplete, tcs); if (asyncCompletionResult == AsyncCompletionResult.Completed) { tcs.TrySetResult(connection.EndRead()); } int bytesRead = await tcs.Task; Buffer.BlockCopy(connection.AsyncReadBuffer, 0, buffer, offset, bytesRead); return(bytesRead); }
public SendPreambleAsyncResult(StreamedFramingRequestChannel channel, IConnection connection, ref TimeoutHelper timeoutHelper, ClientFramingDecoder decoder, AsyncCallback callback, object state) : base(callback, state) { this.channel = channel; this.connection = connection; this.timeoutHelper = timeoutHelper; this.decoder = decoder; AsyncCompletionResult writePreambleResult = connection.BeginWrite(channel.Preamble, 0, channel.Preamble.Length, true, timeoutHelper.RemainingTime(), onWritePreamble, this); if (writePreambleResult == AsyncCompletionResult.Queued) { return; } if (HandleWritePreamble()) { base.Complete(true); } }
bool WriteEndBytes() { // check again in case we faulted while we were waiting for the lock this.channel.ThrowIfFaulted(); // we're synchronized by sendLock here if (this.channel.isOutputSessionClosed) { return(true); } this.channel.isOutputSessionClosed = true; AsyncCompletionResult completionResult = this.channel.BeginCloseOutput(this.timeoutHelper.RemainingTime(), onWriteComplete, this); if (completionResult == AsyncCompletionResult.Queued) { return(false); } this.HandleWriteEndBytesComplete(); return(true); }