Describes an input/output channel which is implemented as file descriptor on POSIX systems.
IOChannel | Describes an input/output channel which is implemented as file descriptor on POSIX systems. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file IOChannel. |
C-kern/ | Implementation file IOChannel impl. |
Types | |
struct iochannel_t | Make iochannel_t an alias of sys_iochannel_t. |
Enumerations | |
iochannel_e | Standard channels which are usually open at process start by convention. |
Functions | |
query | |
nropen_iochannel | Returns number of opened I/O data channels. |
test | |
unittest_io_iochannel | Test iochannel_t functionality. |
iochannel_t | Describes an input/output channel like a file or network connection. |
lifetime | |
iochannel_FREE | Static initializer. |
initcopy_iochannel | Makes ioc a duplicate of from_ioc. |
free_iochannel | Closes the I/O channel (file descriptor). |
query | |
isfree_iochannel | Returns true if ioc equals iochannel_FREE. |
isvalid_iochannel | Returns true if ioc is initialized and valid. |
accessmode_iochannel | Returns accessmode_e for an io channel. |
I/ | |
read_iochannel | Reads size bytes from the data stream referenced by ioc into buffer. |
write_iochannel | Writes size bytes from buffer to the data stream referenced by ioc. |
inline implementation | |
Functions | |
isfree_iochannel | Implements iochannel_t.isfree_iochannel. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2013 Jörg Seebohn
Header file IOChannel.
Implementation file IOChannel impl.
Make iochannel_t an alias of sys_iochannel_t.
query | |
nropen_iochannel | Returns number of opened I/O data channels. |
test | |
unittest_io_iochannel | Test iochannel_t functionality. |
int nropen_iochannel( /*out*/size_t * number_open )
Returns number of opened I/O data channels. The number of underlying data streams could be smaller cause oseveral I/O channel could reference the same data object. You can use this function at the beginning and end of any transaction to check if an I/O object (file, network socket...) was not closed properly.
int unittest_io_iochannel( void )
Test iochannel_t functionality.
typedef sys_iochannel_t iochannel_t
Describes an input/output channel like a file or network connection. On POSIX systems it is a synonym for a file descriptor.
A sys_iochannel_t, which is returned by io_directory and other functions can be manipulated by this interface. Do not free a descriptor which is returned by such functions else the underlying object will no more work.
If you use initcopy_iochannel to initialize an iochannel_t from a value acquired by a call to <io_socket> or any other such function, you need to call free_iochannel.
lifetime | |
iochannel_FREE | Static initializer. |
initcopy_iochannel | Makes ioc a duplicate of from_ioc. |
free_iochannel | Closes the I/O channel (file descriptor). |
query | |
isfree_iochannel | Returns true if ioc equals iochannel_FREE. |
isvalid_iochannel | Returns true if ioc is initialized and valid. |
accessmode_iochannel | Returns accessmode_e for an io channel. |
I/ | |
read_iochannel | Reads size bytes from the data stream referenced by ioc into buffer. |
write_iochannel | Writes size bytes from buffer to the data stream referenced by ioc. |
int free_iochannel( iochannel_t * ioc )
Closes the I/O channel (file descriptor). If any other iochannel_t references the same I/O data stream (file, network connection,...) the stream keeps opened. Do not call this function if you got the iochannel_t from an io_XXX function. Such functions return the original iochannel_t and do not make a copy.
static inline bool isfree_iochannel( const iochannel_t ioc )
Returns true if ioc equals iochannel_FREE.
bool isvalid_iochannel( const iochannel_t ioc )
Returns true if ioc is initialized and valid. A return value of true implies isfree_iochannel returns false. The function checks that ioc refers to a valid iochannel which is known to the operating system. It is therefore more costly than isfree_iochannel.
uint8_t accessmode_iochannel( const iochannel_t ioc )
Returns accessmode_e for an io channel. Returns accessmode_READ, accessmode_WRITE or the combination accessmode_RDWR. In case of an error accessmode_NONE is returned.
int read_iochannel( iochannel_t ioc, size_t size, /*out*/void * buffer/*[size]*/, /*out*/size_t * bytes_read )
Reads size bytes from the data stream referenced by ioc into buffer. If an error occurrs or end of input is reached less then size bytes are returned. Less then size bytes could be returned also if the data stream is configured to operate in non blocking mode which is recommended. Check value bytes_read to determine how many bytes were read.
0 | Read data and bytes_read contains the number of read bytes. If bytes_read is 0 end of input (end of file) is reached. |
EAGAIN | Data stream operates in non blocking mode and no bytes could be read. No error log is written. |
EBADF | ioc is closed, has an invalid value or is not open for reading. |
int write_iochannel( iochannel_t ioc, size_t size, const void * buffer/*[size]*/, /*out*/size_t * bytes_written )
Writes size bytes from buffer to the data stream referenced by ioc. Returns EAGAIN in case data stream is in non blocking mode and no bytes could be written (due to no more system buffer space). Less then size bytes could be written if the data stream is configured to operate in non blocking mode which is recommended. Check value bytes_written to determine how many bytes were written.
0 | The first *bytes_written data bytes from buffer are written. |
EAGAIN | Data stream operates in non blocking mode and no bytes could be written. No error log is written. |
EPIPE | Receiver has closed its connection or closed it during a blocking write. No error log is written. |
EBADF | ioc is closed, has an invalid value or is not open for writing. |
static inline bool isfree_iochannel( iochannel_t ioc )
Implements iochannel_t.isfree_iochannel.
Describes an input/output channel like a file or network connection.
typedef sys_iochannel_t iochannel_t
Choose Posix file descriptor type.
#define sys_iochannel_t int
Returns number of opened I/O data channels.
int nropen_iochannel( /*out*/size_t * number_open )
Test iochannel_t functionality.
int unittest_io_iochannel( void )
Static initializer.
#define iochannel_FREE sys_iochannel_FREE
Makes ioc a duplicate of from_ioc.
int initcopy_iochannel( /*out*/iochannel_t * ioc, iochannel_t from_ioc )
Closes the I/O channel (file descriptor).
int free_iochannel( iochannel_t * ioc )
Returns true if ioc equals iochannel_FREE.
static inline bool isfree_iochannel( const iochannel_t ioc )
Returns true if ioc is initialized and valid.
bool isvalid_iochannel( const iochannel_t ioc )
Returns accessmode_e for an io channel.
uint8_t accessmode_iochannel( const iochannel_t ioc )
Reads size bytes from the data stream referenced by ioc into buffer.
int read_iochannel( iochannel_t ioc, size_t size, /*out*/void * buffer/*[size]*/, /*out*/size_t * bytes_read )
Writes size bytes from buffer to the data stream referenced by ioc.
int write_iochannel( iochannel_t ioc, size_t size, const void * buffer/*[size]*/, /*out*/size_t * bytes_written )
Implements iochannel_t.isfree_iochannel.
static inline bool isfree_iochannel( iochannel_t ioc )
Implements directory_t.io_directory.
#define io_directory( dir ) (dirfd((DIR*)CONST_CAST(directory_t, dir)))