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