2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 13:47:41 +00:00

Try to disconnect unused tcp connections

This commit is contained in:
Albert Vaca
2013-09-05 01:03:40 +02:00
parent b4a359d81a
commit 950f684a05

View File

@@ -16,7 +16,6 @@ import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioDatagramAcceptor; import org.apache.mina.transport.socket.nio.NioDatagramAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor; import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketConnector; import org.apache.mina.transport.socket.nio.NioSocketConnector;
import org.kde.connect.ComputerLinks.BaseComputerLink;
import org.kde.connect.ComputerLinks.LanComputerLink; import org.kde.connect.ComputerLinks.LanComputerLink;
import org.kde.connect.NetworkPackage; import org.kde.connect.NetworkPackage;
@@ -45,10 +44,10 @@ public class LanLinkProvider extends BaseLinkProvider {
LanComputerLink brokenLink = nioSessions.remove(session.getId()); LanComputerLink brokenLink = nioSessions.remove(session.getId());
if (brokenLink != null) { if (brokenLink != null) {
connectionLost(brokenLink); connectionLost(brokenLink);
brokenLink.disconnect();
String deviceId = brokenLink.getDeviceId(); String deviceId = brokenLink.getDeviceId();
if (visibleComputers.get(deviceId) == brokenLink) { if (visibleComputers.get(deviceId) == brokenLink) {
visibleComputers.remove(deviceId); visibleComputers.remove(deviceId);
connectionLost(brokenLink);
} }
} }
@@ -161,11 +160,12 @@ public class LanLinkProvider extends BaseLinkProvider {
private void addLink(NetworkPackage identityPackage, LanComputerLink link) { private void addLink(NetworkPackage identityPackage, LanComputerLink link) {
String deviceId = identityPackage.getString("deviceId"); String deviceId = identityPackage.getString("deviceId");
Log.e("LanLinkProvider","addLink to "+deviceId); Log.e("LanLinkProvider","addLink to "+deviceId);
BaseComputerLink oldLink = visibleComputers.get(deviceId); LanComputerLink oldLink = visibleComputers.get(deviceId);
visibleComputers.put(deviceId, link); visibleComputers.put(deviceId, link);
connectionAccepted(identityPackage, link); connectionAccepted(identityPackage, link);
if (oldLink != null) { if (oldLink != null) {
Log.e("LanLinkProvider","Removing old connection to same device"); Log.e("LanLinkProvider","Removing old connection to same device");
oldLink.disconnect();
connectionLost(oldLink); connectionLost(oldLink);
} }
} }