Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-06-11 06:46:35 -0400
committerEike Stepper2013-06-11 06:46:35 -0400
commit50a804b7fe45dbed1d7b7ead2e33597631c731bb (patch)
treebbe17aa05a0b6eeb33d7a8a7c5aff458fe8e6e11
parent6ed03c2aafe6c4d47aeaa86c269ddbd2601012c7 (diff)
downloadcdo-50a804b7fe45dbed1d7b7ead2e33597631c731bb.tar.gz
cdo-50a804b7fe45dbed1d7b7ead2e33597631c731bb.tar.xz
cdo-50a804b7fe45dbed1d7b7ead2e33597631c731bb.zip
[410444] SocketChannel is considered closed if buffer can't be filled
https://bugs.eclipse.org/bugs/show_bug.cgi?id=410444
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java77
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java5
2 files changed, 39 insertions, 43 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
index 68ed2e0183..45acdd3159 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java
@@ -61,6 +61,12 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
return selector;
}
+ @Override
+ public String toString()
+ {
+ return "TCPSelector"; //$NON-NLS-1$
+ }
+
public void orderRegistration(final ServerSocketChannel channel, final ITCPPassiveSelectorListener listener)
{
assertValidListener(listener);
@@ -165,22 +171,26 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
SelectionKey selKey = it.next();
it.remove();
- try
+ SelectableChannel channel = selKey.channel();
+ if (channel.isOpen())
{
- handleSelection(selKey);
- }
- catch (CancelledKeyException ignore)
- {
- // Do nothing
- }
- catch (NullPointerException ignore)
- {
- // Do nothing
- }
- catch (Exception ex)
- {
- OM.LOG.info(ex.getMessage());
- selKey.cancel();
+ try
+ {
+ handleSelection(selKey);
+ }
+ catch (CancelledKeyException ignore)
+ {
+ // Do nothing
+ }
+ catch (NullPointerException ignore)
+ {
+ // Do nothing
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.info(ex.getMessage());
+ selKey.cancel();
+ }
}
}
}
@@ -203,66 +213,55 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
deactivate();
}
- @Override
- public String toString()
- {
- return "TCPSelector"; //$NON-NLS-1$
- }
-
protected void handleSelection(SelectionKey selKey) throws IOException
{
SelectableChannel channel = selKey.channel();
if (channel instanceof ServerSocketChannel)
{
- ServerSocketChannel ssChannel = (ServerSocketChannel)selKey.channel();
- if (ssChannel.isOpen())
- {
- ITCPPassiveSelectorListener listener = (ITCPPassiveSelectorListener)selKey.attachment();
+ ITCPPassiveSelectorListener listener = (ITCPPassiveSelectorListener)selKey.attachment();
- if (selKey.isAcceptable())
+ if (selKey.isAcceptable())
+ {
+ if (TRACER.isEnabled())
{
- if (TRACER.isEnabled())
- {
- TRACER.trace("Accepting " + ssChannel); //$NON-NLS-1$
- }
-
- listener.handleAccept(this, ssChannel);
+ TRACER.trace("Accepting " + channel); //$NON-NLS-1$
}
+
+ listener.handleAccept(this, (ServerSocketChannel)channel);
}
}
else if (channel instanceof SocketChannel)
{
- SocketChannel sChannel = (SocketChannel)channel;
ITCPActiveSelectorListener listener = (ITCPActiveSelectorListener)selKey.attachment();
if (selKey.isConnectable())
{
if (TRACER.isEnabled())
{
- TRACER.trace("Connecting " + sChannel); //$NON-NLS-1$
+ TRACER.trace("Connecting " + channel); //$NON-NLS-1$
}
- listener.handleConnect(this, sChannel);
+ listener.handleConnect(this, (SocketChannel)channel);
}
if (selKey.isReadable())
{
if (TRACER.isEnabled())
{
- TRACER.trace("Reading " + sChannel); //$NON-NLS-1$
+ TRACER.trace("Reading " + channel); //$NON-NLS-1$
}
- listener.handleRead(this, sChannel);
+ listener.handleRead(this, (SocketChannel)channel);
}
if (selKey.isWritable())
{
if (TRACER.isEnabled())
{
- TRACER.trace("Writing " + sChannel); //$NON-NLS-1$
+ TRACER.trace("Writing " + channel); //$NON-NLS-1$
}
- listener.handleWrite(this, sChannel);
+ listener.handleWrite(this, (SocketChannel)channel);
}
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
index 3c95e72645..4294523eef 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
@@ -424,10 +424,7 @@ public class Buffer implements InternalBuffer
{
try
{
- if (socketChannel.read(buffer) == -1)
- {
- throw new ClosedChannelException();
- }
+ socketChannel.read(buffer);
}
catch (ClosedChannelException ex)
{

Back to the top