@@ -88,11 +88,11 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
8888 public static void createSSLSocket (final Ruby runtime , final RubyModule SSL ) { // OpenSSL::SSL
8989 final ThreadContext context = runtime .getCurrentContext ();
9090 RubyClass SSLSocket = SSL .defineClassUnder ("SSLSocket" , runtime .getObject (), SSLSOCKET_ALLOCATOR );
91- SSLSocket .addReadWriteAttribute (context , "io" );
92- SSLSocket .addReadWriteAttribute (context , "context" );
91+ // SSLSocket.addReadAttribute(context, "io");
92+ // SSLSocket.defineAlias("to_io", "io");
93+ // SSLSocket.addReadAttribute(context, "context");
9394 SSLSocket .addReadWriteAttribute (context , "sync_close" );
9495 SSLSocket .addReadWriteAttribute (context , "hostname" );
95- SSLSocket .defineAlias ("to_io" , "io" );
9696 SSLSocket .defineAnnotatedMethods (SSLSocket .class );
9797 }
9898
@@ -156,12 +156,12 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject[] a
156156 if ( ! ( args [0 ] instanceof RubyIO ) ) {
157157 throw runtime .newTypeError ("IO expected but got " + args [0 ].getMetaClass ().getName ());
158158 }
159- this . callMethod ( context , "io= " , this .io = (RubyIO ) args [0 ]);
160- this . callMethod ( context , " context= " , sslContext );
159+ setInstanceVariable ( "@io " , this .io = (RubyIO ) args [0 ]); // compat (we do not read @io)
160+ setInstanceVariable ( "@ context" , this . sslContext ); // only compat (we do not use @context)
161161 // This is a bit of a hack: SSLSocket should share code with
162162 // RubyBasicSocket, which always sets sync to true.
163163 // Instead we set it here for now.
164- this .io . callMethod (context , "sync=" , runtime .getTrue ());
164+ this .set_sync (context , runtime .getTrue ()); // io.sync = true
165165 this .callMethod (context , "sync_close=" , runtime .getFalse ());
166166 sslContext .setup (context );
167167 return Utils .invokeSuper (context , this , args , Block .NULL_BLOCK ); // super()
@@ -175,7 +175,7 @@ private SSLEngine ossl_ssl_setup(final ThreadContext context)
175175 // Server Name Indication (SNI) RFC 3546
176176 // SNI support will not be attempted unless hostname is explicitly set by the caller
177177 String peerHost = this .callMethod (context , "hostname" ).toString ();
178- final int peerPort = socketChannelImpl ().getSocketPort ();
178+ final int peerPort = socketChannelImpl ().getRemotePort ();
179179 engine = sslContext .createSSLEngine (peerHost , peerPort );
180180
181181 final javax .net .ssl .SSLSession session = engine .getSession ();
@@ -189,8 +189,24 @@ private SSLEngine ossl_ssl_setup(final ThreadContext context)
189189 return this .engine = engine ;
190190 }
191191
192+ @ JRubyMethod (name = "io" , alias = "to_io" )
193+ public final RubyIO io () { return this .io ; }
194+
195+ @ JRubyMethod (name = "context" )
196+ public final SSLContext context () { return this .sslContext ; }
197+
198+ @ JRubyMethod (name = "sync" )
199+ public IRubyObject sync (final ThreadContext context ) {
200+ return this .io .callMethod (context , "sync" );
201+ }
202+
203+ @ JRubyMethod (name = "sync=" )
204+ public IRubyObject set_sync (final ThreadContext context , final IRubyObject sync ) {
205+ return this .io .callMethod (context , "sync=" , sync );
206+ }
207+
192208 @ JRubyMethod
193- public IRubyObject connect (ThreadContext context ) {
209+ public IRubyObject connect (final ThreadContext context ) {
194210 return connectImpl (context , true );
195211 }
196212
@@ -728,7 +744,7 @@ private IRubyObject do_syswrite(final ThreadContext context,
728744 written = write (b1 , blocking );
729745 }
730746
731- this .callMethod ( context , "io" ) .callMethod (context , "flush" );
747+ this .io .callMethod (context , "flush" );
732748
733749 return runtime .newFixnum (written );
734750 }
@@ -787,7 +803,7 @@ public IRubyObject sysclose(final ThreadContext context) {
787803 close ( sslContext .isProtocolForClient () );
788804
789805 if ( this .callMethod (context , "sync_close" ).isTrue () ) {
790- this .callMethod ( context , "io" ) .callMethod (context , "close" );
806+ this .io .callMethod (context , "close" );
791807 }
792808 return context .runtime .getNil ();
793809 }
@@ -929,7 +945,7 @@ private static interface SocketChannelImpl {
929945
930946 int write (ByteBuffer src ) throws IOException ;
931947
932- int getSocketPort () ;
948+ int getRemotePort () ;
933949
934950 boolean isSelectable () ;
935951
@@ -965,7 +981,7 @@ public int write(ByteBuffer src) throws IOException {
965981 return channel .write (src );
966982 }
967983
968- public int getSocketPort () { return channel .socket ().getPort (); }
984+ public int getRemotePort () { return channel .socket ().getPort (); }
969985
970986 public boolean isSelectable () {
971987 return true ; // return channel instanceof SelectableChannel;
0 commit comments