chiark / gitweb /
build fix
[disorder] / lib / event.c
index 074569508d9a41d3ba553a84cd9738a683ba8a88..96d7d6056ccbb1367b70d0ec0667dac47d2383d5 100644 (file)
@@ -388,6 +388,7 @@ int ev_fd_cancel(ev_source *ev, ev_fdmode mode, int fd) {
  * cancelled.
  */
 int ev_fd_enable(ev_source *ev, ev_fdmode mode, int fd) {
+  assert(fd >= 0);
   D(("enabling mode %s fd %d", modenames[mode], fd));
   FD_SET(fd, &ev->mode[mode].enabled);
   return 0;
@@ -971,15 +972,17 @@ static int writer_shutdown(ev_source *ev,
 
   if(w->fd == -1)
     return 0;                          /* already shut down */
-  info("writer_shutdown fd=%d", w->fd);
+  info("writer_shutdown fd=%d error=%d", w->fd, w->error);
   ev_timeout_cancel(ev, w->timeout);
   ev_fd_cancel(ev, ev_write, w->fd);
   w->timeout = 0;
   if(w->reader) {
+    info("found a tied reader");
     /* If there is a reader still around we just untie it */
     w->reader->writer = 0;
     shutdown(w->fd, SHUT_WR);          /* there'll be no more writes */
   } else {
+    info("no tied reader");
     /* There's no reader so we are free to close the FD */
     xclose(w->fd);
   }
@@ -1064,6 +1067,8 @@ static int ev_writer_write(struct sink *sk, const void *s, int n) {
 
   if(!n)
     return 0;                          /* avoid silliness */
+  if(w->fd == -1)
+    error(0, "ev_writer_write on %s after shutdown", w->what);
   if(w->spacebound && w->b.end - w->b.start + n > w->spacebound) {
     /* The new buffer contents will exceed the space bound.  We assume that the
      * remote client has gone away and TCP hasn't noticed yet, or that it's got
@@ -1237,10 +1242,12 @@ static int reader_shutdown(ev_source *ev,
   ev_fd_cancel(ev, ev_read, r->fd);
   r->eof = 1;
   if(r->writer) {
+    info("found a tied writer");
     /* If there is a writer still around we just untie it */
     r->writer->reader = 0;
     shutdown(r->fd, SHUT_RD);          /* there'll be no more reads */
   } else {
+    info("no tied writer found");
     /* There's no writer so we are free to close the FD */
     xclose(r->fd);
   }