Elektra  0.9.6
Functions
io.c File Reference

Implementation of I/O functions as defined in kdbio.h. More...

#include <kdbhelper.h>
#include <kdbinvoke.h>
#include <kdbio.h>
#include <kdbioplugin.h>
#include <kdbioprivate.h>
#include <kdblogger.h>
#include <kdbprivate.h>
#include <stdio.h>
Include dependency graph for io.c:

Functions

int elektraIoContract (KeySet *contract, ElektraIoInterface *ioBinding)
 Creates a contract for use with kdbOpen() that sets up an I/O binding. More...
 
ElektraIoInterfaceelektraIoGetBinding (KDB *kdb)
 Get I/O binding for asynchronous I/O operations for KDB instance. More...
 
ElektraIoInterfaceelektraIoNewBinding (ElektraIoBindingAddFd *addFd, ElektraIoBindingUpdateFd *updateFd, ElektraIoBindingRemoveFd *removeFd, ElektraIoBindingAddTimer *addTimer, ElektraIoBindingUpdateTimer *updateTimer, ElektraIoBindingRemoveTimer *removeTimer, ElektraIoBindingAddIdle *addIdle, ElektraIoBindingUpdateIdle *updateIdle, ElektraIoBindingRemoveIdle *removeIdle, ElektraIoBindingCleanup *cleanup)
 Create a new I/O binding. More...
 
int elektraIoBindingAddFd (ElektraIoInterface *binding, ElektraIoFdOperation *fdOp)
 Add file descriptor to be watched by I/O binding. More...
 
int elektraIoBindingUpdateFd (ElektraIoFdOperation *fdOp)
 Notify I/O binding about changes to file descriptor watch operation. More...
 
int elektraIoBindingRemoveFd (ElektraIoFdOperation *fdOp)
 Remove file descriptor from I/O binding. More...
 
int elektraIoBindingAddTimer (ElektraIoInterface *binding, ElektraIoTimerOperation *timerOp)
 Add timer to I/O binding. More...
 
int elektraIoBindingUpdateTimer (ElektraIoTimerOperation *timerOp)
 Notifiy I/O binding about changes to timer structure. More...
 
int elektraIoBindingRemoveTimer (ElektraIoTimerOperation *timerOp)
 Remove timer from I/O binding. More...
 
int elektraIoBindingAddIdle (ElektraIoInterface *binding, ElektraIoIdleOperation *idleOp)
 Add idle to I/O binding. More...
 
int elektraIoBindingUpdateIdle (ElektraIoIdleOperation *idleOp)
 Notifiy I/O binding about changes to idle structure. More...
 
int elektraIoBindingRemoveIdle (ElektraIoIdleOperation *idleOp)
 Remove idle from I/O binding. More...
 
int elektraIoBindingCleanup (ElektraIoInterface *binding)
 Free memory used by I/O binding. More...
 
void * elektraIoBindingGetData (ElektraIoInterface *binding)
 Get private data from I/O Binding. More...
 
int elektraIoBindingSetData (ElektraIoInterface *binding, void *data)
 Set private data from I/O Binding. More...
 
ElektraIoFdOperationelektraIoNewFdOperation (int fd, int flags, int enabled, ElektraIoFdCallback callback, void *privateData)
 Create a new file descriptor watch operation. More...
 
ElektraIoTimerOperationelektraIoNewTimerOperation (unsigned int interval, int enabled, ElektraIoTimerCallback callback, void *privateData)
 Create a new timer operation. More...
 
ElektraIoIdleOperationelektraIoNewIdleOperation (int enabled, ElektraIoIdleCallback callback, void *privateData)
 Create a new idle operation. More...
 
int elektraIoFdSetEnabled (ElektraIoFdOperation *fdOp, int enabled)
 Enable or disable file descriptor watch operation. More...
 
int elektraIoFdSetFlags (ElektraIoFdOperation *fdOp, int flags)
 Update flag bitmask of file descriptor watch operation. More...
 
int elektraIoTimerSetEnabled (ElektraIoTimerOperation *timerOp, int enabled)
 Enable or disable timer operation. More...
 
int elektraIoTimerSetInterval (ElektraIoTimerOperation *timerOp, unsigned int interval)
 Update interval of timer operation. More...
 
int elektraIoIdleSetEnabled (ElektraIoIdleOperation *idleOp, int enabled)
 Enable or disable idle operation. More...
 
int elektraIoFdGetFd (ElektraIoFdOperation *fdOp)
 Get file descriptor number from operation. More...
 
void * elektraIoFdGetData (ElektraIoFdOperation *fdOp)
 Get private data from operation. More...
 
int elektraIoFdSetBindingData (ElektraIoFdOperation *fdOp, void *data)
 Set private binding data for operation. More...
 
void * elektraIoFdGetBindingData (ElektraIoFdOperation *fdOp)
 Get private binding data from operation. More...
 
ElektraIoInterfaceelektraIoFdGetBinding (ElektraIoFdOperation *fdOp)
 Get binding from operation. More...
 
int elektraIoFdIsEnabled (ElektraIoFdOperation *fdOp)
 Check if file descriptor watch operation is enabled or disabled. More...
 
int elektraIoFdGetFlags (ElektraIoFdOperation *fdOp)
 Get flag bitmask of file descriptor watch operation. More...
 
ElektraIoFdCallback elektraIoFdGetCallback (ElektraIoFdOperation *fdOp)
 Get callback of file descriptor watch operation. More...
 
int elektraIoTimerSetBindingData (ElektraIoTimerOperation *timerOp, void *data)
 Set private binding data for operation. More...
 
void * elektraIoTimerGetBindingData (ElektraIoTimerOperation *timerOp)
 Get private binding data from operation. More...
 
ElektraIoInterfaceelektraIoTimerGetBinding (ElektraIoTimerOperation *timerOp)
 Get binding from operation. More...
 
void * elektraIoTimerGetData (ElektraIoTimerOperation *timerOp)
 Get private data from operation. More...
 
int elektraIoTimerIsEnabled (ElektraIoTimerOperation *timerOp)
 Check if timer operation is enabled or disabled. More...
 
unsigned int elektraIoTimerGetInterval (ElektraIoTimerOperation *timerOp)
 Get interval of timer operation. More...
 
ElektraIoTimerCallback elektraIoTimerGetCallback (ElektraIoTimerOperation *timerOp)
 Get callback of timer operation. More...
 
int elektraIoIdleSetBindingData (ElektraIoIdleOperation *idleOp, void *data)
 Set private binding data for operation. More...
 
void * elektraIoIdleGetBindingData (ElektraIoIdleOperation *idleOp)
 Get private binding data from operation. More...
 
ElektraIoInterfaceelektraIoIdleGetBinding (ElektraIoIdleOperation *idleOp)
 Get binding from operation. More...
 
void * elektraIoIdleGetData (ElektraIoIdleOperation *idleOp)
 Get private data from operation. More...
 
int elektraIoIdleIsEnabled (ElektraIoIdleOperation *idleOp)
 Check if idle operation is enabled or disabled. More...
 
ElektraIoIdleCallback elektraIoIdleGetCallback (ElektraIoIdleOperation *idleOp)
 Get callback of idle operation. More...
 

Detailed Description

Implementation of I/O functions as defined in kdbio.h.

Function Documentation

◆ elektraIoBindingAddFd()

int elektraIoBindingAddFd ( ElektraIoInterface binding,
ElektraIoFdOperation fdOp 
)

Add file descriptor to be watched by I/O binding.

An operation may only be added to one binding.

Parameters
bindingI/O binding handle
fdOpfile descriptor operation handle
Return values
1on success
0on error

◆ elektraIoBindingAddIdle()

int elektraIoBindingAddIdle ( ElektraIoInterface binding,
ElektraIoIdleOperation idleOp 
)

Add idle to I/O binding.

Idle callbacks are executed without negative effects on other IO sources or the application (e.g. next event loop iteration) An operation may only be added to one binding.

Parameters
bindingI/O binding handle
idleOpidle operation handle
Return values
1on success
0on error

◆ elektraIoBindingAddTimer()

int elektraIoBindingAddTimer ( ElektraIoInterface binding,
ElektraIoTimerOperation timerOp 
)

Add timer to I/O binding.

Timeouts callbacks are executed after the initial interval has elapsed and then repeatedly after the interval has elapsed. An operation may only be added to one binding.

