aboutsummaryrefslogtreecommitdiffstats
path: root/src/aio_event.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-03-11 16:01:20 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-03-11 16:01:20 +0400
commit899c90dd4273245f3e26cb2d2cf311918dcc9068 (patch)
tree5bc7b12a9bed81168e5a418ff1ed71e3ab309c7c /src/aio_event.c
parent9b8ecfb8923cae677777a68790f23fbcf26bdabf (diff)
downloadrspamd-899c90dd4273245f3e26cb2d2cf311918dcc9068.tar.gz
rspamd-899c90dd4273245f3e26cb2d2cf311918dcc9068.zip
Add offset support to aio operations.
Diffstat (limited to 'src/aio_event.c')
-rw-r--r--src/aio_event.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/aio_event.c b/src/aio_event.c
index c171fece5..dc1d8284a 100644
--- a/src/aio_event.c
+++ b/src/aio_event.c
@@ -302,7 +302,7 @@ rspamd_aio_open (struct aio_context *ctx, const gchar *path, int flags)
* Asynchronous read of file
*/
gint
-rspamd_aio_read (gint fd, gpointer buf, gsize len, struct aio_context *ctx, rspamd_aio_cb cb, gpointer ud)
+rspamd_aio_read (gint fd, gpointer buf, gsize len, off_t offset, struct aio_context *ctx, rspamd_aio_cb cb, gpointer ud)
{
struct io_cbdata *cbdata;
gint r = -1;
@@ -325,7 +325,7 @@ rspamd_aio_read (gint fd, gpointer buf, gsize len, struct aio_context *ctx, rspa
iocb[0]->aio_reqprio = 0;
iocb[0]->aio_buf = (guint64)((uintptr_t)buf);
iocb[0]->aio_nbytes = len;
- iocb[0]->aio_offset = 0;
+ iocb[0]->aio_offset = offset;
iocb[0]->aio_flags |= (1 << 0) /* IOCB_FLAG_RESFD */;
iocb[0]->aio_resfd = ctx->event_fd;
iocb[0]->aio_data = (guint64)((uintptr_t)cbdata);
@@ -348,12 +348,15 @@ rspamd_aio_read (gint fd, gpointer buf, gsize len, struct aio_context *ctx, rspa
else {
/* Blocking variant */
blocking:
- r = read (fd, buf, len);
- if (r >= 0) {
- cb (fd, 0, r, buf, ud);
- }
- else {
- cb (fd, r, -1, buf, ud);
+ r = lseek (fd, offset, SEEK_SET);
+ if (r > 0) {
+ r = read (fd, buf, len);
+ if (r >= 0) {
+ cb (fd, 0, r, buf, ud);
+ }
+ else {
+ cb (fd, r, -1, buf, ud);
+ }
}
}
@@ -364,7 +367,7 @@ blocking:
* Asynchronous write of file
*/
gint
-rspamd_aio_write (gint fd, gpointer buf, gsize len, struct aio_context *ctx, rspamd_aio_cb cb, gpointer ud)
+rspamd_aio_write (gint fd, gpointer buf, gsize len, off_t offset, struct aio_context *ctx, rspamd_aio_cb cb, gpointer ud)
{
struct io_cbdata *cbdata;
gint r = -1;
@@ -387,7 +390,7 @@ rspamd_aio_write (gint fd, gpointer buf, gsize len, struct aio_context *ctx, rsp
iocb[0]->aio_reqprio = 0;
iocb[0]->aio_buf = (guint64)((uintptr_t)buf);
iocb[0]->aio_nbytes = len;
- iocb[0]->aio_offset = 0;
+ iocb[0]->aio_offset = offset;
iocb[0]->aio_flags |= (1 << 0) /* IOCB_FLAG_RESFD */;
iocb[0]->aio_resfd = ctx->event_fd;
iocb[0]->aio_data = (guint64)((uintptr_t)cbdata);
@@ -410,12 +413,15 @@ rspamd_aio_write (gint fd, gpointer buf, gsize len, struct aio_context *ctx, rsp
else {
/* Blocking variant */
blocking:
- r = write (fd, buf, len);
- if (r >= 0) {
- cb (fd, 0, r, buf, ud);
- }
- else {
- cb (fd, r, -1, buf, ud);
+ r = lseek (fd, offset, SEEK_SET);
+ if (r > 0) {
+ r = write (fd, buf, len);
+ if (r >= 0) {
+ cb (fd, 0, r, buf, ud);
+ }
+ else {
+ cb (fd, r, -1, buf, ud);
+ }
}
}