KLALB V3.6.0 写了一半
This commit is contained in:
@@ -37,6 +37,7 @@ import org.kne.cloud.network.TimeoutTimer;
|
||||
import org.kne.io.KNEChannels;
|
||||
|
||||
public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||
private static final boolean debug = false;
|
||||
private volatile long timeoutTimer;
|
||||
private volatile boolean timerenabled=false;
|
||||
private boolean enableBuffer=true;
|
||||
@@ -126,6 +127,7 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
checkflush();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -140,7 +142,6 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
ByteBuffer szeWrite=NetworkPacket.bufferAllocator.allocate(4);
|
||||
szeWrite.limit(4);
|
||||
//szeWrite.clear();
|
||||
incOutput(kp.limit());
|
||||
szeWrite.putInt(kp.limit());
|
||||
szeWrite.flip();
|
||||
KLALBVirtualSocketChannel obj = null;
|
||||
@@ -150,42 +151,7 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
|
||||
}
|
||||
|
||||
private ByteBuffer[] bbfwx=new ByteBuffer[100<<1];
|
||||
{
|
||||
for(int i=0;i<100;i++) {
|
||||
bbfwx[i<<1]=NetworkPacket.bufferAllocator.allocate(4);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void writePackets(ByteBuffer[] kpp,int off,int len) throws IOException {
|
||||
if(len>100) {
|
||||
ByteBuffer[] bbfw=new ByteBuffer[len<<1];
|
||||
for(int i=0;i<len;i++) {
|
||||
ByteBuffer szeWrite=NetworkPacket.bufferAllocator.allocate(4);
|
||||
szeWrite.limit(4);
|
||||
//szeWrite.clear();
|
||||
incOutput(kpp[off+i].limit());
|
||||
szeWrite.putInt(kpp[off+i].limit());
|
||||
szeWrite.flip();
|
||||
KLALBVirtualSocketChannel obj = null;
|
||||
bbfw[i<<1]=szeWrite;
|
||||
bbfw[(i<<1)+1]=kpp[off+i];
|
||||
}
|
||||
writableChannel.write(bbfw);
|
||||
}else {
|
||||
for(int i=0;i<len;i++) {
|
||||
bbfwx[i<<1].clear();
|
||||
bbfwx[i<<1].limit(4);
|
||||
incOutput(kpp[off+i].limit());
|
||||
bbfwx[i<<1].putInt(kpp[off+i].limit());
|
||||
bbfwx[i<<1].flip();
|
||||
bbfwx[(i<<1)+1]=kpp[off+i];
|
||||
}
|
||||
writableChannel.write(bbfwx,0,len<<1);
|
||||
}
|
||||
checkflush();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@@ -203,7 +169,6 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
szeRead.flip();
|
||||
int size=szeRead.getInt(0);
|
||||
kp=NetworkPacket.bufferAllocator.allocate(size);
|
||||
incInput(size);
|
||||
kp.limit(size);
|
||||
KNEChannels.readFully(readableChannel, kp);
|
||||
kp.flip();
|
||||
@@ -213,41 +178,7 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeKLALBPackets(List<KLALBPacket> pkts) throws IOException {
|
||||
KLALBVirtualSocketChannel obj = null;
|
||||
if(writableChannel instanceof KLALBVirtualSocketChannel) {
|
||||
obj=(KLALBVirtualSocketChannel) writableChannel;
|
||||
}
|
||||
boolean isaflush=false;
|
||||
if(obj!=null) {
|
||||
isaflush=obj.isAutoFlush();
|
||||
obj.setAutoFlush(false);
|
||||
}
|
||||
ByteBuffer szeWrite=NetworkPacket.bufferAllocator.allocate(4);
|
||||
szeWrite.limit(4);
|
||||
for(KLALBPacket kp:pkts) {
|
||||
szeWrite.clear();
|
||||
int length=(int) kp.getTotalLength();
|
||||
incOutput(length);
|
||||
szeWrite.putInt(length);
|
||||
szeWrite.flip();
|
||||
|
||||
|
||||
writableChannel.write(szeWrite);
|
||||
|
||||
KLALBPacket.writeKLALBPacketToChannel(writableChannel, kp);
|
||||
|
||||
}
|
||||
if(obj!=null) {
|
||||
obj.flush();
|
||||
}
|
||||
|
||||
checkflush();
|
||||
if(obj!=null) {
|
||||
obj.setAutoFlush(isaflush);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@@ -257,35 +188,25 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
szeWrite.limit(4);
|
||||
//szeWrite.clear();
|
||||
int length=(int) kp.getTotalLength();
|
||||
incOutput(length);
|
||||
szeWrite.putInt(length);
|
||||
szeWrite.flip();
|
||||
KLALBVirtualSocketChannel obj = null;
|
||||
if(writableChannel instanceof KLALBVirtualSocketChannel) {
|
||||
obj=(KLALBVirtualSocketChannel) writableChannel;
|
||||
}
|
||||
boolean isaflush=false;
|
||||
if(obj!=null) {
|
||||
isaflush=obj.isAutoFlush();
|
||||
obj.setAutoFlush(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
writableChannel.write(szeWrite);
|
||||
|
||||
if(debug) {
|
||||
|
||||
AtomicLong al=new AtomicLong(0);
|
||||
KLALBPacket.writeKLALBPacketToChannel(new MonitoredChannel(writableChannel,null,new AtomicLong[] { al}), kp);
|
||||
if(length!=al.get()) {
|
||||
throw new StreamCorruptedException(kp+" packet length error:"+al.get()+"!="+length);
|
||||
}
|
||||
}else {
|
||||
KLALBPacket.writeKLALBPacketToChannel(writableChannel, kp);
|
||||
}
|
||||
|
||||
|
||||
KLALBPacket.writeKLALBPacketToChannel(writableChannel, kp);
|
||||
if(obj!=null) {
|
||||
obj.flush();
|
||||
}
|
||||
checkflush();
|
||||
/*AtomicLong al=new AtomicLong(0);
|
||||
KLALBPacket.writeKLALBPacketToChannel(new MonitoredChannel(connectSocket,null,new AtomicLong[] { al}), kp);
|
||||
if(length!=al.get()) {
|
||||
throw new StreamCorruptedException(kp+" packet length error:"+al.get()+"!="+length);
|
||||
}*/
|
||||
if(obj!=null) {
|
||||
obj.setAutoFlush(isaflush);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkflush() throws IOException {
|
||||
@@ -302,13 +223,13 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
KNEChannels.readFully(readableChannel, szeWrite);
|
||||
szeWrite.flip();
|
||||
int readSize=szeWrite.getInt();
|
||||
incInput(readSize);
|
||||
KLALBPacket kp=KLALBPacket.readKLALBPacketFromChannel(readableChannel);
|
||||
/*
|
||||
long kpl=kp.getLength();
|
||||
if(debug) {
|
||||
long kpl=kp.getTotalLength();
|
||||
if(kpl!=readSize) {
|
||||
throw new StreamCorruptedException(kp+" packet length error:"+kpl+"!="+readSize);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
return kp;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user