aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/MainEventHandler.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-23 12:19:01 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-23 12:19:01 +1300
commit0f1fa7f6f88435fc3fb526fe9e732f2f32172071 (patch)
tree4e73343cf9bceecebe035a6a02dc04bf13881300 /src/org/traccar/MainEventHandler.java
parent6ee29dddb9294bbbdf09861f87d31720a171d87b (diff)
parentc45146fbb6e7d0434f9af4175a7a02e0b5dfc409 (diff)
downloadtrackermap-server-0f1fa7f6f88435fc3fb526fe9e732f2f32172071.tar.gz
trackermap-server-0f1fa7f6f88435fc3fb526fe9e732f2f32172071.tar.bz2
trackermap-server-0f1fa7f6f88435fc3fb526fe9e732f2f32172071.zip
Merge pull request #1470 from vitalidze/master
UDP stops listening after failure
Diffstat (limited to 'src/org/traccar/MainEventHandler.java')
-rw-r--r--src/org/traccar/MainEventHandler.java12
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();
+ }
+ }
}