users@grizzly.java.net

Re: datachannel read/write using ByteBuffer[]

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Thu, 02 Apr 2009 01:53:11 +0200

Hi John,

> I'd like to receeive/send udp datagrams. These datagrams has two
> components: a header and user data. The header is fixed size. My
> software component provides header. So, my component adds header to
> outgoing user data and removes header from incoming user data.
>
> To use Async write, I create a new ByteBuffer, write my header to
> it, and copy user data to it, and call selector handler writeTo I'd
> like to avoid additional allocation and user data copy.
Ok.
>
>
> DataChannel has read/write method that accepts an array of
> ByteBuffer. This is attractive to me because I can avoid a bytecopy
> of user data on the sending side.
>
> AsyncQueueWriter doesn't support Datachannel.write(ByteBuffer[] srcs).
Right, unfortunately it's not supported in AsyncWriteQueue (at least
for now).

> What should I do?
>
> 1) forget about it? if so, why?
no :)
>
>
> 2) modify girzzly, say AsyncQueueWritable, AysncQueueWriter to add
> method that accepts ByteBuffer[] and whatever follows from that?
it's possible.

> 3) other?

If the header has always fixed size (let's say N bytes) - probably it
could make sense to reserve in user data buffer first N bytes. So,
once userdata will be ready - you can prepend header to existing buffer.

Does it make sense?

WBR,
Alexey.


>
>
> Regards,
> John
>