]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/main-rec.c
Doc: Release dates
[libucw.git] / ucw / main-rec.c
index 06c574944144d4b6b547323ae8c961df93d0e92f..ca313187fdf905490bb498035bff01b7d5e7a1a5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     UCW Library -- Main Loop: Record I/O
  *
 /*
  *     UCW Library -- Main Loop: Record I/O
  *
- *     (c) 2011 Martin Mares <mj@ucw.cz>
+ *     (c) 2011--2012 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -9,8 +9,8 @@
 
 #undef LOCAL_DEBUG
 
 
 #undef LOCAL_DEBUG
 
-#include "ucw/lib.h"
-#include "ucw/mainloop.h"
+#include <ucw/lib.h>
+#include <ucw/mainloop.h>
 
 #include <stdio.h>
 #include <string.h>
 
 #include <stdio.h>
 #include <string.h>
@@ -51,9 +51,11 @@ rec_io_add(struct main_rec_io *rio, int fd)
 void
 rec_io_del(struct main_rec_io *rio)
 {
 void
 rec_io_del(struct main_rec_io *rio)
 {
+  if (!rec_io_is_active(rio))
+    return;
+
   timer_del(&rio->timer);
   timer_del(&rio->timer);
-  if (clist_is_linked(&rio->start_read_hook.n))
-    hook_del(&rio->start_read_hook);
+  hook_del(&rio->start_read_hook);
   file_del(&rio->file);
 
   if (rio->read_buf)
   file_del(&rio->file);
 
   if (rio->read_buf)
@@ -113,7 +115,6 @@ restart: ;
   DBG("RIO READ: rec_start=%u avail=%u prev_avail=%u free=%u/%u",
     rec_start_pos, rio->read_avail, rio->read_prev_avail,
     free_space, rio->read_buf_size);
   DBG("RIO READ: rec_start=%u avail=%u prev_avail=%u free=%u/%u",
     rec_start_pos, rio->read_avail, rio->read_prev_avail,
     free_space, rio->read_buf_size);
-  // FIXME: Constants?
   if (free_space <= rio->read_buf_size/8)
     {
       if (rec_start_pos && rec_start_pos >= rio->read_buf_size/2)
   if (free_space <= rio->read_buf_size/8)
     {
       if (rec_start_pos && rec_start_pos >= rio->read_buf_size/2)
@@ -199,7 +200,7 @@ rec_io_recalc_read(struct main_rec_io *rio)
           * of the work to a main_hook, which will be called in the next iteration
           * of the main loop.
           */
           * of the work to a main_hook, which will be called in the next iteration
           * of the main loop.
           */
-         if (!clist_is_linked(&rio->start_read_hook.n))
+         if (!hook_is_active(&rio->start_read_hook))
            {
              DBG("RIO: Scheduling start of reading");
              hook_add(&rio->start_read_hook);
            {
              DBG("RIO: Scheduling start of reading");
              hook_add(&rio->start_read_hook);
@@ -207,7 +208,7 @@ rec_io_recalc_read(struct main_rec_io *rio)
        }
       else
        {
        }
       else
        {
-         if (clist_is_linked(&rio->start_read_hook.n))
+         if (hook_is_active(&rio->start_read_hook))
            {
              DBG("RIO: Descheduling start of reading");
              hook_del(&rio->start_read_hook);
            {
              DBG("RIO: Descheduling start of reading");
              hook_del(&rio->start_read_hook);
@@ -223,7 +224,7 @@ rec_io_recalc_read(struct main_rec_io *rio)
 void
 rec_io_start_read(struct main_rec_io *rio)
 {
 void
 rec_io_start_read(struct main_rec_io *rio)
 {
-  ASSERT(clist_is_linked(&rio->file.n));
+  ASSERT(rec_io_is_active(rio));
   rio->read_started = 1;
   rec_io_recalc_read(rio);
 }
   rio->read_started = 1;
   rec_io_recalc_read(rio);
 }
@@ -231,7 +232,7 @@ rec_io_start_read(struct main_rec_io *rio)
 void
 rec_io_stop_read(struct main_rec_io *rio)
 {
 void
 rec_io_stop_read(struct main_rec_io *rio)
 {
-  ASSERT(clist_is_linked(&rio->file.n));
+  ASSERT(rec_io_is_active(rio));
   rio->read_started = 0;
   rec_io_recalc_read(rio);
 }
   rio->read_started = 0;
   rec_io_recalc_read(rio);
 }
@@ -240,7 +241,8 @@ static void
 rec_io_stop_write(struct main_rec_io *rio)
 {
   DBG("RIO WRITE: Stopping write");
 rec_io_stop_write(struct main_rec_io *rio)
 {
   DBG("RIO WRITE: Stopping write");
-  ASSERT(!rio->write_watermark);
+  // XXX: When we are called after a write error, there might still
+  // be some data queued, but we need not care.
   rio->file.write_handler = NULL;
   file_chg(&rio->file);
 }
   rio->file.write_handler = NULL;
   file_chg(&rio->file);
 }
@@ -311,7 +313,7 @@ void
 rec_io_write(struct main_rec_io *rio, void *data, uns len)
 {
   byte *bdata = data;
 rec_io_write(struct main_rec_io *rio, void *data, uns len)
 {
   byte *bdata = data;
-  ASSERT(clist_is_linked(&rio->file.n));
+  ASSERT(rec_io_is_active(rio));
   if (!len)
     return;
 
   if (!len)
     return;
 
@@ -420,7 +422,7 @@ main(void)
   main_loop();
   msg(L_INFO, "Finished.");
 
   main_loop();
   msg(L_INFO, "Finished.");
 
-  if (clist_is_linked(&rio.file.n))
+  if (file_is_active(&rio.file))
     rec_io_del(&rio);
   main_cleanup();
   return 0;
     rec_io_del(&rio);
   main_cleanup();
   return 0;