0

AIOが機能していないように見えるファイルに簡単なことを書き込もうとしています。何が問題になる可能性がありますか? 不要な余分なヘッダーがあることはわかっています。

#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
#include<errno.h>
#include<stdlib.h>
#include<aio.h>

const int SIZE_TO_WRITE = 100;
char buffer[100];
struct aiocb cb;

int main()
{   

    int file = open("samp", O_CREAT|O_RDWR|O_TRUNC,0664);

    strcpy(buffer,"Sample");

    cb.aio_nbytes = SIZE_TO_WRITE;
    cb.aio_fildes = file;
    cb.aio_buf = buffer;    
    if(aio_write(&cb) == -1){
        printf("ERROR");
    }

    while(aio_error(&cb) == EINPROGRESS)    

    close(file);

    return 0;
}
4

1 に答える 1

1
while(aio_error(&cb) == EINPROGRESS)    
close(file);

実際には

while(aio_error(&cb) == EINPROGRESS)    
    close(file);

代わりに、書き込みが完了するまでビジー状態で待機するつもりでしたか?

while(aio_error(&cb) == EINPROGRESS);
//                                  ^
close(file);
于 2013-12-22T18:22:19.613 に答える