* 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;
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);
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);
+ }
}
}
* 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;
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);
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);
+ }
}
}
/**
* Asynchronous read of file
*/
-gint rspamd_aio_read (gint fd, gpointer buf, gsize len, struct aio_context *ctx, rspamd_aio_cb cb, gpointer ud);
+gint rspamd_aio_read (gint fd, gpointer buf, gsize len, off_t offset,
+ struct aio_context *ctx, rspamd_aio_cb cb, gpointer ud);
/**
* Asynchronous write of file
*/
-gint rspamd_aio_write (gint fd, gpointer buf, gsize len, struct aio_context *ctx, rspamd_aio_cb cb, gpointer ud);
+gint rspamd_aio_write (gint fd, gpointer buf, gsize len, off_t offset,
+ struct aio_context *ctx, rspamd_aio_cb cb, gpointer ud);
/**
* Close of aio operations