mongo_connection *mongo_get_read_write_connection_with_callback(mongo_con_manager *manager, mongo_servers *servers, int connection_flags, void *callback_data, mongo_cleanup_t cleanup_cb, char **error_message) { mongo_connection *connection; mongo_connection_deregister_callback *cb; connection = mongo_get_read_write_connection(manager, servers, connection_flags, error_message); if (!connection) { return NULL; } cb = calloc(1, sizeof(mongo_connection_deregister_callback)); cb->mongo_cleanup_cb = cleanup_cb; cb->callback_data = callback_data; if (connection->cleanup_list) { mongo_connection_deregister_callback *ptr = connection->cleanup_list; do { if (!ptr->next) { ptr->next = cb; break; } ptr = ptr->next; } while(1); } else { connection->cleanup_list = cb; } return connection; }
mongo_connection *mongo_get_read_write_connection_with_callback(mongo_con_manager *manager, mongo_servers *servers, int connection_flags, void *callback_data, mongo_cleanup_t cleanup_cb, char **error_message) { mongo_connection *connection; connection = mongo_get_read_write_connection(manager, servers, connection_flags, error_message); if (!connection) { return NULL; } return mongo_manager_add_connection_callback(connection, callback_data, cleanup_cb); }