📄 connpool_8c-source.html
字号:
<a name="l00286"></a>00286 <a name="l00287"></a>00287 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00288"></a>00288 <span class="comment"> * OCI_ConnPoolGetConnection</span><a name="l00289"></a>00289 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00290"></a>00290 <a name="l00291"></a><a class="code" href="group__g__connpool.html#g774ce156deb3477c83237a633b6538f6">00291</a> <a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> * OCI_API <a class="code" href="group__g__connpool.html#g774ce156deb3477c83237a633b6538f6" title="Get a connection from the pool.">OCI_ConnPoolGetConnection</a>(<a class="code" href="struct_o_c_i___conn_pool.html" title="Oracle Connection Pool.">OCI_ConnPool</a> *pool)<a name="l00292"></a>00292 {<a name="l00293"></a>00293 <a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> *con = NULL;<a name="l00294"></a>00294 OCI_Item *item = NULL;<a name="l00295"></a>00295 <span class="keywordtype">boolean</span> res = FALSE;<a name="l00296"></a>00296 <span class="keywordtype">boolean</span> found = FALSE;<a name="l00297"></a>00297 <a name="l00298"></a>00298 OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, NULL);<a name="l00299"></a>00299 <a name="l00300"></a>00300 <span class="keywordflow">if</span> (OCI_LIB_THREADED)<a name="l00301"></a>00301 <a class="code" href="group__g__threads.html#g88a05b41e24b3bd1789688702cc6f4f4" title="Acquire a mutex lock.">OCI_MutexAcquire</a>(pool-><a class="code" href="struct_o_c_i___conn_pool.html#7a9e6a95517c3fe35b1d6d1eaca742f9">mutex</a>);<a name="l00302"></a>00302 <a name="l00303"></a>00303 <span class="comment">/* fist, try to find an unsued OCI_Connection in list */</span><a name="l00304"></a>00304 <a name="l00305"></a>00305 item = pool-><a class="code" href="struct_o_c_i___conn_pool.html#d3d8ff5a19eb253338f6951315c1f824">cons</a>->head;<a name="l00306"></a>00306 <a name="l00307"></a>00307 <span class="keywordflow">while</span> (item != NULL)<a name="l00308"></a>00308 {<a name="l00309"></a>00309 con = (<a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> *) item->data;<a name="l00310"></a>00310 <a name="l00311"></a>00311 if (con-><a class="code" href="struct_o_c_i___connection.html#25639578bd259929189e6b842598a187">cstate</a> == OCI_CONN_ALLOCATED)<a name="l00312"></a>00312 {<a name="l00313"></a>00313 found = TRUE;<a name="l00314"></a>00314 <span class="keywordflow">break</span>;<a name="l00315"></a>00315 }<a name="l00316"></a>00316 <a name="l00317"></a>00317 item = item->next;<a name="l00318"></a>00318 }<a name="l00319"></a>00319 <a name="l00320"></a>00320 <span class="keywordflow">if</span> (found == FALSE)<a name="l00321"></a>00321 {<a name="l00322"></a>00322 <span class="comment">/* no available connection found !</span><a name="l00323"></a>00323 <span class="comment"> try to allocate a new one... */</span><a name="l00324"></a>00324 <a name="l00325"></a>00325 <span class="keywordflow">if</span> (OCILib.ver_runtime >= OCI_9 || pool-><a class="code" href="struct_o_c_i___conn_pool.html#d3d8ff5a19eb253338f6951315c1f824">cons</a>->count < pool-><a class="code" href="struct_o_c_i___conn_pool.html#39c9b42b23f075338efd5f29aece833f">max</a>)<a name="l00326"></a>00326 {<a name="l00327"></a>00327 ub4 i, nb;<a name="l00328"></a>00328 <a class="code" href="struct_o_c_i___connection.html" title="Oracle physical connection.">OCI_Connection</a> *c = NULL;<a name="l00329"></a>00329 <a name="l00330"></a>00330 nb = pool-><a class="code" href="struct_o_c_i___conn_pool.html#156dc09d514ccbbb775f4582445a6126">nb_opened</a> + pool-><a class="code" href="struct_o_c_i___conn_pool.html#cc48d8aa34b0bf06ba6bb83be6ec120a">incr</a>;<a name="l00331"></a>00331 <a name="l00332"></a>00332 <span class="keywordflow">if</span> (nb > pool-><a class="code" href="struct_o_c_i___conn_pool.html#39c9b42b23f075338efd5f29aece833f">max</a>)<a name="l00333"></a>00333 nb = pool-><a class="code" href="struct_o_c_i___conn_pool.html#39c9b42b23f075338efd5f29aece833f">max</a>;<a name="l00334"></a>00334 <a name="l00335"></a>00335 <span class="keywordflow">for</span> (i = 0; i < nb; i++)<a name="l00336"></a>00336 {<a name="l00337"></a>00337 c = OCI_ConnectionAllocate(pool, pool-><a class="code" href="struct_o_c_i___conn_pool.html#bb78ea3b8eaa958dcef81dff352d9077">db</a>, pool-><a class="code" href="struct_o_c_i___conn_pool.html#c92e9493167088e1143195216a23c073">user</a>, <a name="l00338"></a>00338 pool-><a class="code" href="struct_o_c_i___conn_pool.html#d73354126d5aa4ccea4913593ca6b911">pwd</a>, pool-><a class="code" href="struct_o_c_i___conn_pool.html#b8e888f25184c362b0070ea5a972ee28">mode</a>);<a name="l00339"></a>00339 <a name="l00340"></a>00340 <span class="keywordflow">if</span> (i == 0 && c != NULL)<a name="l00341"></a>00341 con = c;<a name="l00342"></a>00342 }<a name="l00343"></a>00343 }<a name="l00344"></a>00344 }<a name="l00345"></a>00345 <a name="l00346"></a>00346 <span class="keywordflow">if</span> (con != NULL)<a name="l00347"></a>00347 {<a name="l00348"></a>00348 res = TRUE;<a name="l00349"></a>00349 <a name="l00350"></a>00350 <span class="keywordflow">if</span> (con-><a class="code" href="struct_o_c_i___connection.html#25639578bd259929189e6b842598a187">cstate</a> == OCI_CONN_ALLOCATED)<a name="l00351"></a>00351 res = res && OCI_ConnectionAttach(con);<a name="l00352"></a>00352 <a name="l00353"></a>00353 res = res && OCI_ConnectionLogon(con);<a name="l00354"></a>00354 <a name="l00355"></a>00355 <span class="keywordflow">if</span> (res == FALSE)<a name="l00356"></a>00356 {<a name="l00357"></a>00357 <a class="code" href="group__g__connect.html#gc3fe655e96074adb119908be4650a4c9" title="Close a physical connection to an Oracle database server.">OCI_ConnectionFree</a>(con);<a name="l00358"></a>00358 con = NULL;<a name="l00359"></a>00359 }<a name="l00360"></a>00360 }<a name="l00361"></a>00361 <a name="l00362"></a>00362 <span class="keywordflow">if</span> (OCI_LIB_THREADED)<a name="l00363"></a>00363 <a class="code" href="group__g__threads.html#g366f287cf828533617faf0785181de7f" title="Release a mutex lock.">OCI_MutexRelease</a>(pool-><a class="code" href="struct_o_c_i___conn_pool.html#7a9e6a95517c3fe35b1d6d1eaca742f9">mutex</a>);<a name="l00364"></a>00364 <a name="l00365"></a>00365 OCI_RESULT(res);<a name="l00366"></a>00366 <a name="l00367"></a>00367 <span class="keywordflow">return</span> con;<a name="l00368"></a>00368 }<a name="l00369"></a>00369 <a name="l00370"></a>00370 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00371"></a>00371 <span class="comment"> * OCI_ConnPoolGetTimeout</span><a name="l00372"></a>00372 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00373"></a>00373 <a name="l00374"></a><a class="code" href="group__g__connpool.html#g8fd224a01efdfbb76d642dff095d0612">00374</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> OCI_API <a class="code" href="group__g__connpool.html#g8fd224a01efdfbb76d642dff095d0612" title="Get the idle connection timeout.">OCI_ConnPoolGetTimeout</a>(<a class="code" href="struct_o_c_i___conn_pool.html" title="Oracle Connection Pool.">OCI_ConnPool</a> *pool)<a name="l00375"></a>00375 {<a name="l00376"></a>00376 OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, 0);<a name="l00377"></a>00377 <a name="l00378"></a>00378 OCI_RESULT(TRUE);<a name="l00379"></a>00379 <a name="l00380"></a>00380 <span class="keywordflow">return</span> pool-><a class="code" href="struct_o_c_i___conn_pool.html#b91dfe8884f09a5275ac82ad72bf96c8">timeout</a>;<a name="l00381"></a>00381 }<a name="l00382"></a>00382 <a name="l00383"></a>00383 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00384"></a>00384 <span class="comment"> * OCI_ConnPoolSetTimeout</span><a name="l00385"></a>00385 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00386"></a>00386 <a name="l00387"></a><a class="code" href="group__g__connpool.html#gae3bf80948897765fc15d363de073171">00387</a> <span class="keywordtype">boolean</span> OCI_API <a class="code" href="group__g__connpool.html#gae3bf80948897765fc15d363de073171" title="Set the idle connection timeout.">OCI_ConnPoolSetTimeout</a>(<a class="code" href="struct_o_c_i___conn_pool.html" title="Oracle Connection Pool.">OCI_ConnPool</a> *pool, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> value)<a name="l00388"></a>00388 {<a name="l00389"></a>00389 <span class="keywordtype">boolean</span> res = TRUE;<a name="l00390"></a>00390 <a name="l00391"></a>00391 OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, FALSE);<a name="l00392"></a>00392 <a name="l00393"></a>00393 <span class="preprocessor">#if OCI_VERSION_COMPILE >= OCI_9</span><a name="l00394"></a>00394 <span class="preprocessor"></span><a name="l00395"></a>00395 <span class="keywordflow">if</span> (OCILib.ver_runtime >= OCI_9)<a name="l00396"></a>00396 {<a name="l00397"></a>00397 ub4 timeout = value;<a name="l00398"></a>00398 <a name="l00399"></a>00399 OCI_CALL3<a name="l00400"></a>00400 (<a name="l00401"></a>00401 res, pool-><a class="code" href="struct_o_c_i___conn_pool.html#e960f1a00bee41c9d195c15332dafd2d">err</a>, <a name="l00402"></a>00402 <a name="l00403"></a>00403 OCIAttrSet((dvoid *) pool-><a class="code" href="struct_o_c_i___conn_pool.html#167d91c8dc07bb4713b11394c839457b">handle</a>, (ub4) OCI_HTYPE_CPOOL,<a name="l00404"></a>00404 (dvoid *) &timeout,(ub4) <span class="keyword">sizeof</span>(timeout),<a name="l00405"></a>00405 (ub4) OCI_ATTR_CONN_TIMEOUT, pool-><a class="code" href="struct_o_c_i___conn_pool.html#e960f1a00bee41c9d195c15332dafd2d">err</a>)<a name="l00406"></a>00406 )<a name="l00407"></a>00407 }<a name="l00408"></a>00408 <a name="l00409"></a>00409 <span class="preprocessor">#endif</span><a name="l00410"></a>00410 <span class="preprocessor"></span><a name="l00411"></a>00411 <span class="keywordflow">if</span> (res == TRUE)<a name="l00412"></a>00412 pool-><a class="code" href="struct_o_c_i___conn_pool.html#b91dfe8884f09a5275ac82ad72bf96c8">timeout</a> = value;<a name="l00413"></a>00413 <a name="l00414"></a>00414 OCI_RESULT(res);<a name="l00415"></a>00415 <a name="l00416"></a>00416 <span class="keywordflow">return</span> res;<a name="l00417"></a>00417 }<a name="l00418"></a>00418 <a name="l00419"></a>00419 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00420"></a>00420 <span class="comment"> * OCI_ConnPoolGetlGetNoWait</span><a name="l00421"></a>00421 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00422"></a>00422 <a name="l00423"></a><a class="code" href="group__g__connpool.html#g0dff250d296fe1060a576e9bdb43ffb0">00423</a> <span class="keywordtype">boolean</span> OCI_API <a class="code" href="group__g__connpool.html#g0dff250d296fe1060a576e9bdb43ffb0" title="Get the waiing mode used when no more connections are available from the pool.">OCI_ConnPoolGetlGetNoWait</a>(<a class="code" href="struct_o_c_i___conn_pool.html" title="Oracle Connection Pool.">OCI_ConnPool</a> *pool)<a name="l00424"></a>00424 {<a name="l00425"></a>00425 OCI_CHECK_PTR(OCI_IPC_CONNPOOL, pool, FALSE);<a name="l00426"></a>00426 <a name="l00427"></a>00427 OCI_RESULT(TRUE);<a name="l00428"></a>00428 <a name="l00429"></a>00429 <span class="keywordflow">return</span> pool-><a class="code" href="struct_o_c_i___conn_pool.html#b935cb48925a7e1e8307f5c7a5637316">nowait</a>;<a name="l00430"></a>00430 }<a name="l00431"></a>00431 <a name="l00432"></a>00432 <span class="comment">/* ------------------------------------------------------------------------ *</span><a name="l00433"></a>00433 <span class="comment"> * OCI_ConnPoolSetNoWait</span><a name="l00434"></a>00434 <span class="comment"> * ------------------------------------------------------------------------ */</span><a name="l00435"></a>00435
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -