Minor fixups in Channel sending logic

This commit is contained in:
Cory Benfield 2017-11-13 15:34:01 +00:00
parent 8ff2d5bb92
commit 10f93fdca0
1 changed files with 5 additions and 1 deletions

View File

@ -287,7 +287,7 @@ private final class PendingWrites {
// buffer was completely written
p.promise?.succeed(result: ())
if w == 0 {
if w == 0 && buffer.readableBytes > 0 {
return isFlushPending ? .writtenCompletely : .nothingToBeWritten
}
@ -450,6 +450,10 @@ final class SocketChannel : BaseSocketChannel<Socket> {
return .processed(0)
case 1:
let p = ptrs[0]
guard p.iov_len > 0 else {
// No need to call write if the buffer is empty.
return .processed(0)
}
return try self.socket.write(pointer: p.iov_base.assumingMemoryBound(to: UInt8.self), size: p.iov_len)
default:
// Gathering write