Пример #1
0
 private void EndConnectCore(Socket socket, IAsyncResult asyncResult) =>
 TaskToApm.End(asyncResult);
Пример #2
0
        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);
Пример #4
0
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState) =>
 TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState);
Пример #5
0
        // 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);
        }
Пример #6
0
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     return(TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state));
 }
Пример #7
0
 internal IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback asyncCallback, object asyncState)
 {
     return(TaskToApm.Begin(WriteAsync(buffer, offset, count, CancellationToken.None), asyncCallback, asyncState));
 }
Пример #8
0
 public void EndAuthenticateAsServer(IAsyncResult asyncResult)
 {
     TaskToApm.End(asyncResult);
 }
Пример #9
0
 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);
Пример #10
0
 public void EndAuthenticateAsClient(IAsyncResult asyncResult)
 {
     TaskToApm.End(asyncResult);
 }
Пример #11
0
        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));
        }
Пример #12
0
        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));
        }
Пример #13
0
        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));
        }
Пример #14
0
        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));
        }
Пример #15
0
 public override IAsyncResult BeginWrite(byte[] array, int offset, int count, AsyncCallback userCallback, object stateObject)
 {
     return(TaskToApm.Begin(WriteAsync(array, offset, count), userCallback, stateObject));
 }
Пример #16
0
 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);
Пример #17
0
 private void EndSendFileInternal(IAsyncResult asyncResult)
 {
     TaskToApm.End(asyncResult);
 }
Пример #18
0
 public virtual void EndAuthenticateAsServer(IAsyncResult asyncResult) => TaskToApm.End(asyncResult);
Пример #19
0
 internal int EndRead(IAsyncResult asyncResult) => TaskToApm.End <int>(asyncResult);
Пример #20
0
 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback?callback, object?state)
 {
     return(TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state));
 }
Пример #21
0
 internal void EndWrite(IAsyncResult asyncResult) => TaskToApm.End(asyncResult);
Пример #22
0
 public IAsyncResult BeginAcceptTcpClient(AsyncCallback?callback, object?state) =>
 TaskToApm.Begin(AcceptTcpClientAsync(), callback, state);
Пример #23
0
 public override IAsyncResult BeginRead(byte[] array, int offset, int count, AsyncCallback asyncCallback, object asyncState) =>
 TaskToApm.Begin(ReadAsync(array, offset, count, CancellationToken.None), asyncCallback, asyncState);
Пример #24
0
 public virtual int EndRead(IAsyncResult asyncResult) =>
 TaskToApm.End <int>(asyncResult);
Пример #25
0
 public override int EndRead(IAsyncResult asyncResult)
 {
     return(TaskToApm.End <int>(asyncResult));
 }
Пример #26
0
 public virtual void EndWrite(IAsyncResult asyncResult) =>
 TaskToApm.End(asyncResult);
Пример #27
0
 public override void EndWrite(IAsyncResult asyncResult)
 {
     TaskToApm.End(asyncResult);
 }
Пример #28
0
 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);
Пример #30
0
 private IAsyncResult BeginConnectCore(IPAddress[] addresses, int port, AsyncCallback requestCallback, object state) =>
 TaskToApm.Begin(ConnectAsyncCore(addresses, port), requestCallback, state);