]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/main-block.c
Doc: Generalized makefile rules for all categories of manpages.
[libucw.git] / ucw / main-block.c
index 7363c2c3690e41e43271756d2eb80cf69aa54173..9efd8a27549a7e8d0faced887421f168a95f2f55 100644 (file)
@@ -1,16 +1,16 @@
 /*
  *     UCW Library -- Main Loop: Block I/O
  *
- *     (c) 2004--2010 Martin Mares <mj@ucw.cz>
+ *     (c) 2004--2011 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
  */
 
-#define 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>
@@ -24,7 +24,7 @@ block_io_timer_expired(struct main_timer *tm)
   struct main_block_io *bio = tm->data;
   timer_del(&bio->timer);
   if (bio->error_handler)
-    bio->error_handler(bio, MFERR_TIMEOUT);
+    bio->error_handler(bio, BIO_ERR_TIMEOUT);
 }
 
 void
@@ -55,8 +55,8 @@ block_io_read_handler(struct main_file *fi)
       if (l < 0)
        {
          if (errno != EINTR && errno != EAGAIN && bio->error_handler)
-           bio->error_handler(bio, MFERR_READ);
-         return 0;
+           bio->error_handler(bio, BIO_ERR_READ);
+         return HOOK_IDLE;
        }
       else if (!l)
        break;
@@ -66,7 +66,7 @@ block_io_read_handler(struct main_file *fi)
   fi->read_handler = NULL;
   file_chg(fi);
   bio->read_done(bio);
-  return 1;
+  return HOOK_RETRY;
 }
 
 static int
@@ -81,8 +81,8 @@ block_io_write_handler(struct main_file *fi)
       if (l < 0)
        {
          if (errno != EINTR && errno != EAGAIN && bio->error_handler)
-           bio->error_handler(bio, MFERR_WRITE);
-         return 0;
+           bio->error_handler(bio, BIO_ERR_WRITE);
+         return HOOK_IDLE;
        }
       bio->wpos += l;
     }
@@ -90,11 +90,11 @@ block_io_write_handler(struct main_file *fi)
   fi->write_handler = NULL;
   file_chg(fi);
   bio->write_done(bio);
-  return 1;
+  return HOOK_RETRY;
 }
 
 void
-block_io_read(struct main_block_io *bio, void *buf, uns len)
+block_io_read(struct main_block_io *bio, void *buf, uint len)
 {
   ASSERT(bio->file.n.next);
   if (len)
@@ -114,7 +114,7 @@ block_io_read(struct main_block_io *bio, void *buf, uns len)
 }
 
 void
-block_io_write(struct main_block_io *bio, void *buf, uns len)
+block_io_write(struct main_block_io *bio, void *buf, uint len)
 {
   ASSERT(bio->file.n.next);
   if (len)
@@ -132,3 +132,12 @@ block_io_write(struct main_block_io *bio, void *buf, uns len)
     }
   file_chg(&bio->file);
 }
+
+void
+block_io_set_timeout(struct main_block_io *bio, timestamp_t expires_delta)
+{
+  if (!expires_delta)
+    timer_del(&bio->timer);
+  else
+    timer_add_rel(&bio->timer, expires_delta);
+}