Commit e417c3f
authored
Make AsyncIO.read's maxLength a cap and rewrite Darwin backend (#259)
Previously AsyncIO.read(upTo: maxLength) treated maxLength as a target length. It would accumulate bytes in a loop until it had gathered that many before returning. This deadlocks when a subprocess writes fewer bytes than maxLength and then pauses or waits on stdin: the parent blocks forever on data the child never sends.
This commit change maxLength to a "cap", as its name suggests. Each read(upTo:) now returns as soon as the underlying nonblocking read(2) (or ReadFile) completes. Callers that need a specific byte count accumulate across calls themselves.
Follow-on cleanup enabled by the semantics fix:
- Replace Darwin's DispatchIO backend with kqueue + read(2).
The new Darwin path is a thin event-source shim over the same nonblocking read/write loop that Linux and Android already use, sharing implementation in a new IO/AsyncIO+Unix.swift.
- Collapse IOChannel into IODescriptor.
IOChannel only existed to wrap a DispatchIO; with DispatchIO gone, a single fd-owning type suffices.
- Drop the public `preferredBufferSize` parameter from every run()
overload.
It was introduced to let callers work around the old hang; buffer size is now derived from the pipe's capacity via F_GETPIPE_SZ (Linux/Android), fstat().st_blksize (Darwin/OpenBSD), or a fixed 64 KB fallback (FreeBSD, Windows).1 parent 371baa0 commit e417c3f
24 files changed
Lines changed: 1117 additions & 1196 deletions
File tree
- Sources
- Subprocess
- IO
- Platforms
- SubprocessFoundation
- _SubprocessCShims/include
- Tests/SubprocessTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
| 41 | + | |
44 | 42 | | |
45 | 43 | | |
46 | 44 | | |
| |||
55 | 53 | | |
56 | 54 | | |
57 | 55 | | |
58 | | - | |
| 56 | + | |
59 | 57 | | |
60 | 58 | | |
61 | | - | |
| 59 | + | |
| 60 | + | |
62 | 61 | | |
63 | 62 | | |
64 | 63 | | |
| |||
74 | 73 | | |
75 | 74 | | |
76 | 75 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 76 | + | |
80 | 77 | | |
81 | 78 | | |
82 | 79 | | |
83 | 80 | | |
84 | 81 | | |
85 | 82 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 83 | + | |
95 | 84 | | |
96 | 85 | | |
97 | 86 | | |
| |||
101 | 90 | | |
102 | 91 | | |
103 | 92 | | |
104 | | - | |
105 | 93 | | |
106 | | - | |
| 94 | + | |
107 | 95 | | |
108 | | - | |
109 | 96 | | |
110 | 97 | | |
111 | 98 | | |
112 | 99 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 100 | + | |
117 | 101 | | |
118 | 102 | | |
119 | 103 | | |
| |||
268 | 252 | | |
269 | 253 | | |
270 | 254 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | 255 | | |
288 | 256 | | |
289 | 257 | | |
290 | 258 | | |
291 | 259 | | |
292 | 260 | | |
293 | | - | |
294 | 261 | | |
295 | 262 | | |
296 | 263 | | |
| |||
604 | 571 | | |
605 | 572 | | |
606 | 573 | | |
607 | | - | |
| 574 | + | |
608 | 575 | | |
609 | 576 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | 12 | | |
18 | 13 | | |
19 | 14 | | |
| |||
24 | 19 | | |
25 | 20 | | |
26 | 21 | | |
27 | | - | |
28 | 22 | | |
29 | 23 | | |
30 | 24 | | |
31 | 25 | | |
32 | 26 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 27 | | |
53 | 28 | | |
54 | 29 | | |
55 | 30 | | |
56 | 31 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 32 | | |
63 | 33 | | |
64 | 34 | | |
| |||
104 | 74 | | |
105 | 75 | | |
106 | 76 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | | - | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
0 commit comments