Exemple #1
0
        AsyncOperationStatus ProcessHandshake(AsyncProtocolRequest asyncRequest, AsyncOperationStatus status)
        {
            Debug("ProcessHandshake: {0}", status);

            /*
             * The first time we're called (AsyncOperationStatus.Initialize), we need to setup the SslContext and
             * start the handshake.
             */
            if (status == AsyncOperationStatus.Initialize)
            {
                xobileTlsContext.StartHandshake();
                return(AsyncOperationStatus.Continue);
            }
            else if (status == AsyncOperationStatus.ReadDone)
            {
                // remote prematurely closed connection.
                throw new IOException("Remote prematurely closed connection.");
            }
            else if (status != AsyncOperationStatus.Continue)
            {
                throw new InvalidOperationException();
            }

            /*
             * SSLHandshake() will return repeatedly with 'SslStatus.WouldBlock', we then need
             * to take care of I/O and call it again.
             */
            if (!xobileTlsContext.ProcessHandshake())
            {
                /*
                 * Flush the internal write buffer.
                 */
                InnerFlush();
                return(AsyncOperationStatus.Continue);
            }

            xobileTlsContext.FinishHandshake();
            return(AsyncOperationStatus.Complete);
        }