private void EndConnectCore(Socket socket, IAsyncResult asyncResult) => TaskToApm.End(asyncResult);
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { var task = WriteAsync(buffer, offset, count, default(CancellationToken), state); return(TaskToApm.Begin(task, callback, state)); }
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => TaskToApm.Begin(ReadAsync(buffer, offset, count, CancellationToken.None), callback, state);
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) => TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState);
// IO COMPLETION CALLBACK // // This callback is responsible for getting the complete protocol frame. // 1. it reads the header. // 2. it determines the frame size. // 3. loops while not all frame received or an error. // private void ReadFrameComplete(IAsyncResult transportResult) { do { if (!(transportResult.AsyncState is WorkerAsyncResult)) { NetEventSource.Fail(this, $"The state expected to be WorkerAsyncResult, received {transportResult}."); } WorkerAsyncResult workerResult = (WorkerAsyncResult)transportResult.AsyncState; int bytesRead = TaskToApm.End <int>(transportResult); workerResult.Offset += bytesRead; if (!(workerResult.Offset <= workerResult.End)) { NetEventSource.Fail(this, $"WRONG: offset - end = {workerResult.Offset - workerResult.End}"); } if (bytesRead <= 0) { // (by design) This indicates the stream has receives EOF // If we are in the middle of a Frame - fail, otherwise - produce EOF object result = null; if (!workerResult.HeaderDone && workerResult.Offset == 0) { result = (object)-1; } else { result = new System.IO.IOException(SR.net_frame_read_io); } workerResult.InvokeCallback(result); return; } if (workerResult.Offset >= workerResult.End) { if (!workerResult.HeaderDone) { workerResult.HeaderDone = true; // This indicates the header has been read successfully _curReadHeader.CopyFrom(workerResult.Buffer, 0, _readVerifier); int payloadSize = _curReadHeader.PayloadSize; if (payloadSize < 0) { // Let's call user callback and he call us back and we will throw workerResult.InvokeCallback(new System.IO.IOException(SR.Format(SR.net_frame_read_size))); } if (payloadSize == 0) { // report empty frame (NOT eof!) to the caller, he might be interested in workerResult.InvokeCallback(0); return; } if (payloadSize > _curReadHeader.MaxMessageSize) { throw new InvalidOperationException(SR.Format(SR.net_frame_size, _curReadHeader.MaxMessageSize.ToString(NumberFormatInfo.InvariantInfo), payloadSize.ToString(NumberFormatInfo.InvariantInfo))); } // Start reading the remaining frame data (note header does not count). byte[] frame = new byte[payloadSize]; // Save the ref of the data block workerResult.Buffer = frame; workerResult.End = frame.Length; workerResult.Offset = 0; // Transport.ReadAsync below will pickup those changes. } else { workerResult.HeaderDone = false; // Reset for optional object reuse. workerResult.InvokeCallback(workerResult.End); return; } } // This means we need more data to complete the data block. transportResult = TaskToApm.Begin(_transport.ReadAsync(workerResult.Buffer, workerResult.Offset, workerResult.End - workerResult.Offset), _readFrameCallback, workerResult); } while (transportResult.CompletedSynchronously); }
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { return(TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state)); }
internal IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) { return(TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState)); }
public void EndAuthenticateAsServer(IAsyncResult asyncResult) { TaskToApm.End(asyncResult); }
public virtual IAsyncResult BeginAuthenticateAsClient( NetworkCredential credential, ChannelBinding?binding, string targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel, AsyncCallback?asyncCallback, object?asyncState) => TaskToApm.Begin(AuthenticateAsClientAsync(credential, binding, targetName, requiredProtectionLevel, allowedImpersonationLevel), asyncCallback, asyncState);
public void EndAuthenticateAsClient(IAsyncResult asyncResult) { TaskToApm.End(asyncResult); }
public IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState) { var task = ProcessAuthentication(false, true, string.Empty, enabledSslProtocols, serverCertificate, null, clientCertificateRequired); return(TaskToApm.Begin(task, asyncCallback, asyncState)); }
public IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState) { var task = ProcessAuthentication(false, false, targetHost, enabledSslProtocols, null, clientCertificates, false); return(TaskToApm.Begin(task, asyncCallback, asyncState)); }
public virtual IAsyncResult BeginAuthenticateAsServer(X509Certificate serverCertificate, bool clientCertificateRequired, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState) { var task = Impl.AuthenticateAsServerAsync(serverCertificate, clientCertificateRequired, enabledSslProtocols, checkCertificateRevocation); return(TaskToApm.Begin(task, asyncCallback, asyncState)); }
public virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState) { var task = Impl.AuthenticateAsClientAsync(targetHost, clientCertificates, enabledSslProtocols, checkCertificateRevocation); return(TaskToApm.Begin(task, asyncCallback, asyncState)); }
public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback userCallback, object stateObject) { return(TaskToApm.Begin(WriteAsync(array, offset, count), userCallback, stateObject)); }
public virtual IAsyncResult BeginAuthenticateAsServer( NetworkCredential credential, ExtendedProtectionPolicy?policy, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel requiredImpersonationLevel, AsyncCallback?asyncCallback, object?asyncState) => TaskToApm.Begin(AuthenticateAsServerAsync(credential, policy, requiredProtectionLevel, requiredImpersonationLevel), asyncCallback, asyncState);
private void EndSendFileInternal(IAsyncResult asyncResult) { TaskToApm.End(asyncResult); }
public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) => TaskToApm.End(asyncResult);
internal int EndRead(IAsyncResult asyncResult) => TaskToApm.End <int>(asyncResult);
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback?callback, object?state) { return(TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state)); }
internal void EndWrite(IAsyncResult asyncResult) => TaskToApm.End(asyncResult);
public IAsyncResult BeginAcceptTcpClient(AsyncCallback?callback, object?state) => TaskToApm.Begin(AcceptTcpClientAsync(), callback, state);
public override IAsyncResult BeginRead(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) => TaskToApm.Begin(ReadAsync(array, offset, count, CancellationToken.None), asyncCallback, asyncState);
public virtual int EndRead(IAsyncResult asyncResult) => TaskToApm.End <int>(asyncResult);
public override int EndRead(IAsyncResult asyncResult) { return(TaskToApm.End <int>(asyncResult)); }
public virtual void EndWrite(IAsyncResult asyncResult) => TaskToApm.End(asyncResult);
public override void EndWrite(IAsyncResult asyncResult) { TaskToApm.End(asyncResult); }
public override IAsyncResult BeginRead(byte[] array, int offset, int numBytes, AsyncCallback userCallback, object stateObject) { return(TaskToApm.Begin(ReadAsync(array, offset, numBytes), userCallback, stateObject)); }
public override int EndRead(IAsyncResult asyncResult) => TaskToApm.End <int>(asyncResult);
private IAsyncResult BeginConnectCore(IPAddress[] addresses, int port, AsyncCallback requestCallback, object state) => TaskToApm.Begin(ConnectAsyncCore(addresses, port), requestCallback, state);