性能优化

This commit is contained in:
Administrator
2022-11-27 06:36:27 +08:00
parent 642c197143
commit 4f2b416ac3
10 changed files with 129 additions and 372 deletions
@@ -34,7 +34,6 @@ public class TCPConnection {
}
public void close() {
// TODO 自动生成的方法存根
try {
if (din != null)
din.close();
@@ -70,36 +69,19 @@ public class TCPConnection {
public TCPConnection(Tunnel t) throws UnknownHostException, IOException {
this(t, t.connectClientSocket());
}
public TCPConnection(Tunnel t, Socket soc) throws IOException {
connect = soc;
tunnel = t;
// connect.setSoTimeout(10000);
din = new DataInputStream(new BufferedInputStream(connect.getInputStream(), 65536));
dout = new DataOutputStream(new BufferedOutputStream(connect.getOutputStream(), 65536));
ThreadTool.makeVThreadIfSupport("FLUSH", () -> {
try {
while (true) {
Thread.sleep(10);
if(flush) {
synchronized (dout) {
dout.flush();
}
flush=false;
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
private volatile boolean flush = false;
public void flush() throws IOException {
flush = true;
public boolean isOpen() {
if(connect==null) {
return false;
}
return !connect.isClosed();
}
}