当前位置: 技术问答>linux和unix
异步io 文件读写
来源: 互联网 发布时间:2016-10-10
本文导语: 谁能帮我读懂下啊,最好能特别说明下io_prep_pwrite等这样函数的祥解,网上资料好少啊 main() 函数会调用 test_main 出错的地方看下面的注释 #include "config.h" #include "common.h" #include "test.h" #include #include #if HAVE_LIBAIO_H ...
谁能帮我读懂下啊,最好能特别说明下io_prep_pwrite等这样函数的祥解,网上资料好少啊
main() 函数会调用 test_main
出错的地方看下面的注释
#include "config.h"
#include "common.h"
#include "test.h"
#include
#include
#if HAVE_LIBAIO_H
#define AIO_MAXIO 32
#define AIO_BLKSIZE (64*1024)
#define AIO_MAXIO 8
static int alignment = 512;
static int wait_count = 0;
/*
* write work done
*/
static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
{
if (res2 != 0) {
io_error("aio write", res2);
}
if (res != iocb->u.c.nbytes) {
fprintf(stderr, "write missed bytes expect %lu got %ldn",
iocb->u.c.nbytes, res2);
exit(1);
}
wait_count --;
}
/*
* io_wait_run() - wait for an io_event and then call the callback.
*/
int io_wait_run(io_context_t ctx, struct timespec *to)
{
struct io_event events[AIO_MAXIO];
struct io_event *ep;
int ret, n;
/*
* get up to aio_maxio events at a time.
*/
ret = n = io_getevents(ctx, 1, AIO_MAXIO, events, to);
/*
* Call the callback functions for each event.
*/
for (ep = events ; n-- > 0 ; ep++) {
io_callback_t cb = (io_callback_t)ep->data ; struct iocb *iocb = ep->obj ; cb(ctx, iocb, ep->res, ep->res2);
}
return ret;
}
int io_tio(char *pathname, int flag, int n, int operation)
{
int res, fd = 0, i = 0;
void * bufptr = NULL;
off_t offset = 0;
struct timespec timeout;
io_context_t myctx;
struct iocb iocb_array[AIO_MAXIO];
struct iocb *iocbps[AIO_MAXIO];
fd = open (pathname, flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd
main() 函数会调用 test_main
出错的地方看下面的注释
#include "config.h"
#include "common.h"
#include "test.h"
#include
#include
#if HAVE_LIBAIO_H
#define AIO_MAXIO 32
#define AIO_BLKSIZE (64*1024)
#define AIO_MAXIO 8
static int alignment = 512;
static int wait_count = 0;
/*
* write work done
*/
static void work_done(io_context_t ctx, struct iocb *iocb, long res, long res2)
{
if (res2 != 0) {
io_error("aio write", res2);
}
if (res != iocb->u.c.nbytes) {
fprintf(stderr, "write missed bytes expect %lu got %ldn",
iocb->u.c.nbytes, res2);
exit(1);
}
wait_count --;
}
/*
* io_wait_run() - wait for an io_event and then call the callback.
*/
int io_wait_run(io_context_t ctx, struct timespec *to)
{
struct io_event events[AIO_MAXIO];
struct io_event *ep;
int ret, n;
/*
* get up to aio_maxio events at a time.
*/
ret = n = io_getevents(ctx, 1, AIO_MAXIO, events, to);
/*
* Call the callback functions for each event.
*/
for (ep = events ; n-- > 0 ; ep++) {
io_callback_t cb = (io_callback_t)ep->data ; struct iocb *iocb = ep->obj ; cb(ctx, iocb, ep->res, ep->res2);
}
return ret;
}
int io_tio(char *pathname, int flag, int n, int operation)
{
int res, fd = 0, i = 0;
void * bufptr = NULL;
off_t offset = 0;
struct timespec timeout;
io_context_t myctx;
struct iocb iocb_array[AIO_MAXIO];
struct iocb *iocbps[AIO_MAXIO];
fd = open (pathname, flag, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd