Skip to content

Commit dac3499

Browse files
lrewegabimawa
authored andcommitted
protoc-gen-grpc-swift: FileHandle for stdin, stdout (grpc#1361)
This fixes a case where the output response is silently truncated. Truncation occurs because the `write` syscall is only invoked a single time, but `write` may return a value indicating a partial write for various reasons, even in a blocking call. For example, if stdout is a nonblocking pipe, output is truncated when the pipe is full. Instead of rewriting Stdout.write to handle this case, let's migrate to FileHandle for I/O, available as of Swift 3.2. swift-protobuf has already migrated, and this commit is mostly a port of github.com/apple/swift-protobuf/commit/2ccad3484e06d180af3bd7be53c96d41e8f03a62
1 parent 49afcbe commit dac3499

File tree

2 files changed

+2
-66
lines changed

2 files changed

+2
-66
lines changed

Sources/protoc-gen-grpc-swift/io.swift

Lines changed: 0 additions & 64 deletions
This file was deleted.

Sources/protoc-gen-grpc-swift/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func main() throws {
110110
)
111111

112112
// read plugin input
113-
let rawRequest = try Stdin.readall()
113+
let rawRequest = FileHandle.standardInput.readDataToEndOfFile()
114114
let request = try Google_Protobuf_Compiler_CodeGeneratorRequest(serializedData: rawRequest)
115115

116116
let options = try GeneratorOptions(parameter: request.parameter)
@@ -137,7 +137,7 @@ func main() throws {
137137

138138
// return everything to the caller
139139
let serializedResponse = try response.serializedData()
140-
Stdout.write(bytes: serializedResponse)
140+
FileHandle.standardOutput.write(serializedResponse)
141141
}
142142

143143
do {

0 commit comments

Comments
 (0)