Parameters
bindingI/O binding handle
timerOptimer operation handle
Return values
1on success
0on error

◆ elektraIoBindingCleanup()

int elektraIoBindingCleanup ( ElektraIoInterface binding)

Free memory used by I/O binding.

All added operations have to be removed before calling this function.

Parameters
bindingI/O binding handle
Return values
1on success
0on error

◆ elektraIoBindingGetData()

void* elektraIoBindingGetData ( ElektraIoInterface binding)

Get private data from I/O Binding.

To be used by I/O binding implementations only.

Parameters
bindingI/O-Binding handle
Returns
pointer to data or NULL on error

◆ elektraIoBindingRemoveFd()

int elektraIoBindingRemoveFd ( ElektraIoFdOperation fdOp)

Remove file descriptor from I/O binding.

Parameters
fdOpfile descriptor operation handle
Return values
1on success
0on error

◆ elektraIoBindingRemoveIdle()

int elektraIoBindingRemoveIdle ( ElektraIoIdleOperation idleOp)

Remove idle from I/O binding.

Parameters
idleOpidle operation handle
Return values
1on success
0on error

◆ elektraIoBindingRemoveTimer()

int elektraIoBindingRemoveTimer ( ElektraIoTimerOperation timerOp)

Remove timer from I/O binding.

Parameters
timerOptimer operation handle
Return values
1on success
0on error

◆ elektraIoBindingSetData()

int elektraIoBindingSetData ( ElektraIoInterface binding,
void *  data 
)

Set private data from I/O Binding.

To be used by I/O binding implementations only.

Parameters
bindingI/O binding handle
dataprivate data
Return values
1on success
0on error

◆ elektraIoBindingUpdateFd()

int elektraIoBindingUpdateFd ( ElektraIoFdOperation fdOp)

Notify I/O binding about changes to file descriptor watch operation.

Parameters
fdOpfile descriptor operation handle
Return values
1on success
0on error

◆ elektraIoBindingUpdateIdle()

int elektraIoBindingUpdateIdle ( ElektraIoIdleOperation idleOp)

Notifiy I/O binding about changes to idle structure.

Parameters
idleOpidle operation handle
Return values
1on success
0on error

◆ elektraIoBindingUpdateTimer()

int elektraIoBindingUpdateTimer ( ElektraIoTimerOperation timerOp)

Notifiy I/O binding about changes to timer structure.

Parameters
timerOptimer operation handle
Return values
1on success
0on error

◆ elektraIoContract()

int elektraIoContract ( KeySet *  contract,
ElektraIoInterface ioBinding 
)

Creates a contract for use with kdbOpen() that sets up an I/O binding.

When you call kdbOpen() with this contract, the KDB instance will use ioBinding as its I/O binding.

Parameters
contractThe keyset into which the contract is written.
ioBindingThe ioBinding to use.
Return values
-1if contract or ioBinding are NULL
0on success

◆ elektraIoFdGetBinding()

ElektraIoInterface* elektraIoFdGetBinding ( ElektraIoFdOperation fdOp)

Get binding from operation.

Parameters
fdOpfd operation handle
Returns
pointer to binding or NULL on error

◆ elektraIoFdGetBindingData()

void* elektraIoFdGetBindingData ( ElektraIoFdOperation fdOp)

Get private binding data from operation.

Parameters
fdOpfile descriptor operation handle
Returns
pointer to data or NULL on error

◆ elektraIoFdGetCallback()

ElektraIoFdCallback elektraIoFdGetCallback ( ElektraIoFdOperation fdOp)

Get callback of file descriptor watch operation.

Parameters
fdOpfile descriptor operation handle
Returns
callback

◆ elektraIoFdGetData()

void* elektraIoFdGetData ( ElektraIoFdOperation fdOp)

Get private data from operation.

Parameters
fdOpfile descriptor operation handle
Returns
pointer to data or NULL on error

◆ elektraIoFdGetFd()

int elektraIoFdGetFd ( ElektraIoFdOperation fdOp)

Get file descriptor number from operation.

Parameters
fdOpfile descriptor operation handle
Returns
file descriptor number or 0 on error

◆ elektraIoFdGetFlags()

int elektraIoFdGetFlags ( ElektraIoFdOperation fdOp)

