forked from KNEMC/KLALB
延迟优化
This commit is contained in:
@@ -12,61 +12,94 @@ public class TCPConnection {
|
||||
|
||||
private Tunnel tunnel;
|
||||
private Socket connect;
|
||||
private DataInputStream din;
|
||||
public Tunnel getTunnel() {
|
||||
return tunnel;
|
||||
}
|
||||
private DataOutputStream dout;
|
||||
private long delay;
|
||||
public Socket getConnect() {
|
||||
return connect;
|
||||
}
|
||||
public DataInputStream getDin() {
|
||||
return din;
|
||||
}
|
||||
public DataOutputStream getDout() {
|
||||
return dout;
|
||||
}
|
||||
public void close() {
|
||||
// TODO 自动生成的方法存根
|
||||
try {
|
||||
if(din!=null)
|
||||
din.close();
|
||||
} catch (IOException e1) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e1.printStackTrace();
|
||||
private DataInputStream din;
|
||||
|
||||
public Tunnel getTunnel() {
|
||||
return tunnel;
|
||||
}
|
||||
try {
|
||||
if(dout!=null)
|
||||
dout.close();
|
||||
} catch (IOException e1) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e1.printStackTrace();
|
||||
|
||||
private DataOutputStream dout;
|
||||
private long delay;
|
||||
|
||||
public Socket getConnect() {
|
||||
return connect;
|
||||
}
|
||||
try {
|
||||
if(connect!=null)
|
||||
connect.close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
|
||||
public DataInputStream getDin() {
|
||||
return din;
|
||||
}
|
||||
|
||||
public DataOutputStream getDout() {
|
||||
return dout;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
// TODO 自动生成的方法存根
|
||||
try {
|
||||
if (din != null)
|
||||
din.close();
|
||||
} catch (IOException e1) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (dout != null)
|
||||
dout.close();
|
||||
} catch (IOException e1) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (connect != null)
|
||||
connect.close();
|
||||
} catch (IOException e) {
|
||||
// TODO 自动生成的 catch 块
|
||||
e.printStackTrace();
|
||||
}
|
||||
connect = null;
|
||||
}
|
||||
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(long delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
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(100);
|
||||
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;
|
||||
}
|
||||
connect=null;
|
||||
}
|
||||
public long getDelay() {
|
||||
return delay;
|
||||
}
|
||||
public void setDelay(long delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user