Created
August 12, 2014 20:25
-
-
Save clebertsuconic/4a3d472b67f6ff262f58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void write(final ChannelHandlerContext ctx) { | |
synchronized (lock) { | |
while (true) { | |
int pending = transport.pending(); | |
if (pending > 0) { | |
final int size = pending - offset; | |
if (size > 0) { | |
ByteBuf buffer = Unpooled.buffer(size); | |
ByteBuffer head = transport.head(); | |
head.position(offset); | |
buffer.writeBytes(head); | |
ChannelFuture chf = ctx.writeAndFlush(buffer); | |
offset += size; | |
chf.addListener(new ChannelFutureListener() { | |
@Override | |
public void operationComplete(ChannelFuture chf) { | |
if (chf.isSuccess()) { | |
synchronized (lock) { | |
transport.pop(size); | |
offset -= size; | |
} | |
write(ctx); // <<<< I don't like this!!!!! | |
dispatch(); | |
} else { | |
// ??? | |
} | |
} | |
}); | |
} else { | |
return; | |
} | |
} else { | |
if (pending < 0) { | |
closeOnFlush(ctx.channel()); | |
} | |
return; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment