Ejemplo n.º 1
0
        public SNIError(SNIProviders provider, SNIErrorCode sniErrorCode, Exception sniException)
        {
            Debug.Assert(sniException != null);

            this.provider     = provider;
            this.nativeError  = 0;
            this.sniError     = sniErrorCode;
            this.errorMessage = null;
            this.exception    = sniException;
        }
Ejemplo n.º 2
0
        public SNIError(SNIProviders provider, uint nativeError, SNIErrorCode sniErrorCode, string errorMessage)
        {
            Debug.Assert(errorMessage != null);
            Debug.Assert((errorMessage.Length > 0) || sniErrorCode != 0);

            this.provider     = provider;
            this.nativeError  = nativeError;
            this.sniError     = sniErrorCode;
            this.errorMessage = errorMessage;
            this.exception    = null;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Receive a packet synchronously
        /// </summary>
        /// <param name="packet">SNI packet</param>
        /// <param name="timeoutInMilliseconds">Timeout in Milliseconds</param>
        /// <returns>SNI error code</returns>
        public sealed override SNIError Receive(ref SNIPacket packet, int timeoutInMilliseconds)
        {
            packet = packet ?? new SNIPacket();

            using (_debugLock.Acquire(this))
            {
                try
                {
                    SNIError timeoutError = SetupTimeoutForReceive(timeoutInMilliseconds);
                    if (timeoutError != null)
                    {
                        return(timeoutError);
                    }

                    packet.Allocate(_bufferSize);
                    packet.ReadFromStream(_stream);

                    if (packet.Length == 0)
                    {
                        return(new SNIError(ProviderNumber, 0, 0, "Connection was terminated"));
                    }

                    return(null);
                }
                catch (ObjectDisposedException ode)
                {
                    packet = null;
                    return(new SNIError(ProviderNumber, 0, ode));
                }
                catch (SocketException se)
                {
                    packet = null;
                    return(new SNIError(ProviderNumber, 0, se));
                }
                catch (IOException ioe)
                {
                    SNIErrorCode errorCode = SNIErrorCode.NoError;
                    if (ioe.InnerException is SocketException && ((SocketException)(ioe.InnerException)).SocketErrorCode == SocketError.TimedOut)
                    {
                        errorCode = SNIErrorCode.ConnTimeoutError;
                    }

                    packet = null;
                    return(new SNIError(ProviderNumber, errorCode, ioe));
                }
            }
        }