KLALB 3.6.0开发一半的状态
This commit is contained in:
@@ -1,39 +1,21 @@
|
||||
package org.kne.cloud.network.klalb;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.ProtocolFamily;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketOption;
|
||||
import java.net.SocketOptions;
|
||||
import java.net.StandardProtocolFamily;
|
||||
import java.net.StandardSocketOptions;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.AsynchronousSocketChannel;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.GatheringByteChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.ScatteringByteChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.kne.cloud.network.BufferedChannel;
|
||||
import org.kne.cloud.network.ByteBufferAllocator;
|
||||
import org.kne.cloud.network.MultipurposeSocketAddress;
|
||||
import org.kne.cloud.network.NetworkPacket;
|
||||
import org.kne.cloud.network.ThreadTool;
|
||||
import org.kne.cloud.network.TimeoutTimer;
|
||||
import org.kne.io.KNEChannels;
|
||||
|
||||
public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implements KLALBPacketLink {
|
||||
@@ -64,7 +46,8 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
public String toString() {
|
||||
try {
|
||||
return new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getLocalAddress())+"←"+new MultipurposeSocketAddress("TCP",(InetSocketAddress)connectSocket.getRemoteAddress());
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "?←?";
|
||||
}
|
||||
}
|
||||
@@ -184,19 +167,20 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
@Override
|
||||
public void writeKLALBPacket(KLALBPacket kp) throws IOException {
|
||||
|
||||
ByteBuffer szeWrite=NetworkPacket.bufferAllocator.allocate(4);
|
||||
/*ByteBuffer szeWrite=NetworkPacket.bufferAllocator.allocate(4);
|
||||
szeWrite.limit(4);
|
||||
//szeWrite.clear();
|
||||
int length=(int) kp.getTotalLength();
|
||||
szeWrite.putInt(length);
|
||||
szeWrite.putInt(0,length);
|
||||
szeWrite.flip();
|
||||
|
||||
|
||||
|
||||
writableChannel.write(szeWrite);
|
||||
writableChannel.write(szeWrite);*/
|
||||
|
||||
if(debug) {
|
||||
|
||||
int length=(int) kp.getTotalLength();
|
||||
AtomicLong al=new AtomicLong(0);
|
||||
KLALBPacket.writeKLALBPacketToChannel(new MonitoredChannel(writableChannel,null,new AtomicLong[] { al}), kp);
|
||||
if(length!=al.get()) {
|
||||
@@ -212,19 +196,23 @@ public class StreamChannelKLALBPacketLink extends AbstractKLALBPacketLink implem
|
||||
private void checkflush() throws IOException {
|
||||
if(writableChannel instanceof BufferedChannel) {
|
||||
((BufferedChannel) writableChannel).flush();
|
||||
}else if(writableChannel instanceof KLALBVirtualSocketChannel) {
|
||||
((KLALBVirtualSocketChannel) writableChannel).flush();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KLALBPacket readKLALBPacket() throws IOException {
|
||||
|
||||
ByteBuffer szeWrite=NetworkPacket.bufferAllocator.allocate(4);
|
||||
/*ByteBuffer szeWrite=NetworkPacket.bufferAllocator.allocate(4);
|
||||
szeWrite.limit(4);
|
||||
KNEChannels.readFully(readableChannel, szeWrite);
|
||||
szeWrite.flip();
|
||||
int readSize=szeWrite.getInt();
|
||||
int readSize=szeWrite.getInt();*/
|
||||
KLALBPacket kp=KLALBPacket.readKLALBPacketFromChannel(readableChannel);
|
||||
if(debug) {
|
||||
int readSize=0;
|
||||
long kpl=kp.getTotalLength();
|
||||
if(kpl!=readSize) {
|
||||
throw new StreamCorruptedException(kp+" packet length error:"+kpl+"!="+readSize);
|
||||
|
||||
Reference in New Issue
Block a user