On Thu, Jan 23, 2014 at 7:24 PM, Yann Ylavic <ylavic.dev@gmail.com> wrote:
> Hi,
>
> I'd like to propose the following/attached patch which adds the
> apr_sockaddr_info_copy() function to network_io.
>
Committed to APR trunk as r1587045...
If you are able, could you submit a patch to add a testcase for this? Even
if the testcase isn't interesting, it would be a big head start in case
someone has a need to test a particular aspect of it in the future. Thanks!
>
> It can be useful when one wants an existing apr_sockaddr_t with a
> different lifetime (pool) without a DNS lookup, ie. a redundant/costly call
> to apr_sockaddr_info_get().
>
> I hope it can be useful.
>
> Regards,
> Yann.
>
>
> Index: include/apr_network_io.h
> ===================================================================
> --- include/apr_network_io.h (revision 1560855)
> +++ include/apr_network_io.h (working copy)
> @@ -428,6 +428,15 @@ APR_DECLARE(apr_status_t) apr_sockaddr_info_get(ap
> apr_int32_t flags,
> apr_pool_t *p);
>
> +/**
> + * Copy apr_sockaddr_t src to dst on pool p.
> + * @param dst The destination apr_sockaddr_t.
> + * @param src The source apr_sockaddr_t.
> + * @param p The pool for the apr_sockaddr_t and associated storage.
> + */
> +APR_DECLARE(apr_status_t) apr_sockaddr_info_copy(apr_sockaddr_t **dst,
> + const apr_sockaddr_t
> *src,
> + apr_pool_t *p);
>
> /**
> * Look up the host name from an apr_sockaddr_t.
> Index: network_io/unix/sockaddr.c
> ===================================================================
> --- network_io/unix/sockaddr.c (revision 1560855)
> +++ network_io/unix/sockaddr.c (working copy)
> @@ -660,6 +660,41 @@ APR_DECLARE(apr_status_t) apr_sockaddr_info_get(ap
> return find_addresses(sa, hostname, family, port, flags, p);
> }
>
> +APR_DECLARE(apr_status_t) apr_sockaddr_info_copy(apr_sockaddr_t **dst,
> + const apr_sockaddr_t
> *src,
> + apr_pool_t *p)
> +{
> + apr_sockaddr_t *d;
> + const apr_sockaddr_t *s;
> + for (*dst = d = NULL, s = src; s; s = s->next) {
> + if (!d) {
> + *dst = d = apr_pmemdup(p, s, sizeof *s);
> + }
> + else {
> + d = d->next = apr_pmemdup(p, s, sizeof *s);
> + }
> + if (s->hostname) {
> + if (s == src || s->hostname != src->hostname) {
> + d->hostname = apr_pstrdup(p, s->hostname);
> + }
> + else {
> + d->hostname = (*dst)->hostname;
> + }
> + }
> + if (s->servname) {
> + if (s == src || s->servname != src->servname) {
> + d->servname = apr_pstrdup(p, s->servname);
> + }
> + else {
> + d->servname = (*dst)->servname;
> + }
> + }
> + d->pool = p;
> + apr_sockaddr_vars_set(d, s->family, s->port);
> + }
> + return APR_SUCCESS;
> +}
> +
> APR_DECLARE(apr_status_t) apr_getnameinfo(char **hostname,
> apr_sockaddr_t *sockaddr,
> apr_int32_t flags)
> [EOS]
>
--
Born in Roswell... married an alien...
http://emptyhammock.com/
http://edjective.org/
|