@@ -27,21 +27,26 @@ private let write = _write(_:_:_:)
2727
2828/// Concrete 'MessageConnection' type using Standard I/O.
2929///
30- /// When creating, `stdout` is redirected to `stderr` so that print statements
31- /// from the plugin are treated as plain-text output, and `stdin` is closed so
32- /// that any attempts by the plugin logic to read from console result in errors
33- /// instead of blocking the process. The original `stdin` and `stdout` are
34- /// duplicated for use as messaging pipes, and are not directly used by the
35- /// plugin logic.
36- ///
3730/// Each message is serialized to UTF-8 encoded JSON text, prefixed with a
3831/// 8 byte header which is the byte size of the JSON payload serialized to a
3932/// little-endian 64bit unsigned integer.
4033@_spi ( PluginMessage)
4134public struct StandardIOMessageConnection : MessageConnection {
42- private var inputFileDescriptor : CInt
43- private var outputFileDescriptor : CInt
35+ private let inputFileDescriptor : CInt
36+ private let outputFileDescriptor : CInt
37+
38+ public init ( inputFileDescriptor: CInt , outputFileDescriptor: CInt ) {
39+ self . inputFileDescriptor = inputFileDescriptor
40+ self . outputFileDescriptor = outputFileDescriptor
41+ }
4442
43+ /// Convenience initializer for normal executable plugins. Upon creation:
44+ /// - Redirect `stdout` to `stderr` so that print statements from the plugin
45+ /// are treated as plain-text output
46+ /// - Close `stdin` so that any attempts by the plugin logic to read from
47+ /// console result in errors instead of blocking the process
48+ /// - Duplicate the original `stdin` and `stdout` for use as messaging
49+ /// pipes, and are not directly used by the plugin logic
4550 public init ( ) throws {
4651 // Duplicate the `stdin` file descriptor, which we will then use for
4752 // receiving messages from the plugin host.
@@ -76,8 +81,7 @@ public struct StandardIOMessageConnection: MessageConnection {
7681 _ = _setmode ( outputFD, _O_BINARY)
7782 #endif
7883
79- self . inputFileDescriptor = inputFD
80- self . outputFileDescriptor = outputFD
84+ self . init ( inputFileDescriptor: inputFD, outputFileDescriptor: outputFD)
8185 }
8286
8387 /// Write the buffer to the file descriptor. Throws an error on failure.
0 commit comments