| 1426 | |
| 1427 | |
| 1428 | Future<Connection> connect( |
| 1429 | const network::Address& address, |
| 1430 | Scheme scheme, |
| 1431 | const Option<string>& peer_hostname) |
| 1432 | { |
| 1433 | SocketImpl::Kind kind; |
| 1434 | |
| 1435 | switch (scheme) { |
| 1436 | case Scheme::HTTP: |
| 1437 | kind = SocketImpl::Kind::POLL; |
| 1438 | break; |
| 1439 | #ifdef USE_SSL_SOCKET |
| 1440 | case Scheme::HTTPS: |
| 1441 | kind = SocketImpl::Kind::SSL; |
| 1442 | break; |
| 1443 | #endif |
| 1444 | } |
| 1445 | |
| 1446 | Try<network::Socket> socket = network::Socket::create( |
| 1447 | address.family(), |
| 1448 | kind); |
| 1449 | |
| 1450 | if (socket.isError()) { |
| 1451 | return Failure("Failed to create socket: " + socket.error()); |
| 1452 | } |
| 1453 | |
| 1454 | Future<Nothing> connected = [&]() { |
| 1455 | switch (scheme) { |
| 1456 | case Scheme::HTTP: |
| 1457 | return socket->connect(address); |
| 1458 | #ifdef USE_SSL_SOCKET |
| 1459 | case Scheme::HTTPS: |
| 1460 | return socket->connect( |
| 1461 | address, |
| 1462 | network::openssl::create_tls_client_config(peer_hostname)); |
| 1463 | #endif |
| 1464 | } |
| 1465 | UNREACHABLE(); |
| 1466 | }(); |
| 1467 | |
| 1468 | return connected |
| 1469 | .then([socket, address]() -> Future<Connection> { |
| 1470 | Try<network::Address> localAddress = socket->address(); |
| 1471 | if (localAddress.isError()) { |
| 1472 | return Failure("Failed to get socket's local address: " + |
| 1473 | localAddress.error()); |
| 1474 | } |
| 1475 | |
| 1476 | return Connection(socket.get(), localAddress.get(), address); |
| 1477 | }); |
| 1478 | } |
| 1479 | |
| 1480 | |
| 1481 | Future<Connection> connect( |
no test coverage detected