⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connpool.c

📁 oci的源码,可以在任何平台上编译,相当方便实用
💻 C
📖 第 1 页 / 共 2 页
字号:
 * ------------------------------------------------------------------------ */

OCI_Connection * OCI_API OCI_ConnPoolGetConnection(OCI_ConnPool *pool)
{
    OCI_Connection *con  = NULL;
    OCI_Item       *item = NULL;
    boolean res          = FALSE;
    boolean found        = FALSE;

    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, NULL);

    if (OCI_LIB_THREADED)
        OCI_MutexAcquire(pool->mutex);

    /* fist, try to find an unused OCI_Connection in list */

    item = pool->cons->head;

    while (item != NULL)
    {
        con = (OCI_Connection *) item->data;

        if (con->cstate == OCI_CONN_ALLOCATED)
        {
            found = TRUE;
            break;
        }

        item = item->next;
    }

    if (found == FALSE)
    {
        /* no available connection found ! Try to allocate a new one... */

        if (OCILib.ver_runtime >= OCI_9 || pool->cons->count < pool->max)
        {
            ub4 i, nb;
            OCI_Connection *c = NULL;

            nb = pool->nb_opened + pool->incr;

            if (nb > pool->max)
                nb = pool->max;

            for (i = 0; i < nb; i++)
            {
                c = OCI_ConnectionAllocate(pool, pool->db, pool->user,
                                           pool->pwd, pool->mode);

                if (i == 0 && c != NULL)
                   con = c;
            }
        }
    }

    if (con != NULL)
    {
        res = TRUE;

        if (con->cstate == OCI_CONN_ALLOCATED)
            res = res && OCI_ConnectionAttach(con);

        res  = res &&  OCI_ConnectionLogon(con);

        if (res == FALSE)
        {
            OCI_ConnectionFree(con);
            con = NULL;
        }
    }

    if (OCI_LIB_THREADED)
        OCI_MutexRelease(pool->mutex);

    OCI_RESULT(res);

    return con;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolGetTimeout
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_ConnPoolGetTimeout(OCI_ConnPool *pool)
{
    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, 0);

    OCI_RESULT(TRUE);

    return pool->timeout;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolSetTimeout
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ConnPoolSetTimeout(OCI_ConnPool *pool, unsigned int value)
{
    boolean res = TRUE;

    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, FALSE);

#if OCI_VERSION_COMPILE >= OCI_9

    if (OCILib.ver_runtime >= OCI_9)
    {
        ub4 timeout = value;

        OCI_CALL3
        (
            res, pool->err,

            OCIAttrSet((dvoid *) pool->handle, (ub4) OCI_HTYPE_CPOOL,
                       (dvoid *) &timeout,(ub4) sizeof(timeout),
                       (ub4) OCI_ATTR_CONN_TIMEOUT, pool->err)
        )
    }

#endif

    if (res == TRUE)
        pool->timeout = value;

    OCI_RESULT(res);

    return res;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolGetlGetNoWait
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ConnPoolGetlGetNoWait(OCI_ConnPool *pool)
{
    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, FALSE);

    OCI_RESULT(TRUE);

    return pool->nowait;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolSetNoWait
 * ------------------------------------------------------------------------ */

boolean OCI_API OCI_ConnPoolSetNoWait(OCI_ConnPool *pool, boolean value)
{
    boolean res = TRUE;

    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, 0);

#if OCI_VERSION_COMPILE >= OCI_9

    if (OCILib.ver_runtime >= OCI_9)
    {
        ub1 nowait = (ub1) value;

        OCI_CALL3
        (
            res, pool->err,

            OCIAttrSet((dvoid *) pool->handle, (ub4) OCI_HTYPE_CPOOL,
                       (dvoid *) &nowait, (ub4) sizeof(nowait),
                       (ub4) OCI_ATTR_CONN_NOWAIT, pool->err)
        )
    }

#endif

    if (res == TRUE)
        pool->nowait = value;

    OCI_RESULT(res);

    return TRUE;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolGetBusyCount
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_ConnPoolGetBusyCount(OCI_ConnPool *pool)
{
    boolean res = TRUE;

    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, 0);

#if OCI_VERSION_COMPILE >= OCI_9

    if (OCILib.ver_runtime >= OCI_9)
    {
        ub4 value = 0;

        OCI_CALL3
        (
            res, pool->err,

            OCIAttrGet((dvoid *) pool->handle,(ub4) OCI_HTYPE_CPOOL,
                       (dvoid *) &value, (ub4 *) NULL,
                       (ub4) OCI_ATTR_CONN_BUSY_COUNT, pool->err)
        )

        if (res == TRUE)
            pool->nb_busy = value;
    }

#endif

    OCI_RESULT(res);

    return pool->nb_busy;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolGetOpenedCount
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_ConnPoolGetOpenedCount(OCI_ConnPool *pool)
{
    boolean res = TRUE;

    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, 0);

#if OCI_VERSION_COMPILE >= OCI_9

    if (OCILib.ver_runtime >= OCI_9)
    {
        ub4 value = 0;

        OCI_CALL3
        (
            res, pool->err,

            OCIAttrGet((dvoid *) pool->handle, (ub4) OCI_HTYPE_CPOOL,
                       (dvoid *) &value, (ub4 *) NULL,
                       (ub4) OCI_ATTR_CONN_OPEN_COUNT, pool->err)
        )

        if (res == TRUE)
            pool->nb_opened = value;
    }

#endif

     OCI_RESULT(res);

     return pool->nb_opened;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolGetMin
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_ConnPoolGetMin(OCI_ConnPool *pool)
{
    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, 0);

    OCI_RESULT(TRUE);

    return pool->min;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolGetMax
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_ConnPoolGetMax(OCI_ConnPool *pool)
{
    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, 0);

    OCI_RESULT(TRUE);

    return pool->max;
}

/* ------------------------------------------------------------------------ *
 * OCI_ConnPoolGetIncrement
 * ------------------------------------------------------------------------ */

unsigned int OCI_API OCI_ConnPoolGetIncrement(OCI_ConnPool *pool)
{
    OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, 0);

    OCI_RESULT(TRUE);

    return pool->incr;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -