chiark / gitweb /
Update some copyright dates.
[disorder] / lib / event.c
index 56278f6882188d8a6fb0542142bc3c6547ed59c8..db8b9404407be8263a6a39288439be8d1c6e9633 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2007 Richard Kettlewell
+ * Copyright (C) 2004, 2005, 2007, 2008 Richard Kettlewell
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -161,7 +161,7 @@ static inline int gt(const struct timeval *a, const struct timeval *b) {
 
 /** @brief Greater-than-or-equal comparison for timevals
  *
- * Ought to be in @file lib/timeval.h
+ * Ought to be in @ref lib/timeval.h
  */
 static inline int ge(const struct timeval *a, const struct timeval *b) {
   return !gt(b, a);
@@ -455,7 +455,7 @@ void ev_report(ev_source *ev) {
 
 /** @brief Register a timeout
  * @param ev Event source
- * @param handle Where to store timeout handle, or @c NULL
+ * @param handlep Where to store timeout handle, or @c NULL
  * @param when Earliest time to call @p callback, or @c NULL
  * @param callback Function to call at or after @p when
  * @param u Passed to @p callback
@@ -930,6 +930,9 @@ struct ev_writer {
 
   /** @brief Tied reader or 0 */
   ev_reader *reader;
+
+  /** @brief Set when abandoned */
+  int abandoned;
 };
 
 /** @brief State structure for a buffered reader */
@@ -998,9 +1001,12 @@ static int writer_timebound_exceeded(ev_source *ev,
                                     void *u) {
   ev_writer *const w = u;
 
-  error(0, "abandoning writer %s because no writes within %ds",
-       w->what, w->timebound);
-  w->error = ETIMEDOUT;
+  if(!w->abandoned) {
+    w->abandoned = 1;
+    error(0, "abandoning writer '%s' because no writes within %ds",
+         w->what, w->timebound);
+    w->error = ETIMEDOUT;
+  }
   return writer_shutdown(ev, now, u);
 }
 
@@ -1075,11 +1081,15 @@ static int ev_writer_write(struct sink *sk, const void *s, int n) {
     /* 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
      * hopelessly stuck. */
-    error(0, "abandoning writer %s because buffer has reached %td bytes",
-         w->what, w->b.end - w->b.start);
-    ev_fd_disable(w->ev, ev_write, w->fd);
-    w->error = EPIPE;
-    return ev_timeout(w->ev, 0, 0, writer_shutdown, w);
+    if(!w->abandoned) {
+      w->abandoned = 1;
+      error(0, "abandoning writer '%s' because buffer has reached %td bytes",
+           w->what, w->b.end - w->b.start);
+      ev_fd_disable(w->ev, ev_write, w->fd);
+      w->error = EPIPE;
+      return ev_timeout(w->ev, 0, 0, writer_shutdown, w);
+    } else
+      return 0;
   }
   /* Make sure there is space */
   buffer_space(&w->b, n);