> > Im trying to write a smallnioserver. Its ServerChannel is configured
> > for nonblocking operation. When a SocketChannel becomes readable I
[quoted text clipped - 10 lines]
> make the ByteBuffer itself the attachment. But you must obviously have
> one ByteBuffer per channel.
> i was just hoping for some way to
> avoid copying data and creating new objects but i dont think it can be
> avoided
It can be avoided if you make the attachment the ByteBuffer as I suggested.
> Another issue to deal with now is how/when to clean incomplete
> messages attached to
> selectionKeys that expire/never trigger again so i dont get a memory
> leak.
Don't select forever, select for a finite timeout, which might be say 10
minutes or so. Whenever this expires, i.e. select() returns zero, scan
the keyset of the selector (not the selected keys) and close any
channels which haven't had any recent activity. You will need to keep a
separate map of selection keys, or channels, to date last used.