protected int doWriteMessages(MessageBuf<Object> buf, boolean lastSpin) throws Exception {
DatagramPacket packet = (DatagramPacket) buf.peek();
ByteBuf data = packet.data();
int dataLen = data.readableBytes();
ByteBuffer nioData;
if (data.nioBufferCount() == 1) {
nioData = data.nioBuffer();
} else {
nioData = ByteBuffer.allocate(dataLen);
data.getBytes(data.readerIndex(), nioData);
nioData.flip();