version 1.16, 2011/05/03 08:00:54 |
version 1.17, 2011/10/12 07:20:04 |
|
|
#include "conf.h" |
#include "conf.h" |
#include "listen.h" |
#include "listen.h" |
#include "sock.h" |
#include "sock.h" |
|
#include "dbg.h" |
|
|
struct fileops listen_ops = { |
struct fileops listen_ops = { |
"listen", |
"listen", |
|
|
listen_revents |
listen_revents |
}; |
}; |
|
|
|
struct listen *listen_list = NULL; |
|
|
void |
void |
listen_new_un(char *path) |
listen_new_un(char *path) |
{ |
{ |
|
|
goto bad_close; |
goto bad_close; |
} |
} |
umask(oldumask); |
umask(oldumask); |
if (listen(sock, 1) < 0) { |
|
perror("listen"); |
|
goto bad_close; |
|
} |
|
f = (struct listen *)file_new(&listen_ops, path, 1); |
f = (struct listen *)file_new(&listen_ops, path, 1); |
if (f == NULL) |
if (f == NULL) |
goto bad_close; |
goto bad_close; |
|
|
exit(1); |
exit(1); |
} |
} |
f->fd = sock; |
f->fd = sock; |
|
f->next = listen_list; |
|
listen_list = f; |
return; |
return; |
bad_close: |
bad_close: |
close(sock); |
close(sock); |
|
|
perror("bind"); |
perror("bind"); |
goto bad_close; |
goto bad_close; |
} |
} |
if (listen(s, 1) < 0) { |
|
perror("listen"); |
|
goto bad_close; |
|
} |
|
f = (struct listen *)file_new(&listen_ops, addr, 1); |
f = (struct listen *)file_new(&listen_ops, addr, 1); |
if (f == NULL) { |
if (f == NULL) { |
bad_close: |
bad_close: |
|
|
} |
} |
f->path = NULL; |
f->path = NULL; |
f->fd = s; |
f->fd = s; |
|
f->next = listen_list; |
|
listen_list = f; |
n++; |
n++; |
} |
} |
freeaddrinfo(ailist); |
freeaddrinfo(ailist); |
|
|
} |
} |
|
|
int |
int |
|
listen_init(struct listen *f) |
|
{ |
|
if (listen(f->fd, 1) < 0) { |
|
perror("listen"); |
|
return 0; |
|
} |
|
return 1; |
|
} |
|
|
|
int |
listen_nfds(struct file *f) { |
listen_nfds(struct file *f) { |
return 1; |
return 1; |
} |
} |
|
|
void |
void |
listen_close(struct file *file) |
listen_close(struct file *file) |
{ |
{ |
struct listen *f = (struct listen *)file; |
struct listen *f = (struct listen *)file, **pf; |
|
|
if (f->path != NULL) { |
if (f->path != NULL) { |
unlink(f->path); |
unlink(f->path); |
free(f->path); |
free(f->path); |
} |
} |
close(f->fd); |
close(f->fd); |
} |
for (pf = &listen_list; *pf != f; pf = &(*pf)->next) { |
|
#ifdef DEBUG |
void |
if (*pf == NULL) { |
listen_closeall(void) |
dbg_puts("listen_close: not on list\n"); |
{ |
dbg_panic(); |
struct file *f, *fnext; |
} |
|
#endif |
for (f = LIST_FIRST(&file_list); f != NULL; f = fnext) { |
|
fnext = LIST_NEXT(f, entry); |
|
if (f->ops == &listen_ops) |
|
file_close(f); |
|
} |
} |
|
*pf = f->next; |
} |
} |