| 348 | } |
| 349 | |
| 350 | connect_pool* connect_manager::get(const char* addr, |
| 351 | bool exclusive /* = true */, bool restore /* = false */) |
| 352 | { |
| 353 | string key; |
| 354 | get_key(addr, key); |
| 355 | unsigned long id = get_id(); |
| 356 | |
| 357 | if (exclusive) { |
| 358 | lock_.lock(); |
| 359 | } |
| 360 | |
| 361 | conns_pools& pools = get_pools_by_id(id); |
| 362 | |
| 363 | pools_t::iterator it = pools.pools.begin(); |
| 364 | for (; it != pools.pools.end(); ++it) { |
| 365 | if (key == (*it)->get_key()) { |
| 366 | if (restore && !(*it)->aliving()) { |
| 367 | (*it)->set_alive(true); |
| 368 | } |
| 369 | if (exclusive) { |
| 370 | lock_.unlock(); |
| 371 | } |
| 372 | return *it; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | string buf(addr); |
| 377 | buf.lower(); |
| 378 | |
| 379 | std::map<string, conn_config>::const_iterator cit = addrs_.find(buf); |
| 380 | if (cit == addrs_.end()) { |
| 381 | if (exclusive) { |
| 382 | lock_.unlock(); |
| 383 | } |
| 384 | logger_debug(ACL_CPP_DEBUG_CONN_MANAGER, 1, |
| 385 | "no connect pool for addr %s", addr); |
| 386 | return NULL; |
| 387 | } |
| 388 | |
| 389 | connect_pool* pool = create_pool(cit->second, pools.pools.size()); |
| 390 | pools.pools.push_back(pool); |
| 391 | |
| 392 | if (exclusive) { |
| 393 | lock_.unlock(); |
| 394 | } |
| 395 | |
| 396 | return pool; |
| 397 | } |
| 398 | |
| 399 | ////////////////////////////////////////////////////////////////////////// |
| 400 |
no test coverage detected