SetComplete() 공개 메소드

public SetComplete ( ) : void
리턴 void
예제 #1
0
        private void InternalReceiveRecordCallback(IAsyncResult asyncResult)
        {
            RecordProtocol.ReceiveRecordAsyncResult receiveRecordAsyncResult = asyncResult.AsyncState as RecordProtocol.ReceiveRecordAsyncResult;
            Stream record = receiveRecordAsyncResult.Record;

            try
            {
                if (receiveRecordAsyncResult.Record.EndRead(asyncResult) == 0)
                {
                    receiveRecordAsyncResult.SetComplete(null);
                }
                else
                {
                    int num = (int)receiveRecordAsyncResult.InitialBuffer[0];
                    this.context.LastHandshakeMsg = HandshakeType.ClientHello;
                    ContentType contentType = (ContentType)num;
                    byte[]      array       = this.ReadRecordBuffer(num, record);
                    if (array == null)
                    {
                        receiveRecordAsyncResult.SetComplete(null);
                    }
                    else
                    {
                        if (contentType != ContentType.Alert || array.Length != 2)
                        {
                            if (this.Context.Read != null && this.Context.Read.Cipher != null)
                            {
                                array = this.decryptRecordFragment(contentType, array);
                            }
                        }
                        ContentType contentType2 = contentType;
                        switch (contentType2)
                        {
                        case ContentType.ChangeCipherSpec:
                            this.ProcessChangeCipherSpec();
                            break;

                        case ContentType.Alert:
                            this.ProcessAlert((AlertLevel)array[0], (AlertDescription)array[1]);
                            if (record.CanSeek)
                            {
                                record.SetLength(0L);
                            }
                            array = null;
                            break;

                        case ContentType.Handshake:
                        {
                            TlsStream tlsStream = new TlsStream(array);
                            while (!tlsStream.EOF)
                            {
                                this.ProcessHandshakeMessage(tlsStream);
                            }
                            break;
                        }

                        case ContentType.ApplicationData:
                            break;

                        default:
                            if (contentType2 != (ContentType)128)
                            {
                                throw new TlsException(AlertDescription.UnexpectedMessage, "Unknown record received from server.");
                            }
                            this.context.HandshakeMessages.Write(array);
                            break;
                        }
                        receiveRecordAsyncResult.SetComplete(array);
                    }
                }
            }
            catch (Exception complete)
            {
                receiveRecordAsyncResult.SetComplete(complete);
            }
        }
예제 #2
0
        private void InternalReceiveRecordCallback(IAsyncResult asyncResult)
        {
            RecordProtocol.ReceiveRecordAsyncResult asyncState = asyncResult.AsyncState as RecordProtocol.ReceiveRecordAsyncResult;
            Stream record = asyncState.Record;

            try
            {
                if (asyncState.Record.EndRead(asyncResult) == 0)
                {
                    asyncState.SetComplete((byte[])null);
                }
                else
                {
                    int contentType1 = (int)asyncState.InitialBuffer[0];
                    this.context.LastHandshakeMsg = HandshakeType.ClientHello;
                    ContentType contentType2 = (ContentType)contentType1;
                    byte[]      numArray     = this.ReadRecordBuffer(contentType1, record);
                    if (numArray == null)
                    {
                        asyncState.SetComplete((byte[])null);
                    }
                    else
                    {
                        if ((contentType2 != ContentType.Alert || numArray.Length != 2) && (this.Context.Read != null && this.Context.Read.Cipher != null))
                        {
                            numArray = this.decryptRecordFragment(contentType2, numArray);
                        }
                        switch (contentType2)
                        {
                        case ContentType.ChangeCipherSpec:
                            this.ProcessChangeCipherSpec();
                            goto case ContentType.ApplicationData;

                        case ContentType.Alert:
                            this.ProcessAlert((AlertLevel)numArray[0], (AlertDescription)numArray[1]);
                            if (record.CanSeek)
                            {
                                record.SetLength(0L);
                            }
                            numArray = (byte[])null;
                            goto case ContentType.ApplicationData;

                        case ContentType.Handshake:
                            TlsStream handMsg = new TlsStream(numArray);
                            while (!handMsg.EOF)
                            {
                                this.ProcessHandshakeMessage(handMsg);
                            }
                            goto case ContentType.ApplicationData;

                        case ContentType.ApplicationData:
                            asyncState.SetComplete(numArray);
                            break;

                        case (ContentType)128:
                            this.context.HandshakeMessages.Write(numArray);
                            goto case ContentType.ApplicationData;

                        default:
                            throw new TlsException(AlertDescription.UnexpectedMessage, "Unknown record received from server.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                asyncState.SetComplete(ex);
            }
        }