forked from cozis/tinyio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
44 lines (36 loc) · 1.04 KB
/
example.c
File metadata and controls
44 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include "io.h"
#define NUM_OPS 3
int main()
{
io_global_init();
struct io_operation ops[100];
struct io_resource res[100];
struct io_context ioc;
if (!io_init(&ioc, res, ops, sizeof(res)/sizeof(res[0]), sizeof(ops)/sizeof(ops[0])))
return -1;
io_handle files[NUM_OPS];
for (int i = 0; i < NUM_OPS; i++) {
char name[1<<8];
snprintf(name, sizeof(name), "file_%d.txt", i);
files[i] = io_create_file(&ioc, name, IO_CREATE_CANTEXIST);
if (files[i] == IO_INVALID)
fprintf(stderr, "Couldn't create '%s'\n", name);
}
int started = 0;
char msg[] = "Hello, world!\n";
for (int i = 0; i < NUM_OPS; i++) {
if (io_send(&ioc, NULL, files[i], msg, sizeof(msg)-1))
started++;
else
fprintf(stderr, "ERROR\n");
}
for (int i = 0; i < started; i++) {
struct io_event ev;
io_wait(&ioc, &ev);
fprintf(stderr, "CONCLUDED\n");
}
io_free(&ioc);
io_global_free();
return 0;
}