Lely core libraries  2.2.5
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,
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 
97 io_handle_t io_handle_acquire(io_handle_t handle);
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 #ifdef _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_
This header file is part of the C11 and POSIX compatibility library; it includes <sys/types.h>, if it exists, and defines any missing functionality.
int io_flush(io_handle_t handle)
Flushes the write buffer of a an I/O device.
Definition: io.c:184
Receive own messages (i.e., sent by the same device).
Definition: io.h:64
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, IO_TYPE_SERIAL or IO_TYPE_SOCK), or -1 on error.
Definition: io.c:87
An opaque network address type.
Definition: addr.h:30
ssize_t io_write(io_handle_t handle, const void *buf, size_t nbytes)
Performs a write operation.
Definition: io.c:167
A pipe.
Definition: io.h:51
int io_get_flags(io_handle_t handle)
Obtains the flags of an I/O device.
Definition: io.c:110
A network socket.
Definition: io.h:55
int lely_io_init(void)
Initializes the I/O library and makes the I/O functions available for use.
Definition: io.c:33
struct io_handle * io_handle_t
An opaque I/O device handle type.
Definition: io.h:31
io_handle_t io_handle_acquire(io_handle_t handle)
Increments the reference count of an I/O device handle.
Definition: handle.c:32
void lely_io_fini(void)
Finalizes the I/O library and terminates the availability of the I/O functions.
Definition: io.c:59
Perform I/O operations in non-blocking mode.
Definition: io.h:62
A regular file.
Definition: io.h:49
Do not close the native file descriptor when closing an I/O device.
Definition: io.h:60
An opaque serial I/O device attributes type.
Definition: attr.h:34
int io_set_flags(io_handle_t handle, int flags)
Sets the flags of an I/O device.
Definition: io.c:124
This header file is part of the C11 and POSIX compatibility library; it includes <stddef.h> and defines any missing functionality.
void io_handle_release(io_handle_t handle)
Decrements the reference count of an I/O device handle.
Definition: handle.c:47
ssize_t io_read(io_handle_t handle, void *buf, size_t nbytes)
Performs a read operation.
Definition: io.c:150
int io_close(io_handle_t handle)
Closes an I/O device.
Definition: io.c:74
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:67
This header file is part of the C11 and POSIX compatibility library; it includes <stdint.h> and defines any missing functionality.
int io_get_fd(io_handle_t handle)
Returns the native file descriptor of an I/O device.
Definition: io.c:99
A CAN device.
Definition: io.h:47
int64_t io_off_t
A file offset type.
Definition: io.h:37
A serial I/O device.
Definition: io.h:53
An I/O device handle.
Definition: handle.h:41
This is the public header file of the utilities library.