| 678 | } |
| 679 | |
| 680 | std::unique_ptr<Sock> Proxy::Connect() const |
| 681 | { |
| 682 | if (!IsValid()) return {}; |
| 683 | |
| 684 | if (!m_is_unix_socket) return ConnectDirectly(proxy, /*manual_connection=*/true); |
| 685 | |
| 686 | #ifdef HAVE_SOCKADDR_UN |
| 687 | auto sock = CreateSock(AF_UNIX, SOCK_STREAM, 0); |
| 688 | if (!sock) { |
| 689 | LogError("Cannot create a socket for connecting to %s\n", m_unix_socket_path); |
| 690 | return {}; |
| 691 | } |
| 692 | |
| 693 | const std::string path{m_unix_socket_path.substr(ADDR_PREFIX_UNIX.length())}; |
| 694 | |
| 695 | struct sockaddr_un addrun; |
| 696 | memset(&addrun, 0, sizeof(addrun)); |
| 697 | addrun.sun_family = AF_UNIX; |
| 698 | // leave the last char in addrun.sun_path[] to be always '\0' |
| 699 | memcpy(addrun.sun_path, path.c_str(), std::min(sizeof(addrun.sun_path) - 1, path.length())); |
| 700 | socklen_t len = sizeof(addrun); |
| 701 | |
| 702 | if (!ConnectToSocket(*sock, |
| 703 | (struct sockaddr*)&addrun, |
| 704 | len, |
| 705 | path, |
| 706 | /*manual_connection=*/true, |
| 707 | std::chrono::milliseconds{nConnectTimeout})) { |
| 708 | return {}; |
| 709 | } |
| 710 | |
| 711 | return sock; |
| 712 | #else |
| 713 | return {}; |
| 714 | #endif |
| 715 | } |
| 716 | |
| 717 | bool SetProxy(enum Network net, const Proxy &addrProxy) { |
| 718 | assert(net >= 0 && net < NET_MAX); |
no test coverage detected