Commit 86749092 authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added read, write, read_nb, and write_nb

parent f1a65039
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script. # Process this file with autoconf to produce a configure script.
AC_PREREQ([2.67]) AC_PREREQ([2.67])
AC_INIT([abt-io], [0.1], [],[],[]) AC_INIT([abt-io], [0.2], [],[],[])
AC_CONFIG_MACRO_DIRS([m4]) AC_CONFIG_MACRO_DIRS([m4])
LT_INIT LT_INIT
......
...@@ -90,6 +90,25 @@ abt_io_op_t* abt_io_pwrite_nb( ...@@ -90,6 +90,25 @@ abt_io_op_t* abt_io_pwrite_nb(
off_t offset, off_t offset,
ssize_t *ret); ssize_t *ret);
/**
* wrapper for write()
*/
ssize_t abt_io_write(
abt_io_instance_id aid,
int fd,
const void *buf,
size_t count);
/**
* non-blocking wrapper for write()
*/
abt_io_op_t* abt_io_write_nb(
abt_io_instance_id aid,
int fd,
const void *buf,
size_t count,
ssize_t *ret);
/** /**
* wrapper for pread() * wrapper for pread()
*/ */
...@@ -111,6 +130,25 @@ abt_io_op_t* abt_io_pread_nb( ...@@ -111,6 +130,25 @@ abt_io_op_t* abt_io_pread_nb(
off_t offset, off_t offset,
ssize_t *ret); ssize_t *ret);
/**
* wrapper for read()
*/
ssize_t abt_io_read(
abt_io_instance_id aid,
int fd,
void *buf,
size_t count);
/**
* non-blocking wrapper for read()
*/
abt_io_op_t* abt_io_read_nb(
abt_io_instance_id aid,
int fd,
void *buf,
size_t count,
ssize_t *ret);
/** /**
* wrapper for mkostemp() * wrapper for mkostemp()
*/ */
......
...@@ -5,7 +5,7 @@ includedir=@includedir@ ...@@ -5,7 +5,7 @@ includedir=@includedir@
Name: abt-io Name: abt-io
Description: Argobots bindings for common POSIX I/O functions Description: Argobots bindings for common POSIX I/O functions
Version: 0.1 Version: 0.2
URL: https://xgitlab.cels.anl.gov/sds/abt-io URL: https://xgitlab.cels.anl.gov/sds/abt-io
Requires: argobots Requires: argobots
Libs: -L${libdir} -labt-io Libs: -L${libdir} -labt-io
......
...@@ -315,6 +315,93 @@ abt_io_op_t* abt_io_pread_nb(abt_io_instance_id aid, int fd, void *buf, ...@@ -315,6 +315,93 @@ abt_io_op_t* abt_io_pread_nb(abt_io_instance_id aid, int fd, void *buf,
else return op; else return op;
} }
struct abt_io_read_state
{
ssize_t *ret;
int fd;
void *buf;
size_t count;
ABT_eventual eventual;
};
static void abt_io_read_fn(void *foo)
{
struct abt_io_read_state *state = foo;
*state->ret = read(state->fd, state->buf, state->count);
if(*state->ret < 0)
*state->ret = -errno;
ABT_eventual_set(state->eventual, NULL, 0);
return;
}
static int issue_read(ABT_pool pool, abt_io_op_t *op, int fd, void *buf,
size_t count, ssize_t *ret)
{
struct abt_io_read_state state;
struct abt_io_read_state *pstate = NULL;
int rc;
if (op == NULL) pstate = &state;
else
{
pstate = malloc(sizeof(*pstate));
if (pstate == NULL) { *ret = -ENOMEM; goto err; }
}
*ret = -ENOSYS;
pstate->ret = ret;
pstate->fd = fd;
pstate->buf = buf;
pstate->count = count;
pstate->eventual = NULL;
rc = ABT_eventual_create(0, &pstate->eventual);
if (rc != ABT_SUCCESS) { *ret = -ENOMEM; goto err; }
if (op != NULL) op->e = pstate->eventual;
rc = ABT_task_create(pool, abt_io_read_fn, pstate, NULL);
if(rc != ABT_SUCCESS) { *ret = -EINVAL; goto err; }
if (op == NULL) {
rc = ABT_eventual_wait(pstate->eventual, NULL);
// what error should we use here?
if (rc != ABT_SUCCESS) { *ret = -EINVAL; goto err; }
}
else {
op->e = pstate->eventual;
op->state = pstate;
op->free_fn = free;
}
return 0;
err:
if (pstate->eventual != NULL) ABT_eventual_free(&pstate->eventual);
if (pstate != NULL && op != NULL) free(pstate);
return -1;
}
ssize_t abt_io_read(abt_io_instance_id aid, int fd, void *buf, size_t count)
{
ssize_t ret = -1;
issue_read(aid->progress_pool, NULL, fd, buf, count, &ret);
return ret;
}
abt_io_op_t* abt_io_read_nb(abt_io_instance_id aid, int fd, void *buf,
size_t count, ssize_t *ret)
{
abt_io_op_t *op;
int iret;
op = malloc(sizeof(*op));
if (op == NULL) return NULL;
iret = issue_read(aid->progress_pool, op, fd, buf, count, ret);
if (iret != 0) { free(op); return NULL; }
else return op;
}
struct abt_io_pwrite_state struct abt_io_pwrite_state
{ {
...@@ -407,6 +494,95 @@ abt_io_op_t* abt_io_pwrite_nb(abt_io_instance_id aid, int fd, const void *buf, ...@@ -407,6 +494,95 @@ abt_io_op_t* abt_io_pwrite_nb(abt_io_instance_id aid, int fd, const void *buf,
else return op; else return op;
} }
struct abt_io_write_state
{
ssize_t *ret;
int fd;
const void *buf;
size_t count;
ABT_eventual eventual;
};
static void abt_io_write_fn(void *foo)
{
struct abt_io_write_state *state = foo;
*state->ret = write(state->fd, state->buf, state->count);
if(*state->ret < 0)
*state->ret = -errno;
ABT_eventual_set(state->eventual, NULL, 0);
return;
}
static int issue_write(ABT_pool pool, abt_io_op_t *op, int fd, const void *buf,
size_t count, ssize_t *ret)
{
struct abt_io_write_state state;
struct abt_io_write_state *pstate = NULL;
int rc;
if (op == NULL) pstate = &state;
else
{
pstate = malloc(sizeof(*pstate));
if (pstate == NULL) { *ret = -ENOMEM; goto err; }
}
*ret = -ENOSYS;
pstate->ret = ret;
pstate->fd = fd;
pstate->buf = buf;
pstate->count = count;
pstate->eventual = NULL;
rc = ABT_eventual_create(0, &pstate->eventual);
if (rc != ABT_SUCCESS) { *ret = -ENOMEM; goto err; }
if (op != NULL) op->e = pstate->eventual;
rc = ABT_task_create(pool, abt_io_write_fn, pstate, NULL);
if(rc != ABT_SUCCESS) { *ret = -EINVAL; goto err; }
if (op == NULL) {
rc = ABT_eventual_wait(pstate->eventual, NULL);
// what error should we use here?
if (rc != ABT_SUCCESS) { *ret = -EINVAL; goto err; }
}
else {
op->e = pstate->eventual;
op->state = pstate;
op->free_fn = free;
}
return 0;
err:
if (pstate->eventual != NULL) ABT_eventual_free(&pstate->eventual);
if (pstate != NULL && op != NULL) free(pstate);
return -1;
}
ssize_t abt_io_write(abt_io_instance_id aid, int fd, const void *buf, size_t count)
{
ssize_t ret = -1;
issue_write(aid->progress_pool, NULL, fd, buf, count, &ret);
return ret;
}
abt_io_op_t* abt_io_write_nb(abt_io_instance_id aid, int fd, const void *buf,
size_t count, ssize_t *ret)
{
abt_io_op_t *op;
int iret;
op = malloc(sizeof(*op));
if (op == NULL) return NULL;
iret = issue_write(aid->progress_pool, op, fd, buf, count, ret);
if (iret != 0) { free(op); return NULL; }
else return op;
}
struct abt_io_mkostemp_state struct abt_io_mkostemp_state
{ {
int *ret; int *ret;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment