From 459fe403a88a8f50c489c9227cdce89cdf205d1a Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 7 Mar 2015 20:13:35 -0800 Subject: [PATCH] Increased the maximum length of incoming NetworkPackages from 1KB to 512KB BUG: 343417 --- .../Backends/LanBackend/LanLinkProvider.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java index 6295f41c..bc8a418f 100644 --- a/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java +++ b/src/org/kde/kdeconnect/Backends/LanBackend/LanLinkProvider.java @@ -158,13 +158,11 @@ public class LanLinkProvider extends BaseLinkProvider { final NioSocketConnector connector = new NioSocketConnector(); connector.setHandler(tcpHandler); - //TextLineCodecFactory will split incoming data delimited by the given string - connector.getFilterChain().addLast("codec", - new ProtocolCodecFilter( - new TextLineCodecFactory(Charset.defaultCharset(), LineDelimiter.UNIX, LineDelimiter.UNIX) - ) - ); connector.getSessionConfig().setKeepAlive(true); + //TextLineCodecFactory will buffer incoming data and emit a message very time it finds a \n + TextLineCodecFactory textLineFactory = new TextLineCodecFactory(Charset.defaultCharset(), LineDelimiter.UNIX, LineDelimiter.UNIX); + textLineFactory.setDecoderMaxLineLength(512*1024); //Allow to receive up to 512kb of data + tcpAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(textLineFactory)); int tcpPort = identityPackage.getInt("tcpPort",port); ConnectFuture future = connector.connect(new InetSocketAddress(address.getAddress(), tcpPort)); @@ -235,17 +233,16 @@ public class LanLinkProvider extends BaseLinkProvider { tcpAcceptor.getSessionConfig().setKeepAlive(true); tcpAcceptor.getSessionConfig().setReuseAddress(true); tcpAcceptor.setCloseOnDeactivation(false); - //TextLineCodecFactory will split incoming data delimited by the given string - tcpAcceptor.getFilterChain().addLast("codec", - new ProtocolCodecFilter( - new TextLineCodecFactory(Charset.defaultCharset(), LineDelimiter.UNIX, LineDelimiter.UNIX) - ) - ); + //TextLineCodecFactory will buffer incoming data and emit a message very time it finds a \n + TextLineCodecFactory textLineFactory = new TextLineCodecFactory(Charset.defaultCharset(), LineDelimiter.UNIX, LineDelimiter.UNIX); + textLineFactory.setDecoderMaxLineLength(512*1024); //Allow to receive up to 512kb of data + tcpAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(textLineFactory)); udpAcceptor = new NioDatagramAcceptor(); - udpAcceptor.getSessionConfig().setReuseAddress(true); //Share port if existing - //TextLineCodecFactory will split incoming data delimited by the given string + udpAcceptor.getSessionConfig().setReuseAddress(true); //Share port if existing + //TextLineCodecFactory will buffer incoming data and emit a message very time it finds a \n + //This one will have the default MaxLineLength of 1KB udpAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter( new TextLineCodecFactory(Charset.defaultCharset(), LineDelimiter.UNIX, LineDelimiter.UNIX)