dump connection is disconnected

dump connection is disconnected since SocketChannel.cache is overflow.
This commit is contained in:
jason huang
2018-01-09 18:25:51 +08:00
committed by GitHub
parent 93be9d1909
commit a965d2cd04

View File

@@ -27,10 +27,22 @@ public class SocketChannel {
this.channel = channel;
}
public void writeCache(ByteBuf buf) {
public void writeCache(ByteBuf buf) throws InterruptedException {
synchronized (lock) {
while (true) {
cache.discardReadBytes();// 回收内存
cache.writeBytes(buf);
//source buffer is empty.
if (!buf.isReadable()) {
break;
}
if (cache.isWritable()) {
cache.writeBytes(buf, Math.min(cache.writableBytes(), buf.readableBytes()));
} else {
//dest buffer is full.
lock.wait(100);
}
}
}
}