Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2011-10-18 03:38:02 +0000
committerGreg Wilkins2011-10-18 03:38:02 +0000
commite43b718fb1a2aed25d35edd4327687c4468328d1 (patch)
tree590cf9626161fad7522853c87cfb4820a6f247bd /jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java
parente9c398e86b6d64aa6f64395ea4cb3c0af1d341ff (diff)
downloadorg.eclipse.jetty.project-e43b718fb1a2aed25d35edd4327687c4468328d1.tar.gz
org.eclipse.jetty.project-e43b718fb1a2aed25d35edd4327687c4468328d1.tar.xz
org.eclipse.jetty.project-e43b718fb1a2aed25d35edd4327687c4468328d1.zip
Refactored NIO to better handle half closes. Applied the following policy:
Call shutdownOutput to signal the other end that you have written all the data that your are going to write (eg and the end of a non persistent HTTP response). This can be done either by generator (when it is complete) or coordinator or handle - but we need to decide which and have only 1 doing it. Call shutdownInput to signal your own end that you have read -1 and to allow other local code to check that with an isInputShutdown. Ideally we could get by without any calls at all to shutdownInput, so long as we well handle reading -1 (Currently we don't). This should be done by whatever does the IO read. Calling close should always be a real TCP close, even with SSL. SSL shutdown The default handling of an idle callback should be close. But some connections (NOT endpoints) may implement idle as initiating a shutdown exchange (eg websocket close). If they do, this is state that should be held in the connection or parser - ie do-this-exhange-and-then-shutdown Call close when you want to shutdown Output and you have already read -1, so input is already shutdown. We need to double verify that this is correct and that if a FIN has been received from the other end, that a close will not result in a reset. I'll do that today. Call close when you want to shutdown Input and output has already been shutdown. This means you have read -1 after having sent a FIN. Call close on any errors. The current state is that server HttpConnection appears to be working well. Other connection types have not been updated and/or tested
Diffstat (limited to 'jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java')
-rw-r--r--jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java22
1 files changed, 12 insertions, 10 deletions
diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java
index 0b64d34023..eb2a936af8 100644
--- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java
+++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketClientFactory.java
@@ -16,6 +16,7 @@ import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.ConnectedEndPoint;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.SimpleBuffers;
+import org.eclipse.jetty.io.nio.AsyncConnection;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.io.nio.SelectorManager;
import org.eclipse.jetty.util.B64Code;
@@ -207,11 +208,11 @@ public class WebSocketClientFactory extends AggregateLifeCycle
@Override
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, final SelectionKey sKey) throws IOException
{
- return new SelectChannelEndPoint(channel,selectSet,sKey);
+ return new SelectChannelEndPoint(channel,selectSet,sKey,channel.socket().getSoTimeout());
}
@Override
- protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
+ protected AsyncConnection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
{
WebSocketClient.WebSocketFuture holder = (WebSocketClient.WebSocketFuture) endpoint.getSelectionKey().attachment();
return new HandshakeConnection(endpoint,holder);
@@ -255,7 +256,7 @@ public class WebSocketClientFactory extends AggregateLifeCycle
/** Handshake Connection.
* Handles the connection until the handshake succeeds or fails.
*/
- class HandshakeConnection extends AbstractConnection
+ class HandshakeConnection extends AbstractConnection implements AsyncConnection
{
private final SelectChannelEndPoint _endp;
private final WebSocketClient.WebSocketFuture _future;
@@ -370,15 +371,11 @@ public class WebSocketClientFactory extends AggregateLifeCycle
{
while (_endp.isOpen() && !_parser.isComplete())
{
- switch (_parser.parseAvailable())
+ if (!_parser.parseAvailable())
{
- case -1:
+ if (_endp.isInputShutdown())
_future.handshakeFailed(new IOException("Incomplete handshake response"));
- return this;
- case 0:
- return this;
- default:
- break;
+ return this;
}
}
if (_error==null)
@@ -407,6 +404,11 @@ public class WebSocketClientFactory extends AggregateLifeCycle
return this;
}
+ public void onInputShutdown() throws IOException
+ {
+ // TODO
+ }
+
public boolean isIdle()
{
return false;

Back to the top