All communications with KAVDaemon are performed within a a context of a session. In libkavclient this session context is represented by a variable of type kav_ctx. Internally, kav_ctx is a pointer to a structure, but you should treat is a an opaque token identifying your connection to KAVDaemon. You set KAVDaemon connection parameters into the context (using the functions described in the section called “Setting connection parameters”), and then call one of the libkavclient file or memory checking functions. Those functions, in turn, record the results of the checks they perform in the context. You then use the functions described in the section called “Interpreting check results” to extract the detailed results from the context.
Before a session context can be used to communicate to KAVDaemon it must be allocated. Use the kav_new function to do this. This function is declared as follows:
The kav_new function allocates a new session context. Use this context to check files and memory regions for viruses, as described in further sections of this manual. When a session context is no longer needed, it must be disposed of with kav_free.
In a multi-threaded program it is completely safe to concurrently call libkavclient functions from different threads using separate session contexts. Thus, typically, each thread that needs to access KAVDaemon will allocate its own session context. However, if session contexts are to be shared among threads, you must ensure that only one thread accesses a session context at any given time by employing appropriate locking mechanisms.
If kav_new fails to allocate a new session context, it returns NULL. The only reason why kav_new would fail is when your system could not allocate memory; e.g. if it's out of memory.