mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 03:23:07 +00:00
Disable Nagle on the control socket. Use a single resync thread rather than spawning a new thread each time.
This commit is contained in:
parent
fb437f11a0
commit
f4cf83012e
@ -152,6 +152,8 @@ public class NvControl implements ConnectionStatusListener {
|
|||||||
|
|
||||||
private Thread heartbeatThread;
|
private Thread heartbeatThread;
|
||||||
private Thread jitterThread;
|
private Thread jitterThread;
|
||||||
|
private Thread resyncThread;
|
||||||
|
private Object resyncNeeded = new Object();
|
||||||
private boolean aborting = false;
|
private boolean aborting = false;
|
||||||
|
|
||||||
public NvControl(InetAddress host, NvConnectionListener listener)
|
public NvControl(InetAddress host, NvConnectionListener listener)
|
||||||
@ -164,6 +166,7 @@ public class NvControl implements ConnectionStatusListener {
|
|||||||
{
|
{
|
||||||
s = new Socket();
|
s = new Socket();
|
||||||
s.setSoTimeout(CONTROL_TIMEOUT);
|
s.setSoTimeout(CONTROL_TIMEOUT);
|
||||||
|
s.setTcpNoDelay(true);
|
||||||
s.connect(new InetSocketAddress(host, PORT), CONTROL_TIMEOUT);
|
s.connect(new InetSocketAddress(host, PORT), CONTROL_TIMEOUT);
|
||||||
in = s.getInputStream();
|
in = s.getInputStream();
|
||||||
out = s.getOutputStream();
|
out = s.getOutputStream();
|
||||||
@ -250,6 +253,32 @@ public class NvControl implements ConnectionStatusListener {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
heartbeatThread.start();
|
heartbeatThread.start();
|
||||||
|
|
||||||
|
resyncThread = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (!isInterrupted())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// Wait for notification of a resync needed
|
||||||
|
synchronized (resyncNeeded) {
|
||||||
|
resyncNeeded.wait();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
listener.connectionTerminated(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
requestResync();
|
||||||
|
} catch (IOException e) {
|
||||||
|
listener.connectionTerminated(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
resyncThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startJitterPackets()
|
public void startJitterPackets()
|
||||||
@ -468,16 +497,9 @@ public class NvControl implements ConnectionStatusListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connectionNeedsResync() {
|
public void connectionNeedsResync() {
|
||||||
new Thread(new Runnable() {
|
synchronized (resyncNeeded) {
|
||||||
@Override
|
// Wake up the resync thread
|
||||||
public void run() {
|
resyncNeeded.notify();
|
||||||
try {
|
|
||||||
requestResync();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
abort();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).start();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user