Skip to content

Commit

Permalink
adds separate event queue - this is temporary because I don't like th…
Browse files Browse the repository at this point in the history
…is solution long term for guaranteeing order of operations
  • Loading branch information
jon-valliere committed Feb 29, 2024
1 parent 93a4ff7 commit ed97be8
Showing 1 changed file with 26 additions and 1 deletion.
Expand Up @@ -24,6 +24,7 @@
import org.apache.mina.core.session.IoSession;
import org.apache.mina.core.write.WriteRejectedException;
import org.apache.mina.core.write.WriteRequest;
import org.apache.mina.filter.FilterEvent;

import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLEngineResult;
Expand All @@ -33,6 +34,7 @@
import java.util.Deque;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.Executor;
import java.util.logging.Filter;

/**
* Default implementation of SSLHandler
Expand Down Expand Up @@ -105,6 +107,11 @@
*/
protected final Deque<IoBuffer> mReceiveQueue = new ConcurrentLinkedDeque<>();

/**
* Pending filter events for dispatching
*/
protected final Deque<FilterEvent> mEventQueue = new ConcurrentLinkedDeque<>();

/**
* Captured error state
*/
Expand Down Expand Up @@ -147,6 +154,7 @@ public void open(NextFilter next) throws SSLException {
throw_pending_error(next);
} finally {
forward_writes(next);
forward_events(next);
}
}

Expand Down Expand Up @@ -174,6 +182,7 @@ public void receive(NextFilter next, IoBuffer message) throws SSLException {
} finally {
forward_writes(next);
forward_received(next);
forward_events(next);
}
}

Expand Down Expand Up @@ -317,6 +326,7 @@ public void ack(NextFilter next, WriteRequest request) throws SSLException {
throw_pending_error(next);
} finally {
forward_writes(next);
forward_events(next);
}
}

Expand Down Expand Up @@ -346,6 +356,7 @@ public void write(NextFilter next, WriteRequest request) throws SSLException, Wr
throw_pending_error(next);
} finally {
forward_writes(next);
forward_events(next);
}
}

Expand Down Expand Up @@ -612,7 +623,7 @@ synchronized protected void finish_handshake(NextFilter next) throws SSLExceptio
if (mHandshakeComplete == false) {
mHandshakeComplete = true;
mSession.setAttribute(SslFilter.SSL_SECURED, mEngine.getSession());
next.event(mSession, SslEvent.SECURED);
mEventQueue.add(SslEvent.SECURED);
}

/**
Expand All @@ -631,6 +642,7 @@ public void flush(NextFilter next) throws SSLException {
throw_pending_error(next);
} finally {
forward_writes(next);
forward_events(next);
}
}

Expand Down Expand Up @@ -687,6 +699,7 @@ public void close(NextFilter next, boolean linger) throws SSLException {
throw_pending_error(next);
} finally {
forward_writes(next);
forward_events(next);
}
}

Expand Down Expand Up @@ -772,6 +785,18 @@ protected void forward_writes(NextFilter next) {
}
}

protected void forward_events(NextFilter next) {
synchronized (mEventQueue) {
FilterEvent x;
while((x = mEventQueue.poll()) != null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} forward_events() - dispatching event {}", toString(), x);
}
next.event(mSession, x);
}
}
}

/**
* Schedule a SSLEngine task for execution, either using an Executor, or immediately.
*
Expand Down

0 comments on commit ed97be8

Please sign in to comment.