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

Re: [Libevent-users] evhttp client and IPv6



I recently went through a similar experience of trying to get evhttp to work as a client with IPv6. This evolved in the thread "evhttp client error handling". Some of the most important posts in the thread are:

http://archives.seul.org/libevent/users/Nov-2012/msg00015.html
http://archives.seul.org/libevent/users/Jan-2013/msg00041.html
http://archives.seul.org/libevent/users/Jan-2013/msg00057.html

Azat Khuzhin submitted a patch which improved IPv6 support:

https://github.com/libevent/libevent/pull/39

However, this patch is only in libevent/master, which is going to be 2.1, but it's too recent to be in the latest 2.1 tarball release, and it's definitely not in 2.0. So you'll need to live on the bleeding edge to get it.

I've been similarly frustrated with the lack of evhttp client examples, especially ones that properly show how to do error handling, IPv6, and https. I've created a repo (because it's just a little too big to feel comfortable as a gist) with my code in it:

https://github.com/ppelleti/https-example

I'd like to (with some help) get this example into shape where it shows the "best practices" for doing all these things, and then potentially contribute it back to libevent, to go in the "sample" directory, because currently the "sample" directory of the libevent repo only has an http server example, but not an http client example. I've been told that the reason there are so few examples is because the tests also serve as examples, but personally I haven't found the tests all that satisfying as examples, either. So, that's why I'd still like to contribute a client/server example (including https, IPv6, and error handling) for evhttp to the libevent "samples" directory.

Although Azat's patch is a good first step for IPv6 support in evhttp, I think some more work is still necessary. In particular, bufferevent_connect_getaddrinfo_cb() in bufferevent_sock.c has the comment "XXX use the other addrinfos?". I think we need to do this, in case a host has both an IPv4 address and an IPv6 address, but the server is only running on IPv4 or IPv6, but not both. Currently, libevent will only try the first address and give up, but I think it needs to try the other one (e. g. IPv4) if the first one (e. g. IPv6) fails. This is the problem I was running into, since "localhost" resolves to both "::1" and "127.0.0.1", and my server was only running on "127.0.0.1". libevent tried "::1" first, saw no server was running there, and gave up, rather than moving on to "127.0.0.1" which would have succeeded.

The other thing people will tell you is to use libevhtp instead of evhttp. If you don't need Windows support, you might want to look into that. It's not an option for me, though, since I need a cross-platform solution, and libevhtp doesn't (yet) support Windows.

--Patrick


On 02/14/2013 05:17 AM, Grega Kres wrote:
Hello,

I've written a simple program to get data off HTTP servers. The gist of
it is here: https://gist.github.com/gkres/4952640

It works as expected with ipv4, but I can't get it to work with ipv6. I
searched around a bit and I'm getting mixed answers about if this is
possible.

The libevent 2.0.21 source seems to suggest the socket is bound with
AF_INET but some people are claiming it can be done, but don't provide
any useful info beyond saying: "Libevent supports ipv6."

If this is in fact possible can someone help out with a working example?

Any help is appreciated.
Thanks

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