Get flag bitmask of file descriptor watch operation.

Parameters
fdOpfile descriptor operation handle
Returns
watch flag bitmask (see ElektraIoFdFlags).

◆ elektraIoFdIsEnabled()

int elektraIoFdIsEnabled ( ElektraIoFdOperation fdOp)

Check if file descriptor watch operation is enabled or disabled.

Parameters
fdOpfile descriptor operation handle
Return values
0if disabled
1if enabled

◆ elektraIoFdSetBindingData()

int elektraIoFdSetBindingData ( ElektraIoFdOperation fdOp,
void *  data 
)

Set private binding data for operation.

Parameters
fdOpfile descriptor operation handle
datapointer to data
Return values
1on success
0on error

◆ elektraIoFdSetEnabled()

int elektraIoFdSetEnabled ( ElektraIoFdOperation fdOp,
int  enabled 
)

Enable or disable file descriptor watch operation.

Parameters
fdOpfile descriptor operation handle
enabled0 to disabled, any other value for enabled
Return values
1on success
0on error

◆ elektraIoFdSetFlags()

int elektraIoFdSetFlags ( ElektraIoFdOperation fdOp,
int  flags 
)

Update flag bitmask of file descriptor watch operation.

Parameters
fdOpfile descriptor operation handle
flagswatch flag bitmask (see ElektraIoFdFlags).
Return values
1on success
0on error

◆ elektraIoGetBinding()

ElektraIoInterface* elektraIoGetBinding ( KDB *  kdb)

Get I/O binding for asynchronous I/O operations for KDB instance.

Returns NULL if no I/O binding was set.

Parameters
kdbKDB instance
Returns
I/O binding or NULL

◆ elektraIoIdleGetBinding()

ElektraIoInterface* elektraIoIdleGetBinding ( ElektraIoIdleOperation idleOp)

Get binding from operation.

Parameters
idleOpidle operation handle
Returns
pointer to binding or NULL on error

◆ elektraIoIdleGetBindingData()

void* elektraIoIdleGetBindingData ( ElektraIoIdleOperation idleOp)

Get private binding data from operation.

Parameters
idleOpidle operation handle
Returns
pointer to data or NULL on error

◆ elektraIoIdleGetCallback()

ElektraIoIdleCallback elektraIoIdleGetCallback ( ElektraIoIdleOperation idleOp)

Get callback of idle operation.

Parameters
idleOpidle operation handle
Returns
callback

◆ elektraIoIdleGetData()

void* elektraIoIdleGetData ( ElektraIoIdleOperation idleOp)

Get private data from operation.

Parameters
idleOpidle operation handle
Returns
pointer to data or NULL on error

◆ elektraIoIdleIsEnabled()

int elektraIoIdleIsEnabled ( ElektraIoIdleOperation idleOp)

Check if idle operation is enabled or disabled.

Parameters
idleOpidle operation handle
Return values
0if disabled
1if enabled

◆ elektraIoIdleSetBindingData()

int elektraIoIdleSetBindingData ( ElektraIoIdleOperation idleOp,
void *  data 
)

Set private binding data for operation.

Parameters
idleOpidle operation handle
datapointer to data
Return values
1on success
0on error

◆ elektraIoIdleSetEnabled()

int elektraIoIdleSetEnabled ( ElektraIoIdleOperation idleOp,
int  enabled 
)

Enable or disable idle operation.

Parameters
idleOpidle operation handle
enabled0 to disabled, any other value for enabled
Return values
1on success
0on error

◆ elektraIoNewBinding()

ElektraIoInterface* elektraIoNewBinding ( ElektraIoBindingAddFd addFd,
ElektraIoBindingUpdateFd updateFd,
ElektraIoBindingRemoveFd removeFd,
ElektraIoBindingAddTimer addTimer,
ElektraIoBindingUpdateTimer updateTimer,
ElektraIoBindingRemoveTimer removeTimer,
ElektraIoBindingAddIdle addIdle,
ElektraIoBindingUpdateIdle updateIdle,
ElektraIoBindingRemoveIdle removeIdle,
ElektraIoBindingCleanup cleanup 
)

Create a new I/O binding.

Make sure to free returned data in ElektraIoBindingCleanup.

