@@ -41,21 +41,26 @@ private let write = _write(_:_:_:)
4141
4242/// Concrete 'MessageConnection' type using Standard I/O.
4343///
44- /// When creating, `stdout` is redirected to `stderr` so that print statements
45- /// from the plugin are treated as plain-text output, and `stdin` is closed so
46- /// that any attempts by the plugin logic to read from console result in errors
47- /// instead of blocking the process. The original `stdin` and `stdout` are
48- /// duplicated for use as messaging pipes, and are not directly used by the
49- /// plugin logic.
50- ///
5144/// Each message is serialized to UTF-8 encoded JSON text, prefixed with a
5245/// 8 byte header which is the byte size of the JSON payload serialized to a
5346/// little-endian 64bit unsigned integer.
5447@_spi ( PluginMessage)
5548public struct StandardIOMessageConnection : MessageConnection {
56- private var inputFileDescriptor : CInt
57- private var outputFileDescriptor : CInt
49+ private let inputFileDescriptor : CInt
50+ private let outputFileDescriptor : CInt
51+
52+ public init ( inputFileDescriptor: CInt , outputFileDescriptor: CInt ) {
53+ self . inputFileDescriptor = inputFileDescriptor
54+ self . outputFileDescriptor = outputFileDescriptor
55+ }
5856
57+ /// Convenience initializer for normal executable plugins. Upon creation:
58+ /// - Redirect `stdout` to `stderr` so that print statements from the plugin
59+ /// are treated as plain-text output
60+ /// - Close `stdin` so that any attempts by the plugin logic to read from
61+ /// console result in errors instead of blocking the process
62+ /// - Duplicate the original `stdin` and `stdout` for use as messaging
63+ /// pipes, and are not directly used by the plugin logic
5964 public init ( ) throws {
6065 // Duplicate the `stdin` file descriptor, which we will then use for
6166 // receiving messages from the plugin host.
@@ -90,8 +95,7 @@ public struct StandardIOMessageConnection: MessageConnection {
9095 _ = _setmode ( outputFD, _O_BINARY)
9196 #endif
9297
93- self . inputFileDescriptor = inputFD
94- self . outputFileDescriptor = outputFD
98+ self . init ( inputFileDescriptor: inputFD, outputFileDescriptor: outputFD)
9599 }
96100
97101 /// Write the buffer to the file descriptor. Throws an error on failure.
0 commit comments