| 1729 | |
| 1730 | |
| 1731 | PID<HttpProxy> SocketManager::proxy(const Socket& socket) |
| 1732 | { |
| 1733 | HttpProxy* proxy = nullptr; |
| 1734 | |
| 1735 | synchronized (mutex) { |
| 1736 | // This socket might have been asked to get closed (e.g., remote |
| 1737 | // side hang up) while a process is attempting to handle an HTTP |
| 1738 | // request. Thus, if there is no more socket, return an empty PID. |
| 1739 | if (sockets.count(socket) > 0) { |
| 1740 | if (proxies.count(socket) > 0) { |
| 1741 | return proxies[socket]->self(); |
| 1742 | } else { |
| 1743 | proxy = new HttpProxy(sockets.at(socket)); |
| 1744 | proxies[socket] = proxy; |
| 1745 | } |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | // Now check if we need to spawn a newly created proxy. Note that we |
| 1750 | // need to do this outside of the synchronized block above to avoid |
| 1751 | // a possible deadlock (because spawn eventually synchronizes on |
| 1752 | // ProcessManager and ProcessManager::cleanup synchronizes on |
| 1753 | // ProcessManager and then SocketManager, so a deadlock results if |
| 1754 | // we do spawn within the synchronized block above). |
| 1755 | if (proxy != nullptr) { |
| 1756 | return spawn(proxy, true); |
| 1757 | } |
| 1758 | |
| 1759 | return PID<HttpProxy>(); |
| 1760 | } |
| 1761 | |
| 1762 | |
| 1763 | void SocketManager::unproxy(const Socket& socket) |
no test coverage detected