1 /*
2  * Copyright (C) 2020 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 #pragma once
18 #include <qemu_pipe_types_bp.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 QEMU_PIPE_HANDLE qemu_pipe_open_ns(const char* ns, const char* pipeName, int flags);
25 QEMU_PIPE_HANDLE qemu_pipe_open(const char* pipeName);
26 void qemu_pipe_close(QEMU_PIPE_HANDLE pipe);
27 
28 int qemu_pipe_read_fully(QEMU_PIPE_HANDLE pipe, void* buffer, int size);
29 int qemu_pipe_write_fully(QEMU_PIPE_HANDLE pipe, const void* buffer, int size);
30 int qemu_pipe_read(QEMU_PIPE_HANDLE pipe, void* buffer, int size);
31 int qemu_pipe_write(QEMU_PIPE_HANDLE pipe, const void* buffer, int size);
32 
33 int qemu_pipe_try_again(int ret);
34 void qemu_pipe_print_error(QEMU_PIPE_HANDLE pipe);
35 
36 #ifdef __cplusplus
37 }  // extern "C"
38 #endif
39 
40 #define QEMU_PIPE_RETRY(exp) ({ \
41     __typeof__(exp) _rc; \
42     do { \
43         _rc = (exp); \
44     } while (qemu_pipe_try_again(_rc)); \
45     _rc; })
46