summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-04-20 04:10:47 (EDT)
committerEike Stepper2008-04-20 04:10:47 (EDT)
commitd014f643cba4c2ba8c3f5939e5ff992e50786295 (patch)
treee45e74dba5a64ee287366d86dda7847a8b8abde1
parent45cb2efcd82a4a81e01c47f5ac14cd6818560976 (diff)
downloadcdo-d014f643cba4c2ba8c3f5939e5ff992e50786295.zip
cdo-d014f643cba4c2ba8c3f5939e5ff992e50786295.tar.gz
cdo-d014f643cba4c2ba8c3f5939e5ff992e50786295.tar.bz2
[227880] [MACOSX] Client registration timeout exception
https://bugs.eclipse.org/bugs/show_bug.cgi?id=227880
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java16
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java6
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java26
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPSelector.java44
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java19
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPActiveSelectorListener.java27
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPPassiveSelectorListener.java23
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java10
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelectorListener.java43
9 files changed, 129 insertions, 85 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
index 7c39aac..1960e01 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
@@ -14,8 +14,8 @@ import org.eclipse.net4j.internal.tcp.bundle.OM;
import org.eclipse.net4j.internal.util.lifecycle.Worker;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.tcp.ITCPAcceptor;
+import org.eclipse.net4j.tcp.ITCPPassiveSelectorListener;
import org.eclipse.net4j.tcp.ITCPSelector;
-import org.eclipse.net4j.tcp.ITCPSelectorListener;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.internal.net4j.acceptor.Acceptor;
@@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit;
/**
* @author Eike Stepper
*/
-public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorListener.Passive
+public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSelectorListener
{
public static final boolean DEFAULT_START_SYNCHRONOUSLY = true;
@@ -118,10 +118,8 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
this.synchronousStartTimeout = synchronousStartTimeout;
}
- public void handleRegistration(SelectionKey selectionKey)
+ public void handleRegistration(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
{
- this.selectionKey = selectionKey;
-
try
{
InetSocketAddress addr = null;
@@ -148,6 +146,9 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
address = address.substring(0, colon);
}
}
+
+ // [MACOSX] Must occur AFTER binding!
+ selectionKey = serverSocketChannel.register(selector.getSocketSelector(), SelectionKey.OP_ACCEPT, this);
}
catch (Exception ex)
{
@@ -192,7 +193,10 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPSelectorL
}
catch (Exception ex)
{
- if (isActive()) OM.LOG.error(ex);
+ if (isActive())
+ {
+ OM.LOG.error(ex);
+ }
deactivate();
}
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
index c6fae7f..418de75 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
@@ -12,11 +12,11 @@ package org.eclipse.net4j.internal.tcp;
import org.eclipse.net4j.connector.ConnectorLocation;
import org.eclipse.net4j.internal.tcp.bundle.OM;
+import org.eclipse.net4j.tcp.ITCPSelector;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.text.MessageFormat;
@@ -85,9 +85,9 @@ public class TCPClientConnector extends TCPConnector
}
@Override
- public void handleRegistration(SelectionKey selectionKey)
+ public void handleRegistration(ITCPSelector selector, SocketChannel socketChannel)
{
- super.handleRegistration(selectionKey);
+ super.handleRegistration(selector, socketChannel);
try
{
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
index d8e9333..b3db21a 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
@@ -18,9 +18,9 @@ import org.eclipse.net4j.internal.tcp.bundle.OM;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.internal.util.security.NegotiationContext;
import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.tcp.ITCPActiveSelectorListener;
import org.eclipse.net4j.tcp.ITCPConnector;
import org.eclipse.net4j.tcp.ITCPSelector;
-import org.eclipse.net4j.tcp.ITCPSelectorListener;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
@@ -41,7 +41,7 @@ import java.util.concurrent.LinkedBlockingQueue;
/**
* @author Eike Stepper
*/
-public abstract class TCPConnector extends Connector implements ITCPConnector, ITCPSelectorListener.Active
+public abstract class TCPConnector extends Connector implements ITCPConnector, ITCPActiveSelectorListener
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TCPConnector.class);
@@ -113,12 +113,26 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
return "tcp://" + host + ":" + port;
}
- public void handleRegistration(SelectionKey selectionKey)
+ public void handleRegistration(ITCPSelector selector, SocketChannel socketChannel)
{
- this.selectionKey = selectionKey;
- if (isServer())
+ try
+ {
+ int interest = isClient() ? SelectionKey.OP_CONNECT : SelectionKey.OP_READ;
+ selectionKey = socketChannel.register(selector.getSocketSelector(), interest, this);
+
+ if (isServer())
+ {
+ leaveConnecting();
+ }
+ }
+ catch (ClosedChannelException ex)
{
- leaveConnecting();
+ deactivate();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ deactivate();
}
}
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 abb204a..cbf9f18 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
@@ -13,14 +13,12 @@ package org.eclipse.net4j.internal.tcp;
import org.eclipse.net4j.internal.tcp.bundle.OM;
import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
+import org.eclipse.net4j.tcp.ITCPActiveSelectorListener;
+import org.eclipse.net4j.tcp.ITCPPassiveSelectorListener;
import org.eclipse.net4j.tcp.ITCPSelector;
-import org.eclipse.net4j.tcp.ITCPSelectorListener;
-import org.eclipse.net4j.tcp.ITCPSelectorListener.Active;
-import org.eclipse.net4j.tcp.ITCPSelectorListener.Passive;
import java.io.IOException;
import java.nio.channels.CancelledKeyException;
-import java.nio.channels.ClosedChannelException;
import java.nio.channels.ClosedSelectorException;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
@@ -44,8 +42,14 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
private Selector selector;
+ /**
+ * Always processed <b>after</b> {@link #serverOperations}.
+ */
private transient Queue<Runnable> clientOperations = new ConcurrentLinkedQueue<Runnable>();
+ /**
+ * Always processed <b>before</b> {@link #clientOperations}.
+ */
private transient Queue<Runnable> serverOperations = new ConcurrentLinkedQueue<Runnable>();
private transient Thread thread;
@@ -56,7 +60,12 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
{
}
- public void orderRegistration(final ServerSocketChannel channel, final Passive listener)
+ public Selector getSocketSelector()
+ {
+ return selector;
+ }
+
+ public void orderRegistration(final ServerSocketChannel channel, final ITCPPassiveSelectorListener listener)
{
assertValidListener(listener);
order(false, new Runnable()
@@ -74,7 +83,8 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
});
}
- public void orderRegistration(final SocketChannel channel, final boolean client, final Active listener)
+ public void orderRegistration(final SocketChannel channel, final boolean client,
+ final ITCPActiveSelectorListener listener)
{
assertValidListener(listener);
order(client, new Runnable()
@@ -211,7 +221,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
ServerSocketChannel ssChannel = (ServerSocketChannel)selKey.channel();
if (ssChannel.isOpen())
{
- ITCPSelectorListener.Passive listener = (ITCPSelectorListener.Passive)selKey.attachment();
+ ITCPPassiveSelectorListener listener = (ITCPPassiveSelectorListener)selKey.attachment();
if (selKey.isAcceptable())
{
@@ -227,7 +237,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
else if (channel instanceof SocketChannel)
{
SocketChannel sChannel = (SocketChannel)channel;
- ITCPSelectorListener.Active listener = (ITCPSelectorListener.Active)selKey.attachment();
+ ITCPActiveSelectorListener listener = (ITCPActiveSelectorListener)selKey.attachment();
if (selKey.isConnectable())
{
@@ -408,7 +418,7 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
}
}
- private void executeRegistration(final ServerSocketChannel channel, final ITCPSelectorListener.Passive listener)
+ private void executeRegistration(final ServerSocketChannel channel, final ITCPPassiveSelectorListener listener)
{
if (TRACER.isEnabled())
{
@@ -417,16 +427,15 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
try
{
- int interest = SelectionKey.OP_ACCEPT;
- SelectionKey selectionKey = channel.register(selector, interest, listener);
- listener.handleRegistration(selectionKey);
+ listener.handleRegistration(this, channel);
}
- catch (ClosedChannelException ignore)
+ catch (Exception ex)
{
+ OM.LOG.debug(ex);
}
}
- private void executeRegistration(final SocketChannel channel, final ITCPSelectorListener.Active listener,
+ private void executeRegistration(final SocketChannel channel, final ITCPActiveSelectorListener listener,
boolean client)
{
if (TRACER.isEnabled())
@@ -436,12 +445,11 @@ public class TCPSelector extends Lifecycle implements ITCPSelector, Runnable
try
{
- int interest = client ? SelectionKey.OP_CONNECT : SelectionKey.OP_READ;
- SelectionKey selectionKey = channel.register(selector, interest, listener);
- listener.handleRegistration(selectionKey);
+ listener.handleRegistration(this, channel);
}
- catch (ClosedChannelException ignore)
+ catch (Exception ex)
{
+ OM.LOG.debug(ex);
}
}
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
index e0608c1..5757072 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPServerConnector.java
@@ -11,8 +11,10 @@
package org.eclipse.net4j.internal.tcp;
import org.eclipse.net4j.connector.ConnectorLocation;
+import org.eclipse.net4j.internal.tcp.bundle.OM;
+import org.eclipse.net4j.tcp.ITCPSelector;
-import java.nio.channels.SelectionKey;
+import java.nio.channels.SocketChannel;
import java.text.MessageFormat;
/**
@@ -75,9 +77,18 @@ public class TCPServerConnector extends TCPConnector
}
@Override
- public void handleRegistration(SelectionKey selectionKey)
+ public void handleRegistration(ITCPSelector selector, SocketChannel socketChannel)
{
- super.handleRegistration(selectionKey);
- acceptor.addConnector(this);
+ super.handleRegistration(selector, socketChannel);
+
+ try
+ {
+ acceptor.addConnector(this);
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ deactivate();
+ }
}
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPActiveSelectorListener.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPActiveSelectorListener.java
new file mode 100644
index 0000000..95b8c73
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPActiveSelectorListener.java
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.tcp;
+
+import java.nio.channels.SocketChannel;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ITCPActiveSelectorListener
+{
+ public void handleRegistration(ITCPSelector selector, SocketChannel socketChannel);
+
+ public void handleConnect(ITCPSelector selector, SocketChannel socketChannel);
+
+ public void handleRead(ITCPSelector selector, SocketChannel socketChannel);
+
+ public void handleWrite(ITCPSelector selector, SocketChannel socketChannel);
+}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPPassiveSelectorListener.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPPassiveSelectorListener.java
new file mode 100644
index 0000000..caf1662
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPPassiveSelectorListener.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.tcp;
+
+import java.nio.channels.ServerSocketChannel;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ITCPPassiveSelectorListener
+{
+ public void handleRegistration(ITCPSelector selector, ServerSocketChannel serverSocketChannel);
+
+ public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel);
+}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java
index 92d15fc..34e19f0 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelector.java
@@ -10,10 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.tcp;
-import org.eclipse.net4j.tcp.ITCPSelectorListener.Active;
-import org.eclipse.net4j.tcp.ITCPSelectorListener.Passive;
-
import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
@@ -22,9 +20,11 @@ import java.nio.channels.SocketChannel;
*/
public interface ITCPSelector
{
- public void orderRegistration(ServerSocketChannel channel, Passive listener);
+ public Selector getSocketSelector();
+
+ public void orderRegistration(ServerSocketChannel channel, ITCPPassiveSelectorListener listener);
- public void orderRegistration(SocketChannel channel, boolean client, Active listener);
+ public void orderRegistration(SocketChannel channel, boolean client, ITCPActiveSelectorListener listener);
public void orderConnectInterest(SelectionKey selectionKey, boolean client, boolean on);
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelectorListener.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelectorListener.java
deleted file mode 100644
index 26c2d1c..0000000
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/ITCPSelectorListener.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.net4j.tcp;
-
-import java.nio.channels.SelectionKey;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-
-/**
- * @author Eike Stepper
- */
-public interface ITCPSelectorListener
-{
- public void handleRegistration(SelectionKey selectionKey);
-
- /**
- * @author Eike Stepper
- */
- public interface Passive extends ITCPSelectorListener
- {
- public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel);
- }
-
- /**
- * @author Eike Stepper
- */
- public interface Active extends ITCPSelectorListener
- {
- public void handleConnect(ITCPSelector selector, SocketChannel channel);
-
- public void handleRead(ITCPSelector selector, SocketChannel socketChannel);
-
- public void handleWrite(ITCPSelector selector, SocketChannel socketChannel);
- }
-}