| 315 | if (response.content_type.rfind("text/event-stream", 0) == 0) { |
| 316 | const std::string data = |
| 317 | "data: {\"type\":\"error\",\"error\":{\"message\":" + |
| 318 | json_quote(ex.what()) + |
| 319 | "}}\n\n"; |
| 320 | writer.write(data); |
| 321 | } else { |
| 322 | std::cerr << "audiocpp_server streaming response failed: " << ex.what() << "\n"; |
| 323 | } |
| 324 | } |
| 325 | writer.finish(); |
| 326 | } else { |
| 327 | send_all(socket.get(), serialize_response(response)); |
| 328 | } |
| 329 | } catch (const std::exception & ex) { |
| 330 | try { |
| 331 | send_all(socket.get(), serialize_response(error_response(500, ex.what(), "server_error"))); |
| 332 | } catch (const std::exception & send_error) { |
| 333 | std::cerr << "audiocpp_server failed to send error response: " << send_error.what() << "\n"; |
| 334 | } |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | bool wait_for_client(SocketHandle socket, int timeout_ms) { |
| 339 | fd_set read_set; |
| 340 | FD_ZERO(&read_set); |
| 341 | FD_SET(socket, &read_set); |
| 342 | |
| 343 | timeval timeout{}; |
| 344 | timeout.tv_sec = timeout_ms / 1000; |
| 345 | timeout.tv_usec = (timeout_ms % 1000) * 1000; |
| 346 | |
| 347 | #ifdef _WIN32 |
| 348 | const int ready = select(0, &read_set, nullptr, nullptr, &timeout); |
| 349 | #else |
| 350 | const int ready = select(socket + 1, &read_set, nullptr, nullptr, &timeout); |
| 351 | #endif |
| 352 | if (ready < 0) { |
| 353 | #ifdef _WIN32 |
no test coverage detected