Skip to content

Commit

Permalink
small change to the control flow for public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-valliere committed Feb 24, 2024
1 parent f5f70ed commit 93a4ff7
Showing 1 changed file with 66 additions and 61 deletions.
127 changes: 66 additions & 61 deletions mina-core/src/main/java/org/apache/mina/filter/ssl/SSLHandlerG1.java
Expand Up @@ -143,21 +143,23 @@ public boolean isConnected() {
@Override
public void open(NextFilter next) throws SSLException {
try {
synchronized (this) {
if (mHandshakeStarted == false) {
mHandshakeStarted = true;
if (mEngine.getUseClientMode()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} open() - begin handshaking", this);
}
mEngine.beginHandshake();
write_handshake(next);
}
}
}
open_start(next);
throw_pending_error(next);
} finally {
forward_writes(next);
throw_pending_error(next);
}
}

synchronized protected void open_start(NextFilter next) throws SSLException {
if (mHandshakeStarted == false) {
mHandshakeStarted = true;
if (mEngine.getUseClientMode()) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} open() - begin handshaking", this);
}
mEngine.beginHandshake();
write_handshake(next);
}
}
}

Expand All @@ -168,10 +170,10 @@ public void open(NextFilter next) throws SSLException {
public void receive(NextFilter next, IoBuffer message) throws SSLException {
try {
receive_start(next, message);
throw_pending_error(next);
} finally {
forward_received(next);
forward_writes(next);
throw_pending_error(next);
forward_received(next);
}
}

Expand Down Expand Up @@ -311,25 +313,26 @@ protected void receive_loop(NextFilter next, IoBuffer message) throws SSLExcepti
@Override
public void ack(NextFilter next, WriteRequest request) throws SSLException {
try {
synchronized (this) {
if (mAckQueue.remove(request)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} ack() - accepted {}", toString(), request);
}

if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} ack() - checking to see if any messages can be flushed", toString(), request);
}
flush_start(next);
} else {
if(LOGGER.isWarnEnabled()) {
LOGGER.warn("{} ack() - unknown message {}", toString(), request);
}
}
}
ack_start(next, request);
throw_pending_error(next);
} finally {
forward_writes(next);
throw_pending_error(next);
}
}

synchronized protected void ack_start(NextFilter next, WriteRequest request) throws SSLException {
if (mAckQueue.remove(request)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} ack() - accepted {}", toString(), request);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} ack() - checking to see if any messages can be flushed", toString(), request);
}
flush_start(next);
} else {
if(LOGGER.isWarnEnabled()) {
LOGGER.warn("{} ack() - unknown message {}", toString(), request);
}
}
}

Expand All @@ -339,37 +342,39 @@ public void ack(NextFilter next, WriteRequest request) throws SSLException {
@Override
public void write(NextFilter next, WriteRequest request) throws SSLException, WriteRejectedException {
try {
synchronized (this) {
write_start(next, request);
throw_pending_error(next);
} finally {
forward_writes(next);
}
}

synchronized protected void write_start(NextFilter next, WriteRequest request) throws SSLException, WriteRejectedException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} write() - source {}", toString(), request);
}
if (mOutboundClosing) {
throw new WriteRejectedException(request, "closing");
}
if (mEncodeQueue.isEmpty()) {
if (write_loop(next, request) == false) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} write() - source {}", toString(), request);
}
if (mOutboundClosing) {
throw new WriteRejectedException(request, "closing");
LOGGER.debug("{} write() - unable to write right now, saving request for later", toString(),
request);
}
if (mEncodeQueue.isEmpty()) {
if (write_loop(next, request) == false) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} write() - unable to write right now, saving request for later", toString(),
request);
}
if (mEncodeQueue.size() == MAX_QUEUED_MESSAGES) {
throw new BufferOverflowException();
}
mEncodeQueue.add(request);
}
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} write() - unable to write right now, saving request for later", toString(), request);
}
if (mEncodeQueue.size() == MAX_QUEUED_MESSAGES) {
throw new BufferOverflowException();
}
mEncodeQueue.add(request);
if (mEncodeQueue.size() == MAX_QUEUED_MESSAGES) {
throw new BufferOverflowException();
}
mEncodeQueue.add(request);
}
} finally {
forward_writes(next);
throw_pending_error(next);
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} write() - unable to write right now, saving request for later", toString(), request);
}
if (mEncodeQueue.size() == MAX_QUEUED_MESSAGES) {
throw new BufferOverflowException();
}
mEncodeQueue.add(request);
}
}

Expand Down Expand Up @@ -623,9 +628,9 @@ synchronized protected void finish_handshake(NextFilter next) throws SSLExceptio
public void flush(NextFilter next) throws SSLException {
try {
flush_start(next);
throw_pending_error(next);
} finally {
forward_writes(next);
throw_pending_error(next);
}
}

Expand Down Expand Up @@ -679,9 +684,9 @@ synchronized protected void flush_start(NextFilter next) throws SSLException {
public void close(NextFilter next, boolean linger) throws SSLException {
try {
close_start(next, linger);
throw_pending_error(next);
} finally {
forward_writes(next);
throw_pending_error(next);
}
}

Expand Down

0 comments on commit 93a4ff7

Please sign in to comment.