mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 22:25:08 +00:00
Using setSoTimeout instead of implementing the timeout ourselves
This commit is contained in:
@@ -99,17 +99,8 @@ public class LanLink extends BaseLink {
|
|||||||
OutputStream socket = null;
|
OutputStream socket = null;
|
||||||
try {
|
try {
|
||||||
//Wait a maximum of 10 seconds for the other end to establish a connection with our socket, close it afterwards
|
//Wait a maximum of 10 seconds for the other end to establish a connection with our socket, close it afterwards
|
||||||
Timer timeout = new Timer();
|
server.setSoTimeout(10*1000);
|
||||||
timeout.schedule(new TimerTask() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Log.e("KDE/sendPackage","Timeout");
|
|
||||||
try { server.close(); } catch (Exception e) { }
|
|
||||||
callback.sendFailure(new TimeoutException("Timed out waiting for other end to establish a connection to receive the payload."));
|
|
||||||
}
|
|
||||||
},10*1000);
|
|
||||||
socket = server.accept().getOutputStream();
|
socket = server.accept().getOutputStream();
|
||||||
timeout.cancel();
|
|
||||||
|
|
||||||
Log.i("KDE/LanLink", "Beginning to send payload");
|
Log.i("KDE/LanLink", "Beginning to send payload");
|
||||||
|
|
||||||
@@ -127,7 +118,7 @@ public class LanLink extends BaseLink {
|
|||||||
}
|
}
|
||||||
socket.flush();
|
socket.flush();
|
||||||
stream.close();
|
stream.close();
|
||||||
Log.i("KDE/LanLink", "Finished sending payload");
|
Log.i("KDE/LanLink", "Finished sending payload ("+progress+" bytes written)");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("KDE/sendPackage", "Exception: "+e);
|
Log.e("KDE/sendPackage", "Exception: "+e);
|
||||||
callback.sendFailure(e);
|
callback.sendFailure(e);
|
||||||
|
Reference in New Issue
Block a user