| 40 | } |
| 41 | |
| 42 | hsclient* hspool::peek(const char* dbn, const char* tbl, |
| 43 | const char* idx, const char* flds, bool readonly /* = false */) |
| 44 | { |
| 45 | hsclient* client; |
| 46 | const char* addr; |
| 47 | |
| 48 | if (readonly) { |
| 49 | addr = addr_rd_; |
| 50 | } else { |
| 51 | addr = addr_rw_; |
| 52 | } |
| 53 | |
| 54 | locker_->lock(); |
| 55 | |
| 56 | // ��˳���ѯ���ϱ��ֶ����������Ӷ��� |
| 57 | std::list<hsclient*>::iterator it = pool_.begin(); |
| 58 | for (; it != pool_.end(); ++it) { |
| 59 | // �����ַ��ƥ�����������ַ����ƥ�� |
| 60 | if (strcmp((*it)->get_addr(), addr) != 0) { |
| 61 | continue; |
| 62 | } |
| 63 | |
| 64 | // ���Ѿ��ı�����ѯ���ֶ��Ƿ���� |
| 65 | if ((*it)->open_tbl(dbn, tbl, idx, flds, false)) { |
| 66 | client = *it; |
| 67 | pool_.erase(it); |
| 68 | locker_->unlock(); |
| 69 | return client; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // ��ѯ��ַƥ������Ӷ����������һ��ƥ������Ӷ����� |
| 74 | // ���µı� |
| 75 | for (it = pool_.begin(); it != pool_.end();) { |
| 76 | // �����ַ��ƥ�����������ַ����ƥ�� |
| 77 | if (strcmp((*it)->get_addr(), addr) != 0) { |
| 78 | ++it; |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | client = *it; |
| 83 | it = pool_.erase(it); // �����ӳ���ɾ�� |
| 84 | |
| 85 | // ���µı� |
| 86 | if (client->open_tbl(dbn, tbl, idx, flds, true)) { |
| 87 | locker_->unlock(); |
| 88 | return client; |
| 89 | } |
| 90 | |
| 91 | // ��ʧ�ܣ�����Ҫɾ�������Ӷ��� |
| 92 | delete client; |
| 93 | } |
| 94 | |
| 95 | locker_->unlock(); |
| 96 | |
| 97 | client = NEW hsclient(addr, cache_enable_, retry_enable_); |
| 98 | |
| 99 | if (!client->open_tbl(dbn, tbl, idx, flds)) { |
no test coverage detected