1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _POSIXASYNCIO_H
18 #define _POSIXASYNCIO_H
19 
20 #include <sys/cdefs.h>
21 #include <sys/types.h>
22 #include <time.h>
23 #include <thread>
24 #include <unistd.h>
25 
26 /**
27  * Provides a subset of POSIX aio operations.
28  */
29 
30 struct aiocb {
31     int aio_fildes;
32     void *aio_buf;
33 
34     off_t aio_offset;
35     size_t aio_nbytes;
36 
37     // Used internally
38     std::thread thread;
39     ssize_t ret;
40     int error;
41 
42     ~aiocb();
43 };
44 
45 // Submit a request for IO to be completed
46 int aio_read(struct aiocb *);
47 int aio_write(struct aiocb *);
48 
49 // Suspend current thread until given IO is complete, at which point
50 // its return value and any errors can be accessed
51 // All submitted requests must have a corresponding suspend.
52 // aiocb->aio_buf must refer to valid memory until after the suspend call
53 int aio_suspend(struct aiocb *[], int, const struct timespec *);
54 int aio_error(const struct aiocb *);
55 ssize_t aio_return(struct aiocb *);
56 
57 // Helper method for setting aiocb members
58 void aio_prepare(struct aiocb *, void*, size_t, off_t);
59 
60 #endif // POSIXASYNCIO_H
61 
62