@@ -162,26 +162,26 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
162162 final Ruby runtime = context .runtime ;
163163
164164 if (Arity .checkArgumentCount (runtime , args , 1 , 2 ) == 1 ) {
165- sslContext = new SSLContext (runtime ).initializeImpl ();
165+ this . sslContext = new SSLContext (runtime ).initializeImpl ();
166166 } else {
167167 if (!(args [1 ] instanceof SSLContext )) {
168168 throw runtime .newTypeError (args [1 ], "OpenSSL::SSL::SSLContext" );
169169 }
170- sslContext = (SSLContext ) args [1 ];
170+ this . sslContext = (SSLContext ) args [1 ];
171171 }
172172
173173 if (!(args [0 ] instanceof RubyIO )) {
174174 throw runtime .newTypeError ("IO expected but got " + args [0 ].getMetaClass ().getName ());
175175 }
176- setInstanceVariable ("@context" , this .sslContext ); // only compat (we do not use @context)
177- setInstanceVariable ("@io" , this .io = (RubyIO ) args [0 ]);
176+ setInstanceVariable ("@io" , this .io = (RubyIO ) args [0 ]); // RubyBasicSocket extends RubyIO
178177 set_io_nonblock_checked (context , runtime .getTrue ());
179178 // This is a bit of a hack: SSLSocket should share code with
180179 // RubyBasicSocket, which always sets sync to true.
181180 // Instead we set it here for now.
182181 set_sync (context , runtime .getTrue ()); // io.sync = true
183182 setInstanceVariable ("@sync_close" , runtime .getFalse ()); // self.sync_close = false
184183 sslContext .setup (context );
184+ setInstanceVariable ("@context" , sslContext ); // only compat (we do not use @context)
185185
186186 this .initializeTime = System .currentTimeMillis ();
187187
@@ -471,8 +471,8 @@ else if ((operations & SelectionKey.OP_WRITE) != 0) {
471471 writeWouldBlock (runtime , exception , result );
472472 }
473473 }
474- }
475- catch ( IOException ioe ) {
474+ } catch ( IOException ioe ) {
475+ debugStackTrace ( runtime , "SSLSocket.waitSelect" , ioe );
476476 throw runtime .newRuntimeError ("Error with selector: " + ioe .getMessage ());
477477 }
478478 } else {
@@ -483,6 +483,7 @@ public void run() throws InterruptedException {
483483 result [0 ] = selector .select ();
484484 }
485485 catch (IOException ioe ) {
486+ debugStackTrace (runtime , "SSLSocket.waitSelect" , ioe );
486487 throw runtime .newRuntimeError ("Error with selector: " + ioe .getMessage ());
487488 }
488489 }
@@ -505,32 +506,27 @@ public void wakeup() {
505506 //JRuby <= 9.1.2.0 that makes this not always the case, so we have to check
506507 return selector .selectedKeys ().contains (key ) ? Boolean .TRUE : Boolean .FALSE ;
507508 }
508- }
509- catch (InterruptedException interrupt ) { return Boolean .FALSE ; }
510- finally {
511- // Note: I don't like ignoring these exceptions, but it's
512- // unclear how likely they are to happen or what damage we
513- // might do by ignoring them. Note that the pieces are separate
514- // so that we can ensure one failing does not affect the others
515- // running.
509+ } catch (InterruptedException interrupt ) {
510+ debug (runtime , "SSLSocket.waitSelect" , interrupt );
511+ return Boolean .FALSE ;
512+ } finally {
513+ // Note: I don't like ignoring these exceptions, but it's unclear how likely they are to happen or what
514+ // damage we might do by ignoring them. Note that the pieces are separate so that we can ensure one failing
515+ // does not affect the others running.
516516
517517 // clean up the key in the selector
518518 try {
519519 if ( key != null ) key .cancel ();
520520 if ( selector != null ) selector .selectNow ();
521- }
522- catch (Exception e ) { // ignore
523- debugStackTrace (runtime , e );
521+ } catch (Exception e ) { // ignore
522+ debugStackTrace (runtime , "SSLSocket.waitSelect (ignored)" , e );
524523 }
525524
526525 // shut down and null out the selector
527526 try {
528- if ( selector != null ) {
529- runtime .getSelectorPool ().put (selector );
530- }
531- }
532- catch (Exception e ) { // ignore
533- debugStackTrace (runtime , e );
527+ if ( selector != null ) runtime .getSelectorPool ().put (selector );
528+ } catch (Exception e ) { // ignore
529+ debugStackTrace (runtime , "SSLSocket.waitSelect (ignored)" , e );
534530 }
535531
536532 if (blocking ) {
@@ -810,8 +806,11 @@ private void doShutdown() throws IOException {
810806 flushData (true );
811807 }
812808
813- private IRubyObject sysreadImpl (final ThreadContext context ,
814- IRubyObject len , IRubyObject buff , final boolean blocking , final boolean exception ) {
809+ /**
810+ * @return the (@link RubyString} buffer or :wait_readable / :wait_writeable {@link RubySymbol}
811+ */
812+ private IRubyObject sysreadImpl (final ThreadContext context , final IRubyObject len , final IRubyObject buff ,
813+ final boolean blocking , final boolean exception ) {
815814 final Ruby runtime = context .runtime ;
816815
817816 final int length = RubyNumeric .fix2int (len );
0 commit comments