From: <rhy...@gm...> - 2007-11-27 02:00:24
|
Hi, all I have posted this in asio user group. And I think it is also important for cpp-netlib. I think filter chain is an important facility for almost every some what complicated network application. Say, I want 1. do RC4 encryption/decryption, 2. zip/unzip the byte stream, 3. encode/decode a protocol specific class instance into/from plain byte stream. Then we need 3 filters: an RC4 filter, a compression filter, and a protocol codec filter. We assemble these filters into a filter chain, and attach the filter chain to sessions. There are several choices, say compile time static filter chain or runtime assembled dynamic filter chain? And filters often maintains session specific states, if we store the states in the filters, we should maintain one filter chain per session. If we store the states in the session object, and make all filters stateless, then all session can share a single filter chain. But the session object must meet the concept that all the filters requires. Say, the RC4 encoder/decoder pair are not stateless, thus cannot be stored in the rc4_filter instance, and rc4_filter may requires the session object having two public method: rc4_encoder& get_rc4_encoder(); rc4_decoder& get_rc4_decoder(); What do you think? And I recommend a glance at the Apache MINA project, which have a rather flexible filter chain facility. Here's the site: http://mina.apache.org/ Cheers Cheng |