From 45defb0268d364fca740093642de3970d439030b Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 22 Dec 2011 16:35:11 -0500 Subject: [PATCH] INT-2333 Mac OSX TCP Workaround on Server Side Mac OSX problem was encountered only on the client; similar code exists on the server side, so the workaround should be implemented there too; just in case. --- .../tcp/connection/TcpNioServerConnectionFactory.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java index 9221c112f9..f0a849d4e5 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioServerConnectionFactory.java @@ -21,6 +21,7 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketException; +import java.nio.channels.CancelledKeyException; import java.nio.channels.ClosedChannelException; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; @@ -112,7 +113,15 @@ public class TcpNioServerConnectionFactory extends AbstractServerConnectionFacto private void doSelect(ServerSocketChannel server, final Selector selector) throws IOException, ClosedChannelException, SocketException { while (this.active) { - int selectionCount = selector.select(this.soTimeout); + int soTimeout = this.getSoTimeout(); + int selectionCount = 0; + try { + selectionCount = selector.select(soTimeout < 0 ? 0 : soTimeout); + } catch (CancelledKeyException cke) { + if (logger.isDebugEnabled()) { + logger.debug("CancelledKeyException during Selector.select()"); + } + } this.processNioSelections(selectionCount, selector, server, this.connections); } }