From f96227a35fcfa12a5d1fb2a4c11cf896a0bc6ca2 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Mon, 5 Jun 2017 12:59:03 +0200 Subject: [PATCH] Skip empty buffers when construct array for writev call --- Sources/NIO/Channel.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/NIO/Channel.swift b/Sources/NIO/Channel.swift index 464772c4b..78f180808 100644 --- a/Sources/NIO/Channel.swift +++ b/Sources/NIO/Channel.swift @@ -134,7 +134,10 @@ fileprivate class PendingWrites { // Using withReadPointer as we not want to adjust the readerIndex yet. We will do this at a higher level let written = try pending.buffer.withReadPointer(body: { (pointer: UnsafePointer, size: Int) -> Int? in - pointers.append((pointer, size)) + if size > 0 { + // Only include if its not empty + pointers.append((pointer, size)) + } return try consumeNext0(pendingWrite: pending.next, count: count + 1, body: body) }) return written @@ -261,6 +264,10 @@ public class SocketChannel : Channel { // normal write return try (self.socket as! Socket).write(pointer: $0, size: $1) }, multipleBody: { + guard $0.count > 0 else { + // No need to call writev if there is nothing to write. + return 0 + } // gathering write return try (self.socket as! Socket).writev(pointers: $0) })