aboutsummaryrefslogtreecommitdiffstats
path: root/src/aio_event.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-03-16 17:30:46 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-03-16 17:30:46 +0400
commit312a025f6ea39f044d12f93abc8b503e63ea15ba (patch)
tree558dc1317db7a90ddd447b46a0b4cc7b42da8ee4 /src/aio_event.c
parent02e2d2123b2b09a8e4cf9ef6942973daa4b25c7d (diff)
downloadrspamd-312a025f6ea39f044d12f93abc8b503e63ea15ba.tar.gz
rspamd-312a025f6ea39f044d12f93abc8b503e63ea15ba.zip
Allow multiply aio requests in flight.
Diffstat (limited to 'src/aio_event.c')
-rw-r--r--src/aio_event.c33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/aio_event.c b/src/aio_event.c
index 4df8a54f0..e11b7ec83 100644
--- a/src/aio_event.c
+++ b/src/aio_event.c
@@ -55,6 +55,7 @@ struct io_cbdata {
rspamd_aio_cb cb;
gsize len;
gpointer buf;
+ gpointer io_buf;
gpointer ud;
};
@@ -176,8 +177,6 @@ struct aio_context {
gint event_fd;
struct event eventfd_ev;
aio_context_t io_ctx;
- gpointer buf;
- gsize buflen;
#elif defined(HAVE_AIO_H)
/* POSIX aio */
struct event rtsigs[SIGRTMAX - SIGRTMIN];
@@ -218,6 +217,9 @@ rspamd_eventfdcb (gint fd, gshort what, gpointer ud)
ev_data = (struct io_cbdata *) (uintptr_t) event[i].data;
/* Call this callback */
ev_data->cb (ev_data->fd, event[i].res, ev_data->len, ev_data->buf, ev_data->ud);
+ if (ev_data->io_buf) {
+ free (ev_data->io_buf);
+ }
g_slice_free1 (sizeof (struct io_cbdata), ev_data);
}
}
@@ -320,6 +322,7 @@ rspamd_aio_read (gint fd, gpointer buf, gsize len, off_t offset, struct aio_cont
cbdata->len = len;
cbdata->ud = ud;
cbdata->fd = fd;
+ cbdata->io_buf = NULL;
iocb[0] = alloca (sizeof (struct iocb));
memset (iocb[0], 0, sizeof (struct iocb));
@@ -379,35 +382,24 @@ rspamd_aio_write (gint fd, gpointer buf, gsize len, off_t offset, struct aio_con
#ifdef LINUX
struct iocb *iocb[1];
- /* We need to align pointer on boundary of 512 bytes here */
- if (ctx->buflen < len) {
- if (ctx->buf) {
- free (ctx->buf);
- }
- if (posix_memalign (&ctx->buf, 512, len) != 0) {
- return -1;
- }
- else {
- ctx->buflen = len;
- memcpy (ctx->buf, buf, len);
- }
- }
- else {
- memcpy (ctx->buf, buf, len);
- }
cbdata = g_slice_alloc (sizeof (struct io_cbdata));
cbdata->cb = cb;
cbdata->buf = buf;
cbdata->len = len;
cbdata->ud = ud;
cbdata->fd = fd;
+ /* We need to align pointer on boundary of 512 bytes here */
+ if (posix_memalign (&cbdata->io_buf, 512, len) != 0) {
+ return -1;
+ }
+ memcpy (cbdata->io_buf, buf, len);
iocb[0] = alloca (sizeof (struct iocb));
memset (iocb[0], 0, sizeof (struct iocb));
iocb[0]->aio_fildes = fd;
iocb[0]->aio_lio_opcode = IO_CMD_PWRITE;
iocb[0]->aio_reqprio = 0;
- iocb[0]->aio_buf = (guint64)((uintptr_t)ctx->buf);
+ iocb[0]->aio_buf = (guint64)((uintptr_t)cbdata->io_buf);
iocb[0]->aio_nbytes = len;
iocb[0]->aio_offset = offset;
iocb[0]->aio_flags |= (1 << 0) /* IOCB_FLAG_RESFD */;
@@ -466,9 +458,6 @@ rspamd_aio_close (gint fd, struct aio_context *ctx)
/* Iocb is copied to kernel internally, so it is safe to put it on stack */
r = io_cancel (ctx->io_ctx, &iocb, &ev);
- if (ctx->buf) {
- free (ctx->buf);
- }
close (fd);
return r;