On Fri, 4 Jan 2008 17:38:23 +0100 "Maarten Bosteels" <[EMAIL PROTECTED]> wrote:
> Hello David, > > On Jan 4, 2008 5:10 PM, David M. Lloyd <[EMAIL PROTECTED]> wrote: > > I've written an IoFilter that is intended to run over TCP, which > > "frames" data into discrete messages in order to make TCP appear to > > preserve message boundaries (like UDP) while still retaining the other > > advantages of TCP (guaranteed delivery, firewall interoperability, etc). > > Isn't this the exact purpose of the ProtocolCodecFilter ? > Have you had a look at > http://mina.apache.org/tutorial-on-protocolcodecfilter-for-mina-2x.html > ? Yes - but more generally applied, rather than being protocol-specific. So for example, if/when SCTP ever becomes available for MINA I can simply remove the TCP+Filter and replace it with SCTP and get similar behavior. Basically I can use an IoHandler that expects discrete messages regardless of the underlying protocol. > I guess you are looking for a ByteArrayCodecFactory that can > encode/decode byte arrays ? > Have a look at http://www.mail-archive.com/dev@mina.apache.org/msg06323.html No, my point is that copying is evil, and using a byte array would require that copying be done. Also the existing solutions all require potentially a great deal of extra copying. FWIW, I opened a feature request for the "framing" business here: https://issues.apache.org/jira/browse/DIRMINA-507 - DML > > My filter definitely *works* but it's not very good. It requires that > > the message length be prepended to each message. I've got a hack in > > such that if the provided outbound buffer has enough space "before" the > > current position, it backs up the position and writes the length there. > > Otherwise it has to copy the whole buffer. In order to make this work > > efficiently, whenever I allocate or flip a buffer I have to "skip" a set > > amount of bytes to "make room" for this data. > > > > On receive, if the incoming buffer contains the whole message, the > > filter can just forward a slice of this buffer to the upper layers. > > Otherwise it has to copy the data into a new, properly-sized buffer. > > > > So I'd like to ask your thoughts on the following: > > > > 1) Support sending multiple buffers in one "go" using gathering-writes > > (the message type could be e.g. Collection<IoBuffer> in this case, or > > perhaps using a composite buffer [see DIRMINA-489 [1]]). > > > > 2) Add support to IoBuffer for reserving "space" at the start of the > > buffer. The semantics would need some thought here though. For > > example, should the buffer capacity include the "reserved" space? > > Probably not I guess. Other questions like this would need to be > > answered as well. I guess I should open a JIRA ticket for this to > > provide a point of reference. > > > > Anyway, let me know what you guys think about this stuff. > > > > - DML > > > > [1] https://issues.apache.org/jira/browse/DIRMINA-489 > >