=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/aucat/Attic/listen.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- src/usr.bin/aucat/Attic/listen.c 2011/05/03 08:00:54 1.16 +++ src/usr.bin/aucat/Attic/listen.c 2011/10/12 07:20:04 1.17 @@ -1,4 +1,4 @@ -/* $OpenBSD: listen.c,v 1.16 2011/05/03 08:00:54 ratchov Exp $ */ +/* $OpenBSD: listen.c,v 1.17 2011/10/12 07:20:04 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -36,6 +36,7 @@ #include "conf.h" #include "listen.h" #include "sock.h" +#include "dbg.h" struct fileops listen_ops = { "listen", @@ -50,6 +51,8 @@ listen_revents }; +struct listen *listen_list = NULL; + void listen_new_un(char *path) { @@ -75,10 +78,6 @@ goto bad_close; } umask(oldumask); - if (listen(sock, 1) < 0) { - perror("listen"); - goto bad_close; - } f = (struct listen *)file_new(&listen_ops, path, 1); if (f == NULL) goto bad_close; @@ -88,6 +87,8 @@ exit(1); } f->fd = sock; + f->next = listen_list; + listen_list = f; return; bad_close: close(sock); @@ -136,10 +137,6 @@ perror("bind"); goto bad_close; } - if (listen(s, 1) < 0) { - perror("listen"); - goto bad_close; - } f = (struct listen *)file_new(&listen_ops, addr, 1); if (f == NULL) { bad_close: @@ -148,6 +145,8 @@ } f->path = NULL; f->fd = s; + f->next = listen_list; + listen_list = f; n++; } freeaddrinfo(ailist); @@ -156,6 +155,16 @@ } int +listen_init(struct listen *f) +{ + if (listen(f->fd, 1) < 0) { + perror("listen"); + return 0; + } + return 1; +} + +int listen_nfds(struct file *f) { return 1; } @@ -211,23 +220,20 @@ void listen_close(struct file *file) { - struct listen *f = (struct listen *)file; + struct listen *f = (struct listen *)file, **pf; if (f->path != NULL) { unlink(f->path); free(f->path); } close(f->fd); -} - -void -listen_closeall(void) -{ - struct file *f, *fnext; - - for (f = LIST_FIRST(&file_list); f != NULL; f = fnext) { - fnext = LIST_NEXT(f, entry); - if (f->ops == &listen_ops) - file_close(f); + for (pf = &listen_list; *pf != f; pf = &(*pf)->next) { +#ifdef DEBUG + if (*pf == NULL) { + dbg_puts("listen_close: not on list\n"); + dbg_panic(); + } +#endif } + *pf = f->next; }