@@ -41,21 +41,26 @@ private let write = _write(_:_:_:)
41
41
42
42
/// Concrete 'MessageConnection' type using Standard I/O.
43
43
///
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
- ///
51
44
/// Each message is serialized to UTF-8 encoded JSON text, prefixed with a
52
45
/// 8 byte header which is the byte size of the JSON payload serialized to a
53
46
/// little-endian 64bit unsigned integer.
54
47
@_spi ( PluginMessage)
55
48
public 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
+ }
58
56
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
59
64
public init ( ) throws {
60
65
// Duplicate the `stdin` file descriptor, which we will then use for
61
66
// receiving messages from the plugin host.
@@ -90,8 +95,7 @@ public struct StandardIOMessageConnection: MessageConnection {
90
95
_ = _setmode ( outputFD, _O_BINARY)
91
96
#endif
92
97
93
- self . inputFileDescriptor = inputFD
94
- self . outputFileDescriptor = outputFD
98
+ self . init ( inputFileDescriptor: inputFD, outputFileDescriptor: outputFD)
95
99
}
96
100
97
101
/// Write the buffer to the file descriptor. Throws an error on failure.
0 commit comments