@@ -164,56 +164,57 @@ PTuple doGeneric(VirtualFrame frame, Object rlist, Object wlist, Object xlist, O
164164
165165 @ TruffleBoundary
166166 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 ()) {
168168
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+ }
173173
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+ }
178178
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+ }
185185
186- int selected = selector .select (timeoutMillis );
186+ int selected = selector .select (timeoutMillis );
187187
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+ }
196197 }
197- }
198198
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+ }
205206 }
206- }
207207
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+ }
214215 }
216+ assert selected == (readFDs .length + writeFDs .length + xFDs .length ) - deleted ;
215217 }
216- assert selected == (readFDs .length + writeFDs .length + xFDs .length ) - deleted ;
217218 }
218219
219220 private ChannelFD [] seq2set (VirtualFrame frame , Object sequence , PythonObjectLibrary sequenceLib , PythonObjectLibrary itemLib , LookupAndCallBinaryNode callGetItemNode ,
0 commit comments