mirror of
https://github.com/apple/swift-nio
synced 2026-11-27 05:04:22 +00:00
on Darwin, sendfile might write fully and return EWOULDBLOCK
This commit is contained in:
1 parent
76d9516c84
commit
fa35c603a0
4 files changed
+32
-1
No files matched your search
@@ -272,7 +272,13 @@ private struct PendingWritesState {
|
||||
case .byteBuffer(let buffer):
|
||||
fatalError("write with .wouldBlock(\(n)) but a ByteBuffer (\(buffer)) was written")
|
||||
case .fileRegion(let file):
|
||||
assert(file.readableBytes > 0, "write with .wouldBlock(\(n)) but sendfile wrote fully on \(file)")
|
||||
if file.readableBytes == 0 {
|
||||
/* this is odd, sendfile wrote everything but notionally failed with EWOULDBLOCK. This happens on Darwin. */
|
||||
if let promise = self.fullyWrittenFirst() {
|
||||
promises.append(promise)
|
||||
}
|
||||
return (fulfillPromises, .writtenCompletely)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* we don't update here as we get non-zero only if sendfile was used and we don't track bytes to be sent as `FileRegion` */
|
||||
|
||||
@@ -93,6 +93,12 @@ public final class FileRegion {
|
||||
}
|
||||
}
|
||||
|
||||
extension FileRegion: CustomStringConvertible {
|
||||
public var description: String {
|
||||
return "FileRegion(descriptor: \(self.descriptor), readerIndex: \(self.readerIndex), endIndex: \(self.endIndex), open: \(self.open))"
|
||||
}
|
||||
}
|
||||
|
||||
extension FileRegion {
|
||||
/// Create a new `FileRegion`.
|
||||
///
|
||||
|
||||
@@ -45,6 +45,7 @@ extension ChannelTests {
|
||||
("testPendingWritesWorksWithManyEmptyWrites", testPendingWritesWorksWithManyEmptyWrites),
|
||||
("testPendingWritesCloseDuringVectorWrite", testPendingWritesCloseDuringVectorWrite),
|
||||
("testPendingWritesMoreThanWritevIOVectorLimit", testPendingWritesMoreThanWritevIOVectorLimit),
|
||||
("testPendingWritesIsHappyWhenSendfileReturnsWouldBlockButWroteFully", testPendingWritesIsHappyWhenSendfileReturnsWouldBlockButWroteFully),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -990,6 +990,24 @@ public class ChannelTests: XCTestCase {
|
||||
XCTAssertEqual(WriteResult.writtenCompletely, result)
|
||||
XCTAssertTrue(flushPromise.futureResult.fulfilled)
|
||||
}
|
||||
}
|
||||
|
||||
func testPendingWritesIsHappyWhenSendfileReturnsWouldBlockButWroteFully() {
|
||||
let el = EmbeddedEventLoop()
|
||||
withPendingWritesManager { pwm in
|
||||
let ps: [EventLoopPromise<()>] = (0..<1).map { _ in el.newPromise() }
|
||||
|
||||
_ = pwm.add(data: .fileRegion(FileRegion(descriptor: -1, readerIndex: 0, endIndex: 8192)), promise: ps[0])
|
||||
pwm.markFlushCheckpoint(promise: nil)
|
||||
|
||||
let result = assertExpectedWritability(pendingWritesManager: pwm,
|
||||
promises: ps,
|
||||
expectedSingleWritabilities: nil,
|
||||
expectedVectorWritabilities: nil,
|
||||
expectedFileWritabilities: [(0, 8192)],
|
||||
returns: [.wouldBlock(8192)],
|
||||
promiseStates: [[true]])
|
||||
XCTAssertEqual(.writtenCompletely, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user