src/siri/db/servers.c
/*
 * This function sends a package to all online server.
 *
 * Note:a signal can be raised but the callback will always be called.
 *
 * If promises could not be created, the 'cb' function will still be called
 * using the arguments (NULL, data).
 */
This function sends a package to all online server.
Note:a signal can be raised but the callback will always be called.

If promises could not be created, the 'cb' function will still be called
using the arguments (NULL, data).
This function sends a package to all online server . Note : a signal can be raised but the callback will always be called . If promises could not be created the ' cb ' function will still be called using the arguments ( NULL data ) .
void siridb_servers_send_pkg(
        slist_t * servers,
        sirinet_pkg_t * pkg,
        uint64_t timeout,
        sirinet_promises_cb cb,
        void * data)
{
    sirinet_promises_t * promises =
            sirinet_promises_new(servers->len, cb, data, pkg);
    if (promises == NULL)
    {
        free(pkg);
        cb(NULL, data);
    }
    else
    {
        siridb_server_t * server;
        for (size_t i = 0; i < servers->len; i++)
        {
            server = (siridb_server_t *) servers->data[i];
            if (siridb_server_is_online(server))
            {
                if (siridb_server_send_pkg(
                        server,
                        pkg,
                        timeout,
                        sirinet_promises_on_response,
                        promises,
                        FLAG_KEEP_PKG))
                {
                    log_critical(
                            "Allocation error while trying to send a package "
                            "to '%s'", server->name);
                    slist_append(promises->promises, NULL);
                }
            }
            else
            {
                log_debug("Cannot send package to '%s' (server is offline)",
                        server->name);
                slist_append(promises->promises, NULL);
            }
        }
        SIRINET_PROMISES_CHECK(promises)
    }
}
void siridb_servers_send_pkg ( slist_t * servers , sirinet_pkg_t * pkg , uint64_t timeout , sirinet_promises_cb cb , void * data ) { sirinet_promises_t * promises = sirinet_promises_new ( servers -> len , cb , data , pkg ) ; if ( promises == NULL ) { free ( pkg ) ; cb ( NULL , data ) ; } else { siridb_server_t * server ; for ( size_t i = 0 ; i < servers -> len ; i ++ ) { server = ( siridb_server_t * ) servers -> data [ i ] ; if ( siridb_server_is_online ( server ) ) { if ( siridb_server_send_pkg ( server , pkg , timeout , sirinet_promises_on_response , promises , FLAG_KEEP_PKG ) ) { log_critical ( " " " " , server -> name ) ; slist_append ( promises -> promises , NULL ) ; } } else { log_debug ( " " , server -> name ) ; slist_append ( promises -> promises , NULL ) ; } } SIRINET_PROMISES_CHECK ( promises ) } }
This function sends a package to all online server.
This function sends a package to all online server .