Lely core libraries  2.3.4
io.h
Go to the documentation of this file.
1 
21 #ifndef LELY_IO_IO_H_
22 #define LELY_IO_IO_H_
23 
24 #include <lely/libc/sys/types.h>
25 #include <lely/util/util.h>
26 
27 #include <stddef.h>
28 #include <stdint.h>
29 
31 typedef struct io_handle *io_handle_t;
32 
34 #define IO_HANDLE_ERROR ((io_handle_t)NULL)
35 
37 typedef int64_t io_off_t;
38 
40 typedef union __io_attr io_attr_t;
41 
43 typedef struct __io_addr io_addr_t;
44 
45 enum {
56 };
57 
58 enum {
60  IO_FLAG_NO_CLOSE = 1 << 0,
62  IO_FLAG_NONBLOCK = 1 << 1,
64  IO_FLAG_LOOPBACK = 1 << 2
65 };
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
80 int lely_io_init(void);
81 
88 void lely_io_fini(void);
89 
98 
105 void io_handle_release(io_handle_t handle);
106 
111 int io_handle_unique(io_handle_t handle);
112 
119 int io_close(io_handle_t handle);
120 
126 int io_get_type(io_handle_t handle);
127 
129 #if _WIN32
130 HANDLE io_get_fd(io_handle_t handle);
131 #else
132 int io_get_fd(io_handle_t handle);
133 #endif
134 
144 int io_get_flags(io_handle_t handle);
145 
158 int io_set_flags(io_handle_t handle, int flags);
159 
171 ssize_t io_read(io_handle_t handle, void *buf, size_t nbytes);
172 
184 ssize_t io_write(io_handle_t handle, const void *buf, size_t nbytes);
185 
193 int io_flush(io_handle_t handle);
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #endif // !LELY_IO_IO_H_
void lely_io_fini(void)
Finalizes the I/O library and terminates the availability of the I/O functions.
Definition: io.c:63
int io_close(io_handle_t handle)
Closes an I/O device.
Definition: io.c:78
int64_t io_off_t
A file offset type.
Definition: io.h:37
int io_get_type(io_handle_t handle)
Returns the type of an I/O device (one of IO_TYPE_CAN, IO_TYPE_FILE, IO_TYPE_PIPE,...
Definition: io.c:91
@ IO_TYPE_PIPE
A pipe.
Definition: io.h:51
@ IO_TYPE_FILE
A regular file.
Definition: io.h:49
@ IO_TYPE_SERIAL
A serial I/O device.
Definition: io.h:53
@ IO_TYPE_CAN
A CAN device.
Definition: io.h:47
@ IO_TYPE_SOCK
A network socket.
Definition: io.h:55
ssize_t io_read(io_handle_t handle, void *buf, size_t nbytes)
Performs a read operation.
Definition: io.c:154
io_handle_t io_handle_acquire(io_handle_t handle)
Increments the reference count of an I/O device handle.
Definition: handle.c:36
struct io_handle * io_handle_t
An opaque I/O device handle type.
Definition: io.h:31
int io_handle_unique(io_handle_t handle)
Returns 1 if there is only a single reference to the specified I/O device handle, and 0 otherwise.
Definition: handle.c:71
int lely_io_init(void)
Initializes the I/O library and makes the I/O functions available for use.
Definition: io.c:37
int io_get_fd(io_handle_t handle)
Returns the native file descriptor of an I/O device.
Definition: io.c:103
int io_flush(io_handle_t handle)
Flushes the write buffer of a an I/O device.
Definition: io.c:188
int io_set_flags(io_handle_t handle, int flags)
Sets the flags of an I/O device.
Definition: io.c:128
@ IO_FLAG_NONBLOCK
Perform I/O operations in non-blocking mode.
Definition: io.h:62
@ IO_FLAG_LOOPBACK
Receive own messages (i.e., sent by the same device).
Definition: io.h:64
@ IO_FLAG_NO_CLOSE
Do not close the native file descriptor when closing an I/O device.
Definition: io.h:60
int io_get_flags(io_handle_t handle)
Obtains the flags of an I/O device.
Definition: io.c:114
ssize_t io_write(io_handle_t handle, const void *buf, size_t nbytes)
Performs a write operation.
Definition: io.c:171
void io_handle_release(io_handle_t handle)
Decrements the reference count of an I/O device handle.
Definition: handle.c:51
This is the public header file of the utilities library.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
An opaque network address type.
Definition: addr.h:30
An I/O device handle.
Definition: handle.h:33
This header file is part of the C11 and POSIX compatibility library; it includes <sys/types....
An opaque serial I/O device attributes type.
Definition: attr.h:34