From c45146fbb6e7d0434f9af4175a7a02e0b5dfc409 Mon Sep 17 00:00:00 2001 From: Vitaly Litvak Date: Fri, 23 Oct 2015 01:46:55 +0300 Subject: For #1470 - never close UDP channel because only one channel per protocol is used. Added tests for TCP and UDP server closing. --- src/org/traccar/MainEventHandler.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 8b94a68c9..81376724b 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -20,6 +20,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ExceptionEvent; import org.jboss.netty.channel.MessageEvent; +import org.jboss.netty.channel.socket.DatagramChannel; import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; import org.jboss.netty.handler.timeout.IdleStateEvent; import org.traccar.helper.Log; @@ -61,7 +62,7 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { @Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) { Log.info(formatChannel(e.getChannel()) + " disconnected"); - e.getChannel().close(); + closeChannel(e.getChannel()); Context.getConnectionManager().removeActiveDevice(e.getChannel()); } @@ -69,13 +70,18 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) { Log.warning(formatChannel(e.getChannel()) + " error", e.getCause()); - e.getChannel().close(); + closeChannel(e.getChannel()); } @Override public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) { Log.info(formatChannel(e.getChannel()) + " timed out"); - e.getChannel().close(); + closeChannel(e.getChannel()); } + private void closeChannel(Channel channel) { + if (!(channel instanceof DatagramChannel)) { + channel.close(); + } + } } -- cgit v1.2.3