properly count file descriptors

This commit is contained in:
Alexandre Ratchov 2012-09-05 00:50:42 +02:00
parent 526f2d2b92
commit 84d21ff8c2
1 changed files with 4 additions and 2 deletions

View File

@ -221,8 +221,7 @@ file_new(struct fileops *ops, void *arg, char *name, unsigned int nfds)
{ {
struct file *f; struct file *f;
file_nfds += nfds; if (file_nfds + nfds > MAXFDS) {
if (file_nfds > MAXFDS) {
#ifdef DEBUG #ifdef DEBUG
if (log_level >= 1) { if (log_level >= 1) {
log_puts(name); log_puts(name);
@ -232,6 +231,7 @@ file_new(struct fileops *ops, void *arg, char *name, unsigned int nfds)
return NULL; return NULL;
} }
f = xmalloc(sizeof(struct file)); f = xmalloc(sizeof(struct file));
f->nfds = nfds;
f->ops = ops; f->ops = ops;
f->arg = arg; f->arg = arg;
f->name = name; f->name = name;
@ -244,6 +244,7 @@ file_new(struct fileops *ops, void *arg, char *name, unsigned int nfds)
log_puts(": created\n"); log_puts(": created\n");
} }
#endif #endif
file_nfds += f->nfds;
return f; return f;
} }
@ -256,6 +257,7 @@ file_del(struct file *f)
panic(); panic();
} }
#endif #endif
file_nfds -= f->nfds;
f->state = FILE_ZOMB; f->state = FILE_ZOMB;
#ifdef DEBUG #ifdef DEBUG
if (log_level >= 3) { if (log_level >= 3) {