| 189 | } |
| 190 | |
| 191 | static bool FindConnection(HPool pool, dmhash_t id, dmSocket::Address address, uint16_t port, bool ssl, HConnection* connection) |
| 192 | { |
| 193 | uint32_t n = pool->m_Connections.Size(); |
| 194 | for (uint32_t i = 0; i < n; ++i) { |
| 195 | Connection* c = &pool->m_Connections[i]; |
| 196 | if (c->m_State == STATE_CONNECTED && c->m_ID == id) { |
| 197 | // We have to return a socket with the correct address family |
| 198 | bool ipv4_match = address.m_family == dmSocket::DOMAIN_IPV4 && dmSocket::IsSocketIPv4(c->m_Socket); |
| 199 | bool ipv6_match = address.m_family == dmSocket::DOMAIN_IPV6 && dmSocket::IsSocketIPv6(c->m_Socket); |
| 200 | if (ipv4_match || ipv6_match) |
| 201 | { |
| 202 | c->m_State = STATE_INUSE; |
| 203 | c->m_ReuseCount++; |
| 204 | *connection = MakeHandle(pool, i, c); |
| 205 | return true; |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | static void DoClose(HPool pool, Connection* c) |
| 214 | { |
no test coverage detected