MCPcopy Create free account
hub / github.com/boostorg/beast / main

Function main

example/http/client/coro-ssl/http_client_coro_ssl.cpp:148–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146//------------------------------------------------------------------------------
147
148int main(int argc, char** argv)
149{
150 // Check command line arguments.
151 if(argc != 4 && argc != 5)
152 {
153 std::cerr <<
154 "Usage: http-client-coro-ssl <host> <port> <target> [<HTTP version: 1.0 or 1.1(default)>]\n" <<
155 "Example:\n" <<
156 " http-client-coro-ssl www.example.com 443 /\n" <<
157 " http-client-coro-ssl www.example.com 443 / 1.0\n";
158 return EXIT_FAILURE;
159 }
160 auto const host = argv[1];
161 auto const port = argv[2];
162 auto const target = argv[3];
163 int version = argc == 5 && !std::strcmp("1.0", argv[4]) ? 10 : 11;
164
165 // The io_context is required for all I/O
166 net::io_context ioc;
167
168 // The SSL context is required, and holds certificates
169 ssl::context ctx{ssl::context::tlsv12_client};
170
171 // This holds the root certificate used for verification
172 load_root_certificates(ctx);
173
174 // Verify the remote server's certificate
175 ctx.set_verify_mode(ssl::verify_peer);
176
177 // Launch the asynchronous operation
178 boost::asio::spawn(ioc, std::bind(
179 &do_session,
180 std::string(host),
181 std::string(port),
182 std::string(target),
183 version,
184 std::ref(ioc),
185 std::ref(ctx),
186 std::placeholders::_1),
187 // on completion, spawn will call this function
188 [](std::exception_ptr ex)
189 {
190 // if an exception occurred in the coroutine,
191 // it's something critical, e.g. out of memory
192 // we capture normal errors in the ec
193 // so we just rethrow the exception here,
194 // which will cause `ioc.run()` to throw
195 if (ex)
196 std::rethrow_exception(ex);
197 });
198
199 // Run the I/O service. The call will return when
200 // the get operation is complete.
201 ioc.run();
202
203 return EXIT_SUCCESS;
204}

Callers

nothing calls this directly

Calls 3

load_root_certificatesFunction · 0.85
refFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected