diff options
author | Vitaly Litvak <vitavaque@gmail.com> | 2015-10-23 01:46:55 +0300 |
---|---|---|
committer | Vitaly Litvak <vitavaque@gmail.com> | 2015-10-23 01:46:55 +0300 |
commit | c45146fbb6e7d0434f9af4175a7a02e0b5dfc409 (patch) | |
tree | 4e73343cf9bceecebe035a6a02dc04bf13881300 /src/org/traccar | |
parent | 6ee29dddb9294bbbdf09861f87d31720a171d87b (diff) | |
download | trackermap-server-c45146fbb6e7d0434f9af4175a7a02e0b5dfc409.tar.gz trackermap-server-c45146fbb6e7d0434f9af4175a7a02e0b5dfc409.tar.bz2 trackermap-server-c45146fbb6e7d0434f9af4175a7a02e0b5dfc409.zip |
For #1470 - never close UDP channel because only one channel per protocol is used. Added tests for TCP and UDP server closing.
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/MainEventHandler.java | 12 |
1 files changed, 9 insertions, 3 deletions
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(); + } + } } |