From d60a62ab80b21eb0e5e97fc89e2dcc2cc28a85a6 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 6 Jun 2017 07:51:40 +0200 Subject: [PATCH] Better handling of eof --- Sources/NIO/Channel.swift | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Sources/NIO/Channel.swift b/Sources/NIO/Channel.swift index d8d417665..2a2656456 100644 --- a/Sources/NIO/Channel.swift +++ b/Sources/NIO/Channel.swift @@ -248,8 +248,7 @@ public class SocketChannel : Channel { return buffer } else { // end-of-file - close0() - return nil + throw ChannelError.eof } } return nil @@ -743,14 +742,22 @@ public class Channel : ChannelOutboundInvoker { break } } catch let err { - pipeline.fireErrorCaught0(error: err) - + if let channelErr = err as? ChannelError { + // EOF is not really an error that should be forwarded to the user + if channelErr != ChannelError.eof { + pipeline.fireErrorCaught(error: err) + } + } else { + pipeline.fireErrorCaught(error: err) + } + // Call before triggering the close of the Channel. pipeline.fireChannelReadComplete0() - + close0(error: err) - + return + } } pipeline.fireChannelReadComplete0() @@ -901,4 +908,5 @@ public enum ChannelError: Error { case messageUnsupported case operationUnsupported case closed + case eof }