Date: Thu, 12 Nov 1998 13:56:41 -0500 (EST) From: HighWind Software Information <info@highwind.com> To: current@FreeBSD.ORG Subject: aio_write() doesn't work! Message-ID: <199811121856.NAA23101@highwind.com>
next in thread | raw e-mail | index | archive | help
Is is me or does "aio_write()" under FreeBSD 3.0 simply NOT work?
This prints all x's. Considering I used aio_write() to write a 'y' in
there, why doesn't it work??
-Rob
---
/*****************************************************************************
File: aioTest.c
Contents: Simple Test of the aio_write() function
gcc -o aioTest aioTest.c -Wall -Werror
*****************************************************************************/
#include <assert.h>
#include <fcntl.h>
#include <memory.h>
#include <time.h>
#include <sys/aio.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int fd;
char before[10], after[11], y;
struct aiocb token;
const struct aiocb *tlist;
/* Open the test file */
fd = open("test", O_RDWR | O_CREAT | O_TRUNC, 0666);
assert(fd != -1);
/* Write 10 x's */
memset(before, 'x', 10);
assert(write(fd, &before, 10) == 10);
/* Use aio_write() to write a 'Y' at offset 5 */
y = 'Y';
memset(&token, 0, sizeof(struct aiocb));
token.aio_fildes = fd;
token.aio_offset = 5;
token.aio_buf = &y;
token.aio_nbytes = 1;
token.aio_sigevent.sigev_notify = SIGEV_NONE;
/* Enqueue the write */
assert(aio_write(&token) == 0);
/* Wait for completion */
tlist = &token;
assert(aio_suspend(&tlist, 1, 0) == 0);
/* Ensure the write worked! */
assert(aio_return(&token) == 1);
/* Read back the whole file */
memset(after, 0, 11);
assert(lseek(fd, 0, SEEK_SET) == 0);
assert(read(fd, &after, 10) == 10);
printf("%s\n", after);
return EXIT_SUCCESS;
}
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811121856.NAA23101>
