diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java index 5a5823b15d..b199707cdf 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNioConnection.java @@ -82,7 +82,11 @@ public class TcpNioConnection extends AbstractTcpConnection { public TcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost) throws Exception { super(socketChannel.socket(), server, lookupHost); this.socketChannel = socketChannel; - this.pipedInputStream = new PipedInputStream(); + int receiveBufferSize = socketChannel.socket().getReceiveBufferSize(); + if (receiveBufferSize <= 0) { + receiveBufferSize = this.maxMessageSize; + } + this.pipedInputStream = new PipedInputStream(receiveBufferSize); this.pipedOutputStream = new PipedOutputStream(this.pipedInputStream); this.channelOutputStream = new ChannelOutputStream(); } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java index 63ddeef49e..8cd44f0ff6 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/TcpNioConnectionTests.java @@ -264,6 +264,7 @@ public class TcpNioConnectionTests { return 1025; } }).when(channel).read(Mockito.any(ByteBuffer.class)); + when(socket.getReceiveBufferSize()).thenReturn(1024); final TcpNioConnection connection = new TcpNioConnection(channel, false, false); connection.setTaskExecutor(exec); connection.setPipeTimeout(200);