Lely core libraries 2.3.4
|
This is the public header file of the I/O library. More...
#include <lely/libc/sys/types.h>
#include <lely/util/util.h>
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Macros | |
#define | IO_HANDLE_ERROR ((io_handle_t)NULL) |
The value of an invalid I/O device handle. | |
Typedefs | |
typedef struct io_handle * | io_handle_t |
An opaque I/O device handle type. | |
typedef int64_t | io_off_t |
A file offset type. | |
typedef union __io_attr | io_attr_t |
An opaque serial I/O device attributes type. | |
typedef struct __io_addr | io_addr_t |
An opaque network address type. | |
Enumerations | |
enum | { IO_TYPE_CAN = 1 , IO_TYPE_FILE , IO_TYPE_PIPE , IO_TYPE_SERIAL , IO_TYPE_SOCK } |
enum | { IO_FLAG_NO_CLOSE = 1 << 0 , IO_FLAG_NONBLOCK = 1 << 1 , IO_FLAG_LOOPBACK = 1 << 2 } |
Functions | |
int | lely_io_init (void) |
Initializes the I/O library and makes the I/O functions available for use. | |
void | lely_io_fini (void) |
Finalizes the I/O library and terminates the availability of the I/O functions. | |
io_handle_t | io_handle_acquire (io_handle_t handle) |
Increments the reference count of an I/O device handle. | |
void | io_handle_release (io_handle_t handle) |
Decrements the reference count of an I/O device handle. | |
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. | |
int | io_close (io_handle_t handle) |
Closes an I/O device. | |
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. | |
int | io_get_fd (io_handle_t handle) |
Returns the native file descriptor of an I/O device. | |
int | io_get_flags (io_handle_t handle) |
Obtains the flags of an I/O device. | |
int | io_set_flags (io_handle_t handle, int flags) |
Sets the flags of an I/O device. | |
ssize_t | io_read (io_handle_t handle, void *buf, size_t nbytes) |
Performs a read operation. | |
ssize_t | io_write (io_handle_t handle, const void *buf, size_t nbytes) |
Performs a write operation. | |
int | io_flush (io_handle_t handle) |
Flushes the write buffer of a an I/O device. | |
This is the public header file of the I/O library.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file io.h.
anonymous enum |
anonymous enum |
int lely_io_init | ( | void | ) |
Initializes the I/O library and makes the I/O functions available for use.
On Windows this function invokes WSAStartup()
. This function is not thread safe, but can be invoked multiple times, as long as it is matched by an equal number of calls to lely_io_fini().
void lely_io_fini | ( | void | ) |
Finalizes the I/O library and terminates the availability of the I/O functions.
On Windows this function invokes WSACleanup()
. Note that this function MUST be invoked once for each corresponding call to lely_io_init(). Only the last invocation will finalize the library.
io_handle_t io_handle_acquire | ( | io_handle_t | handle | ) |
void io_handle_release | ( | io_handle_t | handle | ) |
Decrements the reference count of an I/O device handle.
If the count reaches zero, the handle is destroyed.
int io_close | ( | io_handle_t | handle | ) |
Closes an I/O device.
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.
In the latter case, the error number can be obtained with get_errc().
int io_get_flags | ( | io_handle_t | handle | ) |
Obtains the flags of an I/O device.
int io_set_flags | ( | io_handle_t | handle, |
int | flags | ||
) |
Sets the flags of an I/O device.
handle | a valid I/O device handle. |
flags | the I/O device flags (any combination of IO_FLAG_NO_CLOSE, IO_FLAG_NONBLOCK and IO_FLAG_LOOPBACK). |
ssize_t io_read | ( | io_handle_t | handle, |
void * | buf, | ||
size_t | nbytes | ||
) |
Performs a read operation.
For regular files, this function updates the file pointer on success.
handle | a valid I/O device handle. |
buf | a pointer to the destination buffer. |
nbytes | the number of bytes to read. |
ssize_t io_write | ( | io_handle_t | handle, |
const void * | buf, | ||
size_t | nbytes | ||
) |
Performs a write operation.
For regular files, this function updates the file pointer on success.
handle | a valid I/O device handle. |
buf | a pointer to the source buffer. |
nbytes | the number of bytes to write. |
int io_flush | ( | io_handle_t | handle | ) |
Flushes the write buffer of a an I/O device.
This function waits until all buffered data has been written.