|
int main() {
|
|
printf("=== Async I/O Tests ===\n");
|
|
|
|
printf("Test 1: Async file write\n");
|
|
int f = fopen("async_test.txt", "w");
|
|
if (f == 0) {
|
|
printf("ERROR: Could not open file\n");
|
|
return 1;
|
|
}
|
|
int write_handle = async_fwrite(f, "Hello from async I/O!", 21);
|
|
printf("Write started, handle: %d\n", write_handle);
|
|
int result = async_wait(write_handle);
|
|
printf("Write completed, bytes written: %d\n", result);
|
|
fclose(f);
|
|
printf("PASS: Async write works\n");
|
|
|
|
printf("Test 2: Async file read\n");
|
|
f = fopen("async_test.txt", "r");
|
|
if (f == 0) {
|
|
printf("ERROR: Could not open file\n");
|
|
return 1;
|
|
}
|
|
int buffer[256];
|
|
int read_handle = async_fread(f, &buffer, 256);
|
|
printf("Read started, handle: %d\n", read_handle);
|
|
|
|
printf("Polling for completion...\n");
|
|
while (async_poll(read_handle) == 0) {
|
|
printf(".");
|
|
}
|
|
printf("\nRead complete!\n");
|
|
|
|
result = async_result(read_handle);
|
|
printf("Bytes read: %d\n", result);
|
|
fclose(f);
|
|
printf("PASS: Async read works\n");
|
|
|
|
printf("Test 3: Cleanup\n");
|
|
fremove("async_test.txt");
|
|
printf("PASS: File removed\n");
|
|
|
|
printf("\n=== All Async I/O Tests Completed ===\n");
|
|
return 0;
|
|
}
|