# mco_db_sniffer_ex
RT

> Inspects the state of all connections to an existing database and performs recovery if dead connections are detected.

### Prototype

        MCO_RET mco_db_sniffer_ex(
            mco_db_h db,
            mco_sniffer_callback_ex_t callback,
            void *user_context,
            mco_sniffer_policy policy
        );

### Arguments

`db`
Handle of an open database.
`callback`
User-defined function called for each active connection or transaction (see sniffer callback).
`user_context`
Optional pointer passed to the callback; may be `NULL`.
`policy`
Specifies when and how the sniffer inspects connections (see below).

### Description

> This function iterates over database connections or transactions (depending on `policy`) and invokes the provided `callback` for each one. The callback should determine whether the connection is dead (e.g., using timeouts, watchdogs, or OS-specific mechanisms).

> If the callback returns `MCO_S_DEAD_CONNECTION`, the sniffer initiates database recovery for that connection according to the specified policy. If the callback returns any other error code, `mco_db_sniffer_ex` stops immediately and returns that code.

> The `policy` parameter controls the inspection scope:

>         typedef enum mco_sniffer_policy {
>             MCO_SNIFFER_INSPECT_ACTIVE_CONNECTIONS,  // Check all active connections
>             MCO_SNIFFER_INSPECT_ACTIVE_TRANSACTIONS, // Check all active transactions
>             MCO_SNIFFER_INSPECT_HUNG_TRANSACTIONS    // Check only long-running/hung transactions
>         } mco_sniffer_policy;

> The callback must not modify its input parameters. It should return:

> - `MCO_S_OK` — connection is alive,
> - `MCO_S_DEAD_CONNECTION` — connection is dead (triggers recovery),
> - any other error code — aborts the sniffer and propagates the error.

### Return Codes

`MCO_S_OK`
All inspected connections are alive; sniffer completed successfully.
`MCO_E_ILLEGAL_PARAM`
An invalid `policy` value was specified.
User-specified return code
Returned by the callback to abort the sniffer (e.g., custom error or `MCO_S_DEAD_CONNECTION`).

### Files

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