From fc3359f40ffba7da3771926767cb101e2ce9d711 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 23 May 2017 15:35:05 +0200 Subject: [PATCH] Introduce ChannelError and use it for different cases --- Sources/NIO/Channel.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/NIO/Channel.swift b/Sources/NIO/Channel.swift index d5d1bfd43..651983caf 100644 --- a/Sources/NIO/Channel.swift +++ b/Sources/NIO/Channel.swift @@ -266,7 +266,7 @@ public class ServerSocketChannel : Channel { } override fileprivate func writeToSocket(pendingWrites: PendingWrites) throws -> Bool? { - pendingWrites.failAll(error: MessageError.unsupported) + pendingWrites.failAll(error: ChannelError.messageUnsupported) return true } @@ -400,15 +400,15 @@ public class Channel : ChannelOutboundInvoker { func write0(data: Any, promise: Promise) { guard open else { - // Channel was already closed to fail the promise and not even queue it. - promise.fail(error: IOError(errno: EBADF, reason: "Channel closed")) + // Channel was already closed, fail the promise and not even queue it. + promise.fail(error: ChannelError.closed) return } if let buffer = data as? ByteBuffer { pendingWrites.add(buffer: buffer, promise: promise) } else { // Only support ByteBuffer for now. - promise.fail(error: MessageError.unsupported) + promise.fail(error: ChannelError.messageUnsupported) } } @@ -465,7 +465,7 @@ public class Channel : ChannelOutboundInvoker { } } - func close0(promise: Promise = Promise(), error: Error = IOError(errno: EBADF, reason: "Channel closed")) { + func close0(promise: Promise = Promise(), error: Error = ChannelError.closed) { guard open else { // Already closed @@ -676,6 +676,7 @@ public class FixedSizeRecvByteBufferAllocator : RecvByteBufferAllocator { } } -enum MessageError: Error { - case unsupported +public enum ChannelError: Error { + case messageUnsupported + case closed }