protected override Exception CreatePrematureEOFException()
 {
     return(decoder.CreatePrematureEOFException());
 }
예제 #2
0
        async Task ReadAndDispatchAsync()
        {
            bool success = false;

            try
            {
                while ((size > 0 || !isReadPending) && !IsClosed)
                {
                    if (size == 0)
                    {
                        isReadPending = true;
                        size          = await Connection.ReadAsync(0, connectionBuffer.Length, GetRemainingTimeout());

                        offset        = 0;
                        isReadPending = false;
                        if (size == 0)
                        {
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(decoder.CreatePrematureEOFException());
                        }
                    }

                    int bytesRead = decoder.Decode(connectionBuffer, offset, size);
                    if (bytesRead > 0)
                    {
                        offset += bytesRead;
                        size   -= bytesRead;
                    }

                    if (decoder.CurrentState == ServerSingletonDecoder.State.PreUpgradeStart)
                    {
                        via = decoder.Via;
                        var validated = await Connection.ValidateAsync(via);

                        if (!ContinuePostValidationProcessing())
                        {
                            // This goes through the failure path (Abort) even though it doesn't throw.
                            return;
                        }
                        break; //exit loop, set success=true;
                    }
                }
                success = true;
            }
            catch (CommunicationException exception)
            {
                DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);
            }
            catch (TimeoutException exception)
            {
                DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }
                if (!ExceptionHandlerHelper.HandleTransportExceptionHelper(e))
                {
                    throw;
                }

                // containment -- we abort ourselves for any error, no extra containment needed
            }
            finally
            {
                if (!success)
                {
                    Abort();
                }
            }
        }