@@ -164,56 +164,57 @@ PTuple doGeneric(VirtualFrame frame, Object rlist, Object wlist, Object xlist, O
164
164
165
165
@ TruffleBoundary
166
166
private static void doSelect (ChannelFD [] readFDs , ChannelFD [] writeFDs , ChannelFD [] xFDs , long timeoutMillis ) throws IOException {
167
- Selector selector = Selector .open ();
167
+ try ( Selector selector = Selector .open ()) {
168
168
169
- for (ChannelFD readFD : readFDs ) {
170
- readFD .channel .configureBlocking (false );
171
- readFD .channel .register (selector , SelectionKey .OP_READ );
172
- }
169
+ for (ChannelFD readFD : readFDs ) {
170
+ readFD .channel .configureBlocking (false );
171
+ readFD .channel .register (selector , SelectionKey .OP_READ );
172
+ }
173
173
174
- for (ChannelFD writeFD : writeFDs ) {
175
- writeFD .channel .configureBlocking (false );
176
- writeFD .channel .register (selector , SelectionKey .OP_WRITE );
177
- }
174
+ for (ChannelFD writeFD : writeFDs ) {
175
+ writeFD .channel .configureBlocking (false );
176
+ writeFD .channel .register (selector , SelectionKey .OP_WRITE );
177
+ }
178
178
179
- for (ChannelFD xFD : xFDs ) {
180
- // TODO(fa): not sure if these ops are representing
181
- // "exceptional condition pending"
182
- xFD .channel .configureBlocking (false );
183
- xFD .channel .register (selector , SelectionKey .OP_ACCEPT | SelectionKey .OP_CONNECT );
184
- }
179
+ for (ChannelFD xFD : xFDs ) {
180
+ // TODO(fa): not sure if these ops are representing
181
+ // "exceptional condition pending"
182
+ xFD .channel .configureBlocking (false );
183
+ xFD .channel .register (selector , SelectionKey .OP_ACCEPT | SelectionKey .OP_CONNECT );
184
+ }
185
185
186
- int selected = selector .select (timeoutMillis );
186
+ int selected = selector .select (timeoutMillis );
187
187
188
- // remove non-selected channels from given lists
189
- int deleted = 0 ;
190
- for (int i = 0 ; i < readFDs .length ; i ++) {
191
- ChannelFD readFD = readFDs [i ];
192
- SelectionKey selectionKey = readFD .channel .keyFor (selector );
193
- if (!selectionKey .isReadable ()) {
194
- readFDs [i ] = null ;
195
- deleted ++;
188
+ // remove non-selected channels from given lists
189
+ int deleted = 0 ;
190
+ for (int i = 0 ; i < readFDs .length ; i ++) {
191
+ ChannelFD readFD = readFDs [i ];
192
+ SelectionKey selectionKey = readFD .channel .keyFor (selector );
193
+ if (!selectionKey .isReadable ()) {
194
+ readFDs [i ] = null ;
195
+ deleted ++;
196
+ }
196
197
}
197
- }
198
198
199
- for (int i = 0 ; i < writeFDs .length ; i ++) {
200
- ChannelFD writeFD = writeFDs [i ];
201
- SelectionKey selectionKey = writeFD .channel .keyFor (selector );
202
- if (!selectionKey .isWritable ()) {
203
- writeFDs [i ] = null ;
204
- deleted ++;
199
+ for (int i = 0 ; i < writeFDs .length ; i ++) {
200
+ ChannelFD writeFD = writeFDs [i ];
201
+ SelectionKey selectionKey = writeFD .channel .keyFor (selector );
202
+ if (!selectionKey .isWritable ()) {
203
+ writeFDs [i ] = null ;
204
+ deleted ++;
205
+ }
205
206
}
206
- }
207
207
208
- for (int i = 0 ; i < xFDs .length ; i ++) {
209
- ChannelFD xFD = xFDs [i ];
210
- SelectionKey selectionKey = xFD .channel .keyFor (selector );
211
- if (!(selectionKey .isAcceptable () || selectionKey .isConnectable ())) {
212
- xFDs [i ] = null ;
213
- deleted ++;
208
+ for (int i = 0 ; i < xFDs .length ; i ++) {
209
+ ChannelFD xFD = xFDs [i ];
210
+ SelectionKey selectionKey = xFD .channel .keyFor (selector );
211
+ if (!(selectionKey .isAcceptable () || selectionKey .isConnectable ())) {
212
+ xFDs [i ] = null ;
213
+ deleted ++;
214
+ }
214
215
}
216
+ assert selected == (readFDs .length + writeFDs .length + xFDs .length ) - deleted ;
215
217
}
216
- assert selected == (readFDs .length + writeFDs .length + xFDs .length ) - deleted ;
217
218
}
218
219
219
220
private ChannelFD [] seq2set (VirtualFrame frame , Object sequence , PythonObjectLibrary sequenceLib , PythonObjectLibrary itemLib , LookupAndCallBinaryNode callGetItemNode ,
0 commit comments