Receive() public method

public Receive ( byte buf, int off, int len, int waitMillis ) : int
buf byte
off int
len int
waitMillis int
return int
Esempio n. 1
0
        public virtual int Receive(byte[] buf, int off, int len, int waitMillis)
        {
            if (null == buf)
            {
                throw new ArgumentNullException("buf");
            }
            if (off < 0 || off >= buf.Length)
            {
                throw new ArgumentException("invalid offset: " + off, "off");
            }
            if (len < 0 || len > buf.Length - off)
            {
                throw new ArgumentException("invalid length: " + len, "len");
            }
            if (waitMillis < 0)
            {
                throw new ArgumentException("cannot be negative", "waitMillis");
            }

            try
            {
                return(mRecordLayer.Receive(buf, off, len, waitMillis));
            }
            catch (TlsFatalAlert fatalAlert)
            {
                mRecordLayer.Fail(fatalAlert.AlertDescription);
                throw fatalAlert;
            }
            catch (TlsTimeoutException e)
            {
                throw e;
            }
#if !PORTABLE || DOTNET
            catch (SocketException e)
            {
                if (TlsUtilities.IsTimeout(e))
                {
                    throw e;
                }

                mRecordLayer.Fail(AlertDescription.internal_error);
                throw new TlsFatalAlert(AlertDescription.internal_error, e);
            }
#endif
            //catch (InterruptedIOException e)
            //{
            //    throw e;
            //}
            catch (IOException e)
            {
                mRecordLayer.Fail(AlertDescription.internal_error);
                throw e;
            }
            catch (Exception e)
            {
                mRecordLayer.Fail(AlertDescription.internal_error);
                throw new TlsFatalAlert(AlertDescription.internal_error, e);
            }
        }
Esempio n. 2
0
 public virtual int Receive(byte[] buf, int off, int len, int waitMillis)
 {
     try
     {
         return(mRecordLayer.Receive(buf, off, len, waitMillis));
     }
     catch (TlsFatalAlert fatalAlert)
     {
         mRecordLayer.Fail(fatalAlert.AlertDescription);
         throw fatalAlert;
     }
     catch (IOException e)
     {
         mRecordLayer.Fail(AlertDescription.internal_error);
         throw e;
     }
     catch (Exception e)
     {
         mRecordLayer.Fail(AlertDescription.internal_error);
         throw new TlsFatalAlert(AlertDescription.internal_error, e);
     }
 }
Esempio n. 3
0
 public virtual int Receive(byte[] buf, int off, int len, int waitMillis)
 {
     //IL_0028: Expected O, but got Unknown
     try
     {
         return(mRecordLayer.Receive(buf, off, len, waitMillis));
     }
     catch (TlsFatalAlert tlsFatalAlert)
     {
         mRecordLayer.Fail(tlsFatalAlert.AlertDescription);
         throw tlsFatalAlert;
     }
     catch (IOException val)
     {
         IOException val2 = val;
         mRecordLayer.Fail(80);
         throw val2;
     }
     catch (global::System.Exception alertCause)
     {
         mRecordLayer.Fail(80);
         throw new TlsFatalAlert(80, alertCause);
     }
 }
        internal Message ReceiveMessage()
        {
            if (mSending)
            {
                mSending = false;
                PrepareInboundFlight();
            }
            DtlsReassembler dtlsReassembler = (DtlsReassembler)mCurrentInboundFlight.get_Item((object)mNextReceiveSeq);

            if (dtlsReassembler != null)
            {
                byte[] bodyIfComplete = dtlsReassembler.GetBodyIfComplete();
                if (bodyIfComplete != null)
                {
                    mPreviousInboundFlight = null;
                    return(UpdateHandshakeMessagesDigest(new Message(mNextReceiveSeq++, dtlsReassembler.MsgType, bodyIfComplete)));
                }
            }
            byte[] array = null;
            int    num   = 1000;

            while (true)
            {
                int receiveLimit = mRecordLayer.GetReceiveLimit();
                if (array == null || array.Length < receiveLimit)
                {
                    array = new byte[receiveLimit];
                }
                try
                {
                    while (true)
                    {
                        int num2 = mRecordLayer.Receive(array, 0, receiveLimit, num);
                        if (num2 < 0)
                        {
                            break;
                        }
                        if (num2 < 12)
                        {
                            continue;
                        }
                        int num3 = TlsUtilities.ReadUint24(array, 9);
                        if (num2 != num3 + 12)
                        {
                            continue;
                        }
                        int num4 = TlsUtilities.ReadUint16(array, 4);
                        if (num4 > mNextReceiveSeq + 10)
                        {
                            continue;
                        }
                        byte msg_type = TlsUtilities.ReadUint8(array, 0);
                        int  num5     = TlsUtilities.ReadUint24(array, 1);
                        int  num6     = TlsUtilities.ReadUint24(array, 6);
                        if (num6 + num3 > num5)
                        {
                            continue;
                        }
                        if (num4 < mNextReceiveSeq)
                        {
                            if (mPreviousInboundFlight == null)
                            {
                                continue;
                            }
                            DtlsReassembler dtlsReassembler2 = (DtlsReassembler)mPreviousInboundFlight.get_Item((object)num4);
                            if (dtlsReassembler2 != null)
                            {
                                dtlsReassembler2.ContributeFragment(msg_type, num5, array, 12, num6, num3);
                                if (CheckAll(mPreviousInboundFlight))
                                {
                                    ResendOutboundFlight();
                                    num = Math.Min(num * 2, 60000);
                                    ResetAll(mPreviousInboundFlight);
                                }
                            }
                            continue;
                        }
                        DtlsReassembler dtlsReassembler3 = (DtlsReassembler)mCurrentInboundFlight.get_Item((object)num4);
                        if (dtlsReassembler3 == null)
                        {
                            dtlsReassembler3 = new DtlsReassembler(msg_type, num5);
                            mCurrentInboundFlight.set_Item((object)num4, (object)dtlsReassembler3);
                        }
                        dtlsReassembler3.ContributeFragment(msg_type, num5, array, 12, num6, num3);
                        if (num4 == mNextReceiveSeq)
                        {
                            byte[] bodyIfComplete2 = dtlsReassembler3.GetBodyIfComplete();
                            if (bodyIfComplete2 != null)
                            {
                                mPreviousInboundFlight = null;
                                return(UpdateHandshakeMessagesDigest(new Message(mNextReceiveSeq++, dtlsReassembler3.MsgType, bodyIfComplete2)));
                            }
                        }
                    }
                }
                catch (IOException)
                {
                }
                ResendOutboundFlight();
                num = Math.Min(num * 2, 60000);
            }
        }