Protocol wrapping?
Anton Berezin
tobez at tobez.org
Wed Jan 18 18:42:44 CET 2012
Hi,
On Mon, Jan 16, 2012 at 10:08:14PM +0100, Marc Lehmann wrote:
> On Fri, Jan 13, 2012 at 01:48:25PM +0100, Anton Berezin <tobez at tobez.org> wrote:
> > To me this sounds like a job for a (rather thin) wrapper around
> > AnyEvent::Handle.
> If I understand you correctly, what you would ideally want is some kind
> of filter, or, better yet, the ability to add filter layers between the
> AE::Handle api and the low-level socket.
This is precisely correct.
> That is indeed something that I am pondering about for quite a while, and
> something that AE::Handle wasn't designed for, and something I didn't want
> to implement for speed reasons.
I could not help but notice that from the practical standpoint TLS support
in AE::Handle is basically a filter layer, albeit introduced at a pretty low
level (so not easily adapted for other needs).
> It's uncommon for sure, but I think it's very clean. The reason you
> don't see this thing often is that going through the kernel is quite the
> overhead, but clean... clean it is.
>
> > I am pretty new to AnyEvent, so I would not be surprized if I
> > missed a better, more idiomatic/less ugly way of achieving this.
>
> Not really, if you must do it transparently.
> Another way to do it without the overhead, but less flexible, is to implement
> user-defined read/write types, e.g.:
>
> sub Blabla::Telnet::anyevent_read_type {
> my ($hdl, $cb, @ergs) = @_;
> ...
> }
>
> $handle->push_read (Blabla::Telnet => ...
>
> And do the necessary stripping inside these. That is less flexible, but
> probably easier to use.
I do not see how it is easier to use, considering that the application
is interested in a certain structure of the data stream "above" the
telnet commands, and telnet sequences may appear anywhere within the data
stream...
> Yet another way would be to subclass AnyEvent::Handle and provide your own
> push_read/push_write methods.
>
> So.... nothing really wrong with your approach, if it works for you.
Thanks for your reply. Do you think there is much of a chance to
see filter layers support in AE::Handle in a not-so-distant future?
I the meantime I think I will continue using socket pairs for that.
Cheers,
\Anton.
--
Our society can survive even a large amount of irrational regulation.
-- John McCarthy
More information about the anyevent
mailing list