Set hostnamewait and usernamewait earlier. I'm not sure this can matter, but I'm not sure it can't, especially in circumstances like the "newsock >= maxdesc" below.