Skip to content

Commit

Permalink
small internal argument polishing
Browse files Browse the repository at this point in the history
kares committed May 27, 2016
1 parent c90d284 commit dd4a666
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/jruby/ext/openssl/SSLSession.java
Original file line number Diff line number Diff line change
@@ -82,13 +82,13 @@ public IRubyObject initialize(final ThreadContext context, final IRubyObject arg
final Ruby runtime = context.runtime;

if ( arg instanceof SSLSocket ) {
return initializeImpl(context, (SSLSocket) arg);
return initializeImpl((SSLSocket) arg);
}

throw runtime.newNotImplementedError("Session#initialize with " + arg.getMetaClass().getName());
}

SSLSession initializeImpl(final ThreadContext context, final SSLSocket socket) {
SSLSession initializeImpl(final SSLSocket socket) {
sslSession = socket.sslSession();
return this;
}
13 changes: 6 additions & 7 deletions src/main/java/org/jruby/ext/openssl/SSLSocket.java
Original file line number Diff line number Diff line change
@@ -1046,12 +1046,12 @@ final javax.net.ssl.SSLSession sslSession() {
@JRubyMethod(name = "session")
public IRubyObject session(final ThreadContext context) {
if ( sslSession() == null ) return context.nil;
return getSession(context);
return getSession(context.runtime);
}

private SSLSession getSession(final ThreadContext context) {
private SSLSession getSession(final Ruby runtime) {
if ( session == null ) {
return session = new SSLSession(context.runtime).initializeImpl(context, this);
return session = new SSLSession(runtime).initializeImpl(this);
}
return session;
}
@@ -1060,24 +1060,23 @@ private SSLSession getSession(final ThreadContext context) {

@JRubyMethod(name = "session=")
public IRubyObject set_session(IRubyObject session) {
final ThreadContext context = getRuntime().getCurrentContext();
// NOTE: we can not fully support this without the SSL provider internals
// but we can assume setting a session= is meant as a forced session re-use
if ( session instanceof SSLSession ) {
setSession = (SSLSession) session;
if ( engine != null ) copySessionSetupIfSet();
}
//warn(context, "WARNING: SSLSocket#session= has not effect");
return context.nil;
return getRuntime().getNil();
}

private void copySessionSetupIfSet() {
if ( setSession != null ) {
if ( reusableSSLEngine() ) {
engine.setEnableSessionCreation(false);
final ThreadContext context = getRuntime().getCurrentContext();
if ( ! setSession.equals( getSession(context) ) ) {
getSession(context).set_timeout(context, setSession.timeout(context));
if ( ! setSession.equals( getSession(context.runtime) ) ) {
getSession(context.runtime).set_timeout(context, setSession.timeout(context));
}
}
}

0 comments on commit dd4a666

Please sign in to comment.