implement deferred closing

master
leitner 8 years ago
parent b73a699dab
commit 2a0bcc2fb6

@ -11,6 +11,8 @@
extern void io_dontwantread_really(int64 d,io_entry* e); extern void io_dontwantread_really(int64 d,io_entry* e);
extern void io_dontwantwrite_really(int64 d,io_entry* e); extern void io_dontwantwrite_really(int64 d,io_entry* e);
long first_deferred=-1;
void io_close(int64 d) { void io_close(int64 d) {
io_entry* e; io_entry* e;
if ((e=iarray_get(&io_fds,d))) { if ((e=iarray_get(&io_fds,d))) {
@ -27,6 +29,7 @@ void io_close(int64 d) {
#endif #endif
e->mmapped=0; e->mmapped=0;
} }
#if 1
if (e->next_read!=-1 || e->next_write!=-1) { if (e->next_read!=-1 || e->next_write!=-1) {
/* There are still outstanding events. If we close the fd, between /* There are still outstanding events. If we close the fd, between
* now and when those events are handled, another accept() or * now and when those events are handled, another accept() or
@ -35,10 +38,15 @@ void io_close(int64 d) {
* So we don't actually close the fd now, but we will mark it as * So we don't actually close the fd now, but we will mark it as
* closed. */ * closed. */
// fprintf(stderr,"io_close(%d) DEFERRED!\n",d); // fprintf(stderr,"io_close(%d) DEFERRED!\n",d);
e->closed=1; if (e->closed==0) {
e->closed=1;
e->next_defer=first_deferred;
first_deferred=d;
}
return; return;
} else } else
e->closed=0; e->closed=0;
#endif
} }
// fprintf(stderr,"io_close(%d)\n",d); // fprintf(stderr,"io_close(%d)\n",d);
close(d); close(d);

@ -119,6 +119,19 @@ int64 io_waituntil2(int64 milliseconds) {
struct pollfd* p; struct pollfd* p;
#endif #endif
long i,j,r; long i,j,r;
if (first_deferred!=-1) {
while (first_deferred!=-1) {
io_entry* e=iarray_get(&io_fds,first_deferred);
if (e) {
if (e->closed) {
e->closed=0;
close(first_deferred);
}
first_deferred=e->next_defer;
} else
first_deferred=-1; // can't happen
}
}
if (!io_wanted_fds) return 0; if (!io_wanted_fds) return 0;
#ifdef HAVE_EPOLL #ifdef HAVE_EPOLL
if (io_waitmode==EPOLL) { if (io_waitmode==EPOLL) {

Loading…
Cancel
Save