| 86 | //------------------------------------------------------------------------------ |
| 87 | |
| 88 | int |
| 89 | main(int argc, char** argv) |
| 90 | { |
| 91 | try |
| 92 | { |
| 93 | // Check command line arguments. |
| 94 | if(argc != 4 && argc != 5) |
| 95 | { |
| 96 | std::cerr << "Usage: http-client-awaitable <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" |
| 97 | << "Example:\n" |
| 98 | << " http-client-awaitable www.example.com 80 /\n" |
| 99 | << " http-client-awaitable www.example.com 80 / 1.0\n"; |
| 100 | return EXIT_FAILURE; |
| 101 | } |
| 102 | auto const host = argv[1]; |
| 103 | auto const port = argv[2]; |
| 104 | auto const target = argv[3]; |
| 105 | auto const version = |
| 106 | argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11; |
| 107 | |
| 108 | // The io_context is required for all I/O |
| 109 | net::io_context ioc; |
| 110 | |
| 111 | // Launch the asynchronous operation |
| 112 | net::co_spawn( |
| 113 | ioc, |
| 114 | do_session(host, port, target, version), |
| 115 | // If the awaitable exists with an exception, it gets delivered here |
| 116 | // as `e`. This can happen for regular errors, such as connection |
| 117 | // drops. |
| 118 | [](std::exception_ptr e) |
| 119 | { |
| 120 | if(e) |
| 121 | std::rethrow_exception(e); |
| 122 | }); |
| 123 | |
| 124 | // Run the I/O service. The call will return when |
| 125 | // the get operation is complete. |
| 126 | ioc.run(); |
| 127 | } |
| 128 | catch(std::exception const& e) |
| 129 | { |
| 130 | std::cerr << "Error: " << e.what() << std::endl; |
| 131 | return EXIT_FAILURE; |
| 132 | } |
| 133 | return EXIT_SUCCESS; |
| 134 | } |
| 135 | |
| 136 | #else |
| 137 |
nothing calls this directly
no test coverage detected