From e4ef4c19f75b68e4ec97c66b327f8f91e8f1a366 Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Tue, 12 Dec 2017 14:14:10 +0000 Subject: [PATCH] fix write spinning (should be max `writeSpinCount` writes) --- Sources/NIO/Channel.swift | 4 ++-- Tests/NIOTests/ChannelTests.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/NIO/Channel.swift b/Sources/NIO/Channel.swift index 837a13727..42cc4df0b 100644 --- a/Sources/NIO/Channel.swift +++ b/Sources/NIO/Channel.swift @@ -410,7 +410,7 @@ private struct PendingWritesState { private func triggerSingleWrite(singleWriteOperation: (UnsafeRawBufferPointer) throws -> IOResult, fileWriteOperation: (Int32, Int, Int) throws -> IOResult) rethrows -> WriteResult { if self.state.isFlushPending && !self.state.isEmpty { - for _ in 0...writeSpinCount { + for _ in 0..) throws -> IOResult) throws -> WriteResult { assert(self.state.isFlushPending && !self.state.isEmpty, "vector write called in state flush pending: \(self.state.isFlushPending), empty: \(self.state.isEmpty)") - for _ in 0...writeSpinCount { + for _ in 0..(repeating: 0xff, count: numberOfBytes)) let ps: [EventLoopPromise<()>] = (0..<1).map { _ in el.newPromise() } @@ -541,7 +541,7 @@ public class ChannelTests: XCTestCase { var buffer = alloc.buffer(capacity: 12) withPendingWritesManager { pwm in - let numberOfBytes = Int(pwm.writeSpinCount + 1 /* because we spin 1 + spin count */ + 1 /* so one byte remains at the end */) + let numberOfBytes = Int(pwm.writeSpinCount + 1 /* so one byte remains at the end */) buffer.clear() buffer.write(bytes: [0xff] as [UInt8]) let ps: [EventLoopPromise<()>] = (0..