udp优化
This commit is contained in:
@@ -129,6 +129,11 @@ class AsyncNioUdpConnection extends AsyncNioConnection {
|
||||
}
|
||||
int start = dst.position();
|
||||
dst.put(buf);
|
||||
if (buf.hasRemaining()) {
|
||||
revbufferQueue.offerFirst(buf);
|
||||
} else {
|
||||
udpServerChannel.unsafeBufferPool.accept(buf);
|
||||
}
|
||||
return dst.position() - start;
|
||||
}
|
||||
}
|
||||
@@ -178,7 +183,9 @@ class AsyncNioUdpConnection extends AsyncNioConnection {
|
||||
public final void close() throws IOException {
|
||||
super.close();
|
||||
if (clientMode) {
|
||||
channel.close(); //不能关闭channel
|
||||
channel.close();
|
||||
} else if (remoteAddress != null) {
|
||||
udpServerChannel.connections.remove(remoteAddress);
|
||||
}
|
||||
if (this.connectKey != null) {
|
||||
this.connectKey.cancel();
|
||||
|
||||
@@ -120,6 +120,7 @@ class AsyncNioUdpProtocolServer extends ProtocolServer {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
udpServerChannel.unsafeBufferPool = ObjectPool.createUnsafePool(Thread.currentThread(), 512, safeBufferPool);
|
||||
final AsyncIOThread[] ioReadThreads = ioGroup.ioReadThreads;
|
||||
final AsyncIOThread[] ioWriteThreads = ioGroup.ioWriteThreads;
|
||||
final int reads = ioReadThreads.length;
|
||||
@@ -129,7 +130,7 @@ class AsyncNioUdpProtocolServer extends ProtocolServer {
|
||||
Set<SelectionKey> keys = null;
|
||||
final Selector sel = selector;
|
||||
final DatagramChannel serverChannel = udpServerChannel.serverChannel;
|
||||
ObjectPool<ByteBuffer> unsafeBufferPool = ObjectPool.createUnsafePool(null, 512, safeBufferPool);
|
||||
final ObjectPool<ByteBuffer> unsafeBufferPool = udpServerChannel.unsafeBufferPool;
|
||||
while (!closed) {
|
||||
try {
|
||||
int count = sel.select();
|
||||
@@ -237,6 +238,8 @@ class AsyncNioUdpProtocolServer extends ProtocolServer {
|
||||
|
||||
DatagramChannel serverChannel;
|
||||
|
||||
ObjectPool<ByteBuffer> unsafeBufferPool;
|
||||
|
||||
ConcurrentHashMap<SocketAddress, AsyncNioUdpConnection> connections = new ConcurrentHashMap<>();
|
||||
|
||||
public AsyncNioUdpServerChannel(DatagramChannel serverChannel) {
|
||||
|
||||
Reference in New Issue
Block a user