Skip to content
Browse files

- Fixed NIO bug causing hangings. Reported by John Logsdon

  • Loading branch information...
1 parent 6a32115 commit e142785bcad60706ecb996b23ee600e62f69e7d9 @jlouvel jlouvel committed
View
16 modules/org.restlet/src/org/restlet/engine/connector/Connection.java
@@ -749,9 +749,10 @@ public boolean updateState() {
boolean result = true;
if (getState() != ConnectionState.CLOSED) {
+ String oldState = null;
+
if (getHelper().getLogger().isLoggable(Level.FINEST)) {
- getHelper().getLogger().log(Level.FINEST,
- "Old connection NIO interest: " + getRegistration());
+ oldState = getRegistration().toString();
}
getInboundWay().updateState();
@@ -764,12 +765,17 @@ public boolean updateState() {
.getInterestOperations());
if (getHelper().getLogger().isLoggable(Level.FINEST)) {
- getHelper().getLogger().log(Level.FINEST,
- "New connection NIO interest: " + getRegistration());
+ String newState = getRegistration().toString();
+
+ if (!oldState.equals(newState)) {
+ getHelper().getLogger().log(Level.FINEST,
+ "Old connection NIO interest: " + oldState);
+ getHelper().getLogger().log(Level.FINEST,
+ "New connection NIO interest: " + newState);
+ }
}
}
return result;
}
-
}
View
42 modules/org.restlet/src/org/restlet/engine/connector/InboundWay.java
@@ -292,6 +292,12 @@ public int onFill(Buffer buffer, Object... args) throws IOException {
public void onFillEof() {
}
+ @Override
+ protected void onPostProcessing() {
+ // Socket channel exhausted
+ setIoState(IoState.INTEREST);
+ }
+
/**
* Callback invoked when a message has been received. Note that one the
* start line and the headers must have been received, not the optional
@@ -392,16 +398,16 @@ protected void setEntityRegistration(
@Override
public void updateState() {
- if (getHelper().getLogger().isLoggable(Level.FINEST)) {
- getHelper().getLogger().log(Level.FINEST,
- "Old inbound way NIO interest: " + getRegistration());
- getHelper().getLogger().log(
- Level.FINEST,
- "Old inbound entity NIO interest: "
- + getEntityRegistration());
- }
-
if (getMessageState() == MessageState.BODY) {
+ if (getHelper().getLogger().isLoggable(Level.FINEST)) {
+ getHelper().getLogger().log(Level.FINEST,
+ "Old inbound way NIO interest: " + getRegistration());
+ getHelper().getLogger().log(
+ Level.FINEST,
+ "Old inbound entity NIO interest: "
+ + getEntityRegistration());
+ }
+
if ((getEntityRegistration() != null)
&& (getEntityRegistration().getListener() != null)) {
getRegistration().setInterestOperations(
@@ -409,17 +415,17 @@ public void updateState() {
} else {
getRegistration().setInterestOperations(0);
}
+
+ if (getHelper().getLogger().isLoggable(Level.FINEST)) {
+ getHelper().getLogger().log(
+ Level.FINEST,
+ "New inbound entity NIO interest: "
+ + getEntityRegistration());
+ getHelper().getLogger().log(Level.FINEST,
+ "New inbound way NIO interest: " + getRegistration());
+ }
} else {
super.updateState();
}
-
- if (getHelper().getLogger().isLoggable(Level.FINEST)) {
- getHelper().getLogger().log(
- Level.FINEST,
- "New inbound entity NIO interest: "
- + getEntityRegistration());
- getHelper().getLogger().log(Level.FINEST,
- "New inbound way NIO interest: " + getRegistration());
- }
}
}
View
7 modules/org.restlet/src/org/restlet/engine/connector/OutboundWay.java
@@ -318,7 +318,7 @@ public int onDrain(Buffer buffer, int maxDrained, Object... args)
if (result == 0) {
if (getIoState() == IoState.PROCESSING) {
// The byte buffer hasn't been written, the socket
- // channel can't write more. We needs to put the
+ // channel can't write more. We need to put the
// byte buffer in the filling state again and
// wait for a new NIO selection.
setIoState(IoState.INTEREST);
@@ -392,7 +392,10 @@ public void onFillEof() {
@Override
protected void onPostProcessing() {
if ((getMessageState() != MessageState.IDLE) || getBuffer().canDrain()) {
- super.onPostProcessing();
+ // Socket channel exhausted
+ setIoState(IoState.INTEREST);
+ } else {
+ setIoState(IoState.IDLE);
}
}
View
31 modules/org.restlet/src/org/restlet/engine/connector/Way.java
@@ -126,6 +126,14 @@ public boolean canLoop(Buffer buffer, Object... args) {
* pool.
*/
public void clear() {
+ if (getLogger().isLoggable(Level.FINEST)) {
+ if (this instanceof OutboundWay) {
+ getLogger().log(Level.FINEST, "OutboundWay#clear: " + this);
+ } else {
+ getLogger().log(Level.FINEST, "InboundWay#clear: " + this);
+ }
+ }
+
this.buffer.clear();
this.headers = null;
this.ioState = IoState.IDLE;
@@ -332,6 +340,16 @@ public void onClosed() {
* Indicates if the end of the socket channel was detected.
*/
public void onCompleted(boolean endDetected) throws IOException {
+ if (getLogger().isLoggable(Level.FINEST)) {
+ if (this instanceof OutboundWay) {
+ getLogger().log(Level.FINEST,
+ "OutboundWay#onCompleted: " + endDetected);
+ } else {
+ getLogger().log(Level.FINEST,
+ "InboundWay#onCompleted: " + endDetected);
+ }
+ }
+
setIoState(IoState.IDLE);
setMessageState(MessageState.IDLE);
setMessage(null);
@@ -378,10 +396,7 @@ public abstract int onFill(Buffer buffer, Object... args)
* Called back after the IO processing to indicate if there is further IO
* interest. By default, it sets the IO state to {@link IoState#INTEREST}.
*/
- protected void onPostProcessing() {
- // Socket channel exhausted
- setIoState(IoState.INTEREST);
- }
+ protected abstract void onPostProcessing();
/**
* Callback method invoked when the way has been selected for IO operations
@@ -425,6 +440,14 @@ public void onSelected(SelectionRegistration selectionRegistration) {
getConnection().onError("Error while processing a connection", e,
Status.CONNECTOR_ERROR_COMMUNICATION);
}
+
+ if (this instanceof InboundWay) {
+ getLogger().log(Level.FINER,
+ "Inbound way selected. Done for : " + this);
+ } else {
+ getLogger().log(Level.FINER,
+ "Outbound way selected. Done for : " + this);
+ }
}
/**

0 comments on commit e142785

Please sign in to comment.
Something went wrong with that request. Please try again.