当前位置: 首页>>代码示例>>C++>>正文


C++ DatabaseConnection::call方法代码示例

本文整理汇总了C++中DatabaseConnection::call方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnection::call方法的具体用法?C++ DatabaseConnection::call怎么用?C++ DatabaseConnection::call使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseConnection的用法示例。


在下文中一共展示了DatabaseConnection::call方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: connections

/**
 *
 * Reserves a database connection. Until this is freed, it will not be re-used.
 *
 * @param timeout The minimum amount of time to use this connection in seconds
 * @param receiver The object which we'll send any data to
 *
 * @return A UUID for this connection
 */
DatabaseConnection *DatabaseConnectionManager::reserveDatabaseConnectionObj(
        int timeout, SmartObject *receiver)
{
    ConnectionRecord record, currentRecord;
    DatabaseConnection *connection = nullptr, *currentConnection;
    int count;
    bool running, busy;

    if (timeout != 0) {

        // Expiry = unixtime + whatever timeout started as
        timeout += std::time(nullptr);
    }

    while (connection == nullptr) {

        // Reset counter
        count = 0;

        // Iterate connections
        Connections connections(this->connections);
        for (Connections::iterator it = connections.begin();
             it != connections.end(); ++it) {

            currentConnection = it->first;
            currentRecord = it->second;

            if (currentRecord.expiry != 0) {

                // This connection has an expiry. No expiry indicates that it is
                // a reserved connection that should not be re-assigned.
                if (connection == nullptr) {

                    // Lock this connection's mutex
                    currentConnection->mutex.lock();

                    // Check if this connection is in the process of shutting
                    // down or is busy with something (or has pending queries)
                    busy = currentConnection->busy
                            || !currentConnection->commands.empty();

                    // Unlock the mutex
                    currentConnection->mutex.unlock();

                    if (currentConnection->isStopping() && !busy) {

                        // Re-use this connection
                        connection = currentConnection;

                        // Disconnect the execution signal so if the old
                        // receiver is still around it won't keep getting
                        // signals
                        connection->disconnectQueue(
                            DatabaseConnection::EXECUTED);

                        // Rollback transaction if applicable
                        connection->call(Variant(),
                                         QueryEvent::CLEAN_STATE);
                    }

                } else if (currentRecord.expiry != 0
                           && currentRecord.expiry > std::time(nullptr)) {

                    // This connection has expired

                    // Lock this connection's mutex
                    currentConnection->mutex.lock();

                    // Check if this connection is in the process of shutting
                    // down or is busy with something
                    busy = currentConnection->busy
                            || !currentConnection->commands.empty();

                    // Unlock the mutex
                    currentConnection->mutex.unlock();

                    if (!busy) {
                        // Tell the connection to disconnect. We'll free memory
                        // after that is finished
                        if (!currentConnection->isStopping()) {

                            // Ensure this connection's signals are disconnected
                            currentConnection->disconnectQueue(
                                DatabaseConnection::EXECUTED);

                            // Connect to ourself. After the disconnect
                            // completes, we need to free the connection

                            currentConnection->connectQueue(
                                DatabaseConnection::EXECUTED, this);

//.........这里部分代码省略.........
开发者ID:RabidSQL,项目名称:backend,代码行数:101,代码来源:DatabaseConnectionManager.cpp


注:本文中的DatabaseConnection::call方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。