]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
* Add support for the async write op
authoradrian <>
Sun, 12 Aug 2001 21:29:58 +0000 (21:29 +0000)
committeradrian <>
Sun, 12 Aug 2001 21:29:58 +0000 (21:29 +0000)
* Make sure we call freefunc() on the buffer in the write op case

src/fs/coss/async_io.cc

index 55d46cf4d87e0dda2f39c10fd9ecf8784011786e..0f6045000fa8e1edd7e8d1a31db6469b665fc5a2 100644 (file)
@@ -11,7 +11,7 @@
  * supports are read/write, and since COSS works on a single file
  * per storedir it should work just fine.
  *
- * $Id: async_io.cc,v 1.3 2001/08/12 14:58:24 adrian Exp $
+ * $Id: async_io.cc,v 1.4 2001/08/12 15:29:58 adrian Exp $
  */
 
 #include "squid.h"
@@ -105,13 +105,47 @@ void
 a_file_write(async_queue_t *q, int fd, off_t offset, void *buf, int len,
   DWCB *callback, void *data, FREE *freefunc)
 {
+       int slot;
+       async_queue_entry_t *qe;
+
        assert(q->aq_state == AQ_STATE_SETUP);
 
+#if 0
        file_write(fd, offset, buf, len, callback, data, freefunc);
+#endif
        /* Find a free slot */
+       slot = a_file_findslot(q);
+       if (slot < 0) {
                /* No free slot? Callback error, and return */
+               fatal("Aiee! out of aiocb slots!\n");
+       }
+
        /* Mark slot as ours */
+       qe = &q->aq_queue[slot];
+       qe->aq_e_state = AQ_ENTRY_USED;
+       qe->aq_e_callback.write = callback;
+       qe->aq_e_callback_data = data;
+       qe->aq_e_type = AQ_ENTRY_WRITE;
+       qe->aq_e_free = freefunc;
+       qe->aq_e_buf = buf;
+       qe->aq_e_fd = fd;
+
+       qe->aq_e_aiocb.aio_fildes = fd;
+       qe->aq_e_aiocb.aio_nbytes = len;
+       qe->aq_e_aiocb.aio_offset = offset;
+       qe->aq_e_aiocb.aio_buf = buf;
+
+       /* Account */
+       q->aq_numpending++;
+
+       /* Lock */
+       cbdataLock(data);
+
        /* Initiate aio */
+       if (aio_write(&qe->aq_e_aiocb) < 0) {
+               debug(1, 1)("Aiee! aio_read() returned error (%d)!\n", errno);
+               assert(1==0);
+       }
 }
 
 
@@ -175,6 +209,8 @@ a_file_callback(async_queue_t *q)
                                                wc(fd, reterr, retval, callback_data);
                                }
                                cbdataUnlock(callback_data);
+                               if (type == AQ_ENTRY_WRITE && freefunc)
+                                       freefunc(buf);
                        }
                }