- if(res) {
- /* start the new listener */
- if((current_listen_fd = server_start(ev, res->ai_family, res->ai_addrlen,
- res->ai_addr, name)) >= 0) {
- current_listen_addrinfo = res;
- res = 0;
+ }
+
+ /* Open any new listeners that are required */
+ for(r = res; r; r = r->ai_next) {
+ for(l = listeners; l; l = l->next)
+ if(!sockaddrcmp(r->ai_addr, l->sa))
+ break;
+ if(!l) {
+ /* Didn't find a match, need a new listener */
+ int fd = server_start(ev, r->ai_family, r->ai_addrlen, r->ai_addr,
+ format_sockaddr(r->ai_addr));
+ if(fd >= 0) {
+ l = xmalloc(sizeof *l);
+ l->next = listeners;
+ l->sa = copy_sockaddr(r);
+ l->fd = fd;
+ listeners = l;