Parameters
addFdfunction for adding a file descriptor watch operation
updateFdfunction for updating a file descriptor operation
removeFdfunction for removing a file descriptor operation
addTimerfunction for adding a timer operation
updateTimerfunction for updateing a timer operation
removeTimerfunction for removing a timer operation
addIdlefunction for adding an idle operation
updateIdlefunction for updating an idle operation
removeIdlefunction for removing an idle operation
cleanupfunction for cleaning up binding data
Returns
newly created binding

◆ elektraIoNewFdOperation()

ElektraIoFdOperation* elektraIoNewFdOperation ( int  fd,
int  flags,
int  enabled,
ElektraIoFdCallback  callback,
void *  data 
)

Create a new file descriptor watch operation.

Free returned data after use.

Parameters
fdfile descriptor number
flagswatch flag bitmask (see ElektraIoFdFlags). Select on which file descriptor state changes the callback should be invoked
enabled0 to disabled, any other value for enabled
callbackCalled when file descriptor state has changes
dataCustom private data
Returns
file descriptor operation handle

◆ elektraIoNewIdleOperation()

ElektraIoIdleOperation* elektraIoNewIdleOperation ( int  enabled,
ElektraIoIdleCallback  callback,
void *  data 
)

Create a new idle operation.

Free returned data after use.

Parameters
enabled0 to disable, any other value for enabled
callbackCalled when file descriptor state has changes
dataCustom private data
Returns
idle operation handle

◆ elektraIoNewTimerOperation()

ElektraIoTimerOperation* elektraIoNewTimerOperation ( unsigned int  interval,
int  enabled,
ElektraIoTimerCallback  callback,
void *  data 
)

Create a new timer operation.

Free returned data after use.

Parameters
intervaltimer interval in milliseconds
enabled0 to disable, any other value for enabled
callbackCalled when file descriptor state has changes
dataCustom private data
Returns
timer operation handle

◆ elektraIoTimerGetBinding()

ElektraIoInterface* elektraIoTimerGetBinding ( ElektraIoTimerOperation timerOp)

Get binding from operation.

Parameters
timerOptimer operation handle
Returns
pointer to binding or NULL on error

◆ elektraIoTimerGetBindingData()

void* elektraIoTimerGetBindingData ( ElektraIoTimerOperation timerOp)

Get private binding data from operation.

Parameters
timerOptimer operation handle
Returns
pointer to data or NULL on error

◆ elektraIoTimerGetCallback()

ElektraIoTimerCallback elektraIoTimerGetCallback ( ElektraIoTimerOperation timerOp)

Get callback of timer operation.

Parameters
timerOptimer operation handle
Returns
callback

◆ elektraIoTimerGetData()

void* elektraIoTimerGetData ( ElektraIoTimerOperation timerOp)

Get private data from operation.

Parameters
timerOptimer operation handle
Returns
pointer to data or NULL on error

◆ elektraIoTimerGetInterval()

unsigned int elektraIoTimerGetInterval ( ElektraIoTimerOperation timerOp)

Get interval of timer operation.

Parameters
timerOptimer operation handle
Returns
timer interval in milliseconds, 0 on error

◆ elektraIoTimerIsEnabled()

int elektraIoTimerIsEnabled ( ElektraIoTimerOperation timerOp)

Check if timer operation is enabled or disabled.

Parameters
timerOptimer operation handle
Return values
0if disabled
1if enabled

◆ elektraIoTimerSetBindingData()

int elektraIoTimerSetBindingData ( ElektraIoTimerOperation timerOp,
void *  data 
)

Set private binding data for operation.

Parameters
timerOptimer operation handle
datapointer to data
Return values
1on success
0on error

◆ elektraIoTimerSetEnabled()

int elektraIoTimerSetEnabled ( ElektraIoTimerOperation timerOp,
int  enabled 
)

Enable or disable timer operation.

Parameters
timerOptimer operation handle
enabled0 to disabled, any other value for enabled
Return values
1on success
0on error

◆ elektraIoTimerSetInterval()

int elektraIoTimerSetInterval ( ElektraIoTimerOperation timerOp,
unsigned int  interval 
)

Update interval of timer operation.

Parameters
timerOptimer operation handle
intervaltimer interval in milliseconds
Return values
1on success
0on error