<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/4.8.5">
</HEAD>
<BODY LINK="#0000ff">
Hello Kale,<BR>
<BR>
Thanks for reporting and the follow up. <BR>
<BR>
I've been working these days on a patch to add full IPv6 support<BR>
to noPoll (adding new APIs to ensure current published API keeps working<BR>
the same). <BR>
<BR>
At the same time, that code update already replaced gethostbyname<BR>
by getaddrinfo, so next stable release, or current github stable release (305)<BR>
[1] should also fix your issue.<BR>
<BR>
Again, thanks for reporting,<BR>
Best Regards,<BR>
<BR>
[1] <A HREF="https://github.com/ASPLes/nopoll">https://github.com/ASPLes/nopoll</A><BR>
<BR>
<BLOCKQUOTE TYPE=CITE>
     <BR>
    <BR>
    Hello,<BR>
    <BR>
     <BR>
    <BR>
    I have narrowed down the cause of intermittent failures in our stress<BR>
    <BR>
    test cases to the use of gethostbyname() in noPoll library.<BR>
    <BR>
    This function is not thread safe under Linux (possibly other platforms too).<BR>
    <BR>
     <BR>
    <BR>
    I fixed this by modifying  function nopoll_conn_sock_connect_opts()<BR>
    <BR>
    This function is used for outbound client connections. <BR>
    <BR>
    Our application makes multiple websocket connections to <BR>
    <BR>
    different hosts in one process. The problem was revealed when<BR>
    <BR>
    I started using dns hosts names instead of IP addresses.<BR>
    <BR>
    I updated the function to use getaddrinfo() instead of gethostbyname().<BR>
    <BR>
    My modifications fixed the stress test failures.<BR>
    <BR>
    There is another place gethostbyname is used that I did not<BR>
    <BR>
    fix since we are not yet using the server (listen) mode.<BR>
    <BR>
     <BR>
    <BR>
    Below is my modified function for reference:<BR>
    <BR>
     <BR>
    <BR>
    NOPOLL_SOCKET nopoll_conn_sock_connect_opts (noPollCtx       * ctx,<BR>
    <BR>
                                                                                         const char      * host,<BR>
    <BR>
                                                                                         const char      * port,<BR>
    <BR>
                                                                                         noPollConnOpts  * options)<BR>
    <BR>
    {<BR>
    <BR>
                    NOPOLL_SOCKET        session;<BR>
    <BR>
                    struct addrinfo hints, *servinfo, *p;<BR>
    <BR>
                    int rc;<BR>
    <BR>
     <BR>
    <BR>
                    memset(&hints, 0, sizeof hints);<BR>
    <BR>
                    hints.ai_family = AF_INET; /* force IPv4 */<BR>
    <BR>
                    hints.ai_socktype = SOCK_STREAM; <BR>
    <BR>
                    if ((rc = getaddrinfo(host, port, &hints, &servinfo)) != 0) {<BR>
    <BR>
                                    nopoll_log (ctx, NOPOLL_LEVEL_DEBUG, "unable to resolve host name %s", host);<BR>
    <BR>
                                    return -1;<BR>
    <BR>
                    }<BR>
    <BR>
                    p = servinfo;<BR>
    <BR>
                    if (p == NULL) {<BR>
    <BR>
                                    nopoll_log (ctx, NOPOLL_LEVEL_DEBUG, "unable to retrieve address for host name %s", host);<BR>
    <BR>
                                    return -1;<BR>
    <BR>
                    }<BR>
    <BR>
     <BR>
    <BR>
                    /* create the socket and check if it */<BR>
    <BR>
                    session      = socket (AF_INET, SOCK_STREAM, 0);<BR>
    <BR>
                    if (session == NOPOLL_INVALID_SOCKET) {<BR>
    <BR>
                                    nopoll_log (ctx, NOPOLL_LEVEL_CRITICAL, "unable to create socket");<BR>
    <BR>
                    freeaddrinfo(servinfo);<BR>
    <BR>
                                    return -1;<BR>
    <BR>
                    } /* end if */<BR>
    <BR>
     <BR>
    <BR>
                    /* disable nagle */<BR>
    <BR>
                    nopoll_conn_set_sock_tcp_nodelay (session, nopoll_true);<BR>
    <BR>
     <BR>
    <BR>
                    /* bind to specified interface */<BR>
    <BR>
                    if( nopoll_true != nopoll_conn_set_bind_interface (session, options) ) {<BR>
    <BR>
                                    nopoll_log (ctx, NOPOLL_LEVEL_CRITICAL, "unable to bind to specified interface");<BR>
    <BR>
                                    nopoll_close_socket (session);<BR>
    <BR>
                                    freeaddrinfo(servinfo);<BR>
    <BR>
                                    return -1;<BR>
    <BR>
                    } /* end if */<BR>
    <BR>
     <BR>
    <BR>
                    /* set non blocking status */<BR>
    <BR>
                    nopoll_conn_set_sock_block (session, nopoll_false);<BR>
    <BR>
     <BR>
    <BR>
                    /* do a tcp connect */<BR>
    <BR>
                    if (connect (session, p->ai_addr, p->ai_addrlen) < 0) {<BR>
    <BR>
                                    if(errno != NOPOLL_EINPROGRESS && errno != NOPOLL_EWOULDBLOCK && errno != NOPOLL_ENOTCONN) {<BR>
    <BR>
                                            shutdown (session, SHUT_RDWR);<BR>
    <BR>
                            nopoll_close_socket (session);<BR>
    <BR>
     <BR>
    <BR>
                                                    nopoll_log (ctx, NOPOLL_LEVEL_WARNING, "unable to connect to remote host %s:%s errno=%d",<BR>
    <BR>
                                                                        host, port, errno);<BR>
    <BR>
                                    freeaddrinfo(servinfo);<BR>
    <BR>
                                                    return -1;<BR>
    <BR>
                                    } /* end if */<BR>
    <BR>
                    } /* end if */<BR>
    <BR>
     <BR>
    <BR>
                    freeaddrinfo(servinfo);<BR>
    <BR>
     <BR>
    <BR>
                    /* return socket created */<BR>
    <BR>
                    return session;<BR>
    <BR>
    }<BR>
    <BR>
     <BR>
    <BR>
     <BR>
    <BR>
    Regards,<BR>
    <BR>
     <BR>
    <BR>
    Rahul<BR>
    <BR>
     <BR>
    <BR>
     <BR>
    <BR>
     <BR>
    <BR>
     <BR>
    <BR>
    Rahul Kale<BR>
    <BR>
     <BR>
    <BR>
    IP Video Systems<BR>
    <BR>
    Barco, Inc<BR>
    <BR>
    1287 Anvilwood Ave<BR>
    <BR>
    Sunnyvale, CA  94089<BR>
    <BR>
     <BR>
    <BR>
    Tel  +1 408 400 4238<BR>
    <BR>
     <BR>
    <BR>
    <BR>
</BLOCKQUOTE>
<BLOCKQUOTE TYPE=CITE>
    This message is subject to the following terms and conditions: <A HREF="http://www.barco.com/en/maildisclaimer">MAIL DISCLAIMER</A>
<PRE>
_______________________________________________
noPoll mailing list
<A HREF="mailto:noPoll@lists.aspl.es">noPoll@lists.aspl.es</A>
<A HREF="http://lists.aspl.es/cgi-bin/mailman/listinfo/nopoll">http://lists.aspl.es/cgi-bin/mailman/listinfo/nopoll</A>
</PRE>
</BLOCKQUOTE>
<BR>
</BODY>
</HTML>