Zth (libzth)
io.h
Go to the documentation of this file.
1 #ifndef ZTH_IO_H
2 #define ZTH_IO_H
3 /*
4  * Zth (libzth), a cooperative userspace multitasking library.
5  * Copyright (C) 2019-2022 Jochem Rutgers
6  *
7  * This Source Code Form is subject to the terms of the Mozilla Public
8  * License, v. 2.0. If a copy of the MPL was not distributed with this
9  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
10  */
11 
21 #include <libzth/macros.h>
22 #include <libzth/poller.h>
23 
24 #include <unistd.h>
25 
26 #if defined(ZTH_HAVE_POLLER)
27 # if !defined(ZTH_OS_WINDOWS)
28 # if defined(__cplusplus)
29 namespace zth {
30 namespace io {
31 
32 ZTH_EXPORT ssize_t read(int fd, void* buf, size_t count);
33 ZTH_EXPORT ssize_t write(int fd, void const* buf, size_t count);
34 
35 } // namespace io
36 } // namespace zth
37 
43 EXTERN_C ZTH_EXPORT ZTH_INLINE ssize_t zth_read(int fd, void* buf, size_t count)
44 {
45  return zth::io::read(fd, buf, count);
46 }
47 
53 EXTERN_C ZTH_EXPORT ZTH_INLINE ssize_t zth_write(int fd, void const* buf, size_t count)
54 {
55  return zth::io::write(fd, buf, count);
56 }
57 
58 # else // !__cplusplus
59 ZTH_EXPORT ssize_t zth_read(int fd, void* buf, size_t count);
60 ZTH_EXPORT ssize_t zth_write(int fd, void const* buf, size_t count);
61 # endif // __cplusplus
62 # endif // !ZTH_OS_WINDOWS
63 #endif // ZTH_HAVE_POLLER
64 
65 #endif // ZTH_IO_H
ssize_t zth_read(int fd, void *buf, size_t count)
Like normal read(), but forwards the poll() to the zth::Waiter in case it would block.
Definition: io.h:43
ssize_t zth_write(int fd, void const *buf, size_t count)
Like normal write(), but forwards the poll() to the zth::Waiter in case it would block.
Definition: io.h:53
ssize_t read(int fd, void *buf, size_t count)
Like normal read(), but forwards the poll() to the zth::Waiter in case it would block.
Definition: io.cpp:27
ssize_t write(int fd, void const *buf, size_t count)
Like normal write(), but forwards the poll() to the zth::Waiter in case it would block.
Definition: io.cpp:54
#define ZTH_INLINE
Definition: macros.h:130
Definition: allocator.h:23