diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-23 12:19:01 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-23 12:19:01 +1300 |
commit | 0f1fa7f6f88435fc3fb526fe9e732f2f32172071 (patch) | |
tree | 4e73343cf9bceecebe035a6a02dc04bf13881300 /src/org/traccar | |
parent | 6ee29dddb9294bbbdf09861f87d31720a171d87b (diff) | |
parent | c45146fbb6e7d0434f9af4175a7a02e0b5dfc409 (diff) | |
download | traccar-server-0f1fa7f6f88435fc3fb526fe9e732f2f32172071.tar.gz traccar-server-0f1fa7f6f88435fc3fb526fe9e732f2f32172071.tar.bz2 traccar-server-0f1fa7f6f88435fc3fb526fe9e732f2f32172071.zip |
Merge pull request #1470 from vitalidze/master
UDP stops listening after failure
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(); + } + } } |