# mco_db_sniffer
RT

> Inspect the state of all connections to an existing database.

### Prototype

        MCO_RET	mco_db_sniffer(	/*IN*/ mco_db_h db,
                      /*IN*/ mco_sniffer_callback_t callback,
                      /*IN*/ mco_sniffer_policy policy );

### Arguments

db | The database handle of an existing database
callback | A sniffer callback function
policy | An enumerated value for the sniffer policy

### Description

> This function inspects the state of all connections to the database using the provided user's callback function. It performs database recovery if dead connections were detected. The callback user defined function must implement logic (using OS, timeout, watchdogs,...) to detect dead database connections. If this callback returns MCO_S_DEAD_CONNECTION then recovery of the database will be performed according to the sniffer policy specified.

> The following enum defines the sniffer policy (i.e. when sniffer should call the user-defined callback to check the status of the connection):

        typedef enum mco_sniffer_policy {
            MCO_SNIFFER_INSPECT_ACTIVE_CONNECTIONS,
            MCO_SNIFFER_INSPECT_ACTIVE_TRANSACTIONS,
            MCO_SNIFFER_INSPECT_HUNG_TRANSACTIONS
        } mco_sniffer_policy;

> Nothing should be done to affect the input parameters, and the function should return `MCO_S_DEAD_CONNECTION` to force database recovery or `MCO_S_OK` if the connection is ok; any other return code will cause `mco_db_sniffer()` to interrupt and return this error code.

### Return Codes

MCO_S_OK | The sniffer process completed successfully
MCO_E_ILLEGAL_PARAM | An invalid policy value was specified
User Specified Return Code | A user specified return code was passed from the user-defined callback function to abort the sniffer

### Example

The example code demonstrating how to use this function is too long to include here. Please refer to the SDK sample "samples/native/core/19-recovery/sniffer".

### Files

Header file:
mco.h
Source file:
mcodb.c
Library:
libmcolib.a