| 85 | } |
| 86 | |
| 87 | void ExchangeServer::run() |
| 88 | { |
| 89 | while (!stopped) |
| 90 | { |
| 91 | Poco::Timespan timeout(250000); |
| 92 | try |
| 93 | { |
| 94 | if (server_socket.poll(timeout, Poco::Net::Socket::SELECT_READ)) |
| 95 | { |
| 96 | Poco::Net::StreamSocket socket; |
| 97 | try |
| 98 | { |
| 99 | socket = server_socket.acceptConnection(); |
| 100 | } |
| 101 | // Termination request |
| 102 | catch (Poco::InvalidArgumentException &) |
| 103 | { |
| 104 | break; |
| 105 | } |
| 106 | |
| 107 | /// Run the handshake on the pool, not inline, so a slow peer does not stall the |
| 108 | /// accept loop and block subsequent connections. Drop the connection if the pool |
| 109 | /// rejects the job (queue full or shutting down). |
| 110 | try |
| 111 | { |
| 112 | handshake_pool.scheduleOrThrowOnError( |
| 113 | [accepted = socket, conns = connections, task_log = log]() |
| 114 | { |
| 115 | try |
| 116 | { |
| 117 | handleConnection(accepted, conns, task_log); |
| 118 | } |
| 119 | catch (...) |
| 120 | { |
| 121 | tryLogCurrentException(task_log); |
| 122 | } |
| 123 | }); |
| 124 | } |
| 125 | catch (...) |
| 126 | { |
| 127 | tryLogCurrentException(log); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | catch (Poco::Exception &) |
| 132 | { |
| 133 | tryLogCurrentException(log); |
| 134 | Poco::Thread::sleep(50); |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | namespace |
| 140 | { |
nothing calls this directly
no test coverage detected