[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] bufferevent with custom IO



On Wed, Sep 5, 2012 at 5:14 AM, Joachim Bauch <jojo@xxxxxxxxxxx> wrote:
> Hi,
>
> I'm looking for a way to implement a bufferevent that uses a custom API
> to read/write data to the network - similar to what the SSL bufferevent
> does with the OpenSSL BIO.
>
> Any hints on what would be the best way to implement this? The easiest
> solution I came up was to copy most of bufferevent_openssl.c and modify
> "do_read" / "do_write" to use the other API. However this would require
> building a completely custom version of libevent or using various
> internal header files in my application.
>
> I'm thinking about moving all common code from bufferevent_openssl to a
> new bufferevent object that can be customized through callbacks with
> OpenSSL being one implementation.

Sounds like a big but fun project.  You might want to look at
bufferevent_sock.c first; bufferevent_openssl.c has to jump through a
lot of annoying hoops because the TLS protocol has a property that
doing a read at the TLS abstraction may require a write on the
underlying stream, and vice versa.  If your protocol doesn't have that
feature, you can get much, much simpler than something based on
bufferevent_openssl.c.

For any patch here, I'd suggest:
  * Doing as a two-step thing, and not rewriting  the old
bufferevent_openssl.c itself until the new thing is stabilized.
(Assuming you even want to support bufferevent_openssl's weird
read/write model.)
  * Looking at at least two or three other cases beyond your
application and bufferevent_openssl to make sure it's nice and
flexible.
  * Designing the API and circulating it for comment before diving
into the implementation too deeply.

Happy hacking!

-- 
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.