重发数据包优先
This commit is contained in:
@@ -10,6 +10,7 @@ import java.io.OutputStream;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Queue;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
@@ -18,8 +19,11 @@ import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
import org.kne.cloud.network.mport.IPPort;
|
||||
import org.kne.io.AddInputStream;
|
||||
@@ -40,6 +44,8 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
|
||||
}
|
||||
protected void initIOs() throws IOException {
|
||||
connect.setTrafficClass(0x10);
|
||||
connect.setTcpNoDelay(true);
|
||||
OutputStream outm=null;
|
||||
InputStream inm=null;
|
||||
if(tunnel!=null) {
|
||||
@@ -58,8 +64,8 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
}
|
||||
|
||||
|
||||
dout = new DataOutputStream(new BufferedOutputStream(outm,Consts.BLOCKSIZE*2+1) );
|
||||
din = new DataInputStream(new BufferedInputStream(inm,Consts.BLOCKSIZE*2+1));
|
||||
dout = new DataOutputStream(outm);
|
||||
din = new DataInputStream(inm);
|
||||
|
||||
}
|
||||
@Override
|
||||
@@ -133,8 +139,17 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
if (data.data == null) {
|
||||
dout.writeShort(-1);
|
||||
} else {
|
||||
dout.writeShort(data.data.length);
|
||||
dout.write(data.data);
|
||||
Deflater def = new Deflater(Deflater.BEST_COMPRESSION, true);
|
||||
def.setInput(data.data);
|
||||
def.finish();
|
||||
byte[] b = new byte[(int)(data.data.length * 1.1D) + 64];
|
||||
int nsize = def.deflate(b);
|
||||
def.end();
|
||||
this.dout.writeShort(nsize);
|
||||
this.dout.write(b, 0, nsize);
|
||||
/*dout.writeShort(data.data.length);
|
||||
dout.write(data.data);*/
|
||||
//System.out.println(Arrays.toString(data.data));
|
||||
}
|
||||
} else if (data.number == 0) {
|
||||
dout.write(data.command);
|
||||
@@ -165,7 +180,7 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
//System.out.println("SEND:" + data);
|
||||
}
|
||||
|
||||
public KLALBBlock receiveBlock() throws IOException {
|
||||
public KLALBBlock receiveBlock() throws IOException, DataFormatException {
|
||||
KLALBBlock klb = new KLALBBlock();
|
||||
klb.cuid = din.readInt();
|
||||
klb.number = din.readLong();
|
||||
@@ -176,7 +191,18 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
} else {
|
||||
byte[] d = new byte[size];
|
||||
din.readFully(d);
|
||||
klb.data = d;
|
||||
Inflater in = new Inflater(true);
|
||||
in.setInput(d);
|
||||
byte[] b = new byte[8192];
|
||||
int nsize = in.inflate(b);
|
||||
in.end();
|
||||
if (nsize == b.length) {
|
||||
klb.data = b;
|
||||
} else {
|
||||
klb.data = Arrays.copyOf(b, nsize);
|
||||
}
|
||||
//System.out.println(Arrays.toString(d));
|
||||
//klb.data = d;
|
||||
}
|
||||
} else if (klb.number == 0) {
|
||||
klb.command = din.read();
|
||||
@@ -222,7 +248,11 @@ public class RemoteTCPConnection extends TCPConnection {
|
||||
public Queue<KLALBBlock> getNDSendDeque() {
|
||||
return NDsendDeque;
|
||||
}
|
||||
|
||||
private Queue<KLALBBlock> resendDeque = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public Queue<KLALBBlock> getReSendDeque() {
|
||||
return sendDeque;
|
||||
}
|
||||
private Queue<KLALBBlock> sendDeque = new ConcurrentLinkedQueue<>();
|
||||
|
||||
public Queue<KLALBBlock> getSendDeque() {
|
||||
|
||||
Reference in New Issue
Block a user