@@ -3250,6 +3250,24 @@ inline int shutdown_socket(socket_t sock) {
32503250#endif
32513251}
32523252
3253+ inline std::string escape_abstract_namespace_unix_domain (const std::string& s) {
3254+ if (s.size () > 1 && s[0 ] == ' \0 ' ) {
3255+ auto ret = s;
3256+ ret[0 ] = ' @' ;
3257+ return ret;
3258+ }
3259+ return s;
3260+ }
3261+
3262+ inline std::string unescape_abstract_namespace_unix_domain (const std::string& s) {
3263+ if (s.size () > 1 && s[0 ] == ' @' ) {
3264+ auto ret = s;
3265+ ret[0 ] = ' \0 ' ;
3266+ return ret;
3267+ }
3268+ return s;
3269+ }
3270+
32533271template <typename BindOrConnect>
32543272socket_t create_socket (const std::string &host, const std::string &ip, int port,
32553273 int address_family, int socket_flags, bool tcp_nodelay,
@@ -3290,7 +3308,9 @@ socket_t create_socket(const std::string &host, const std::string &ip, int port,
32903308 if (sock != INVALID_SOCKET) {
32913309 sockaddr_un addr{};
32923310 addr.sun_family = AF_UNIX;
3293- std::copy (host.begin (), host.end (), addr.sun_path );
3311+
3312+ auto unescaped_host = unescape_abstract_namespace_unix_domain (host);
3313+ std::copy (unescaped_host.begin (), unescaped_host.end (), addr.sun_path );
32943314
32953315 hints.ai_addr = reinterpret_cast <sockaddr *>(&addr);
32963316 hints.ai_addrlen = static_cast <socklen_t >(
@@ -7044,9 +7064,10 @@ inline ClientImpl::ClientImpl(const std::string &host, int port)
70447064inline ClientImpl::ClientImpl (const std::string &host, int port,
70457065 const std::string &client_cert_path,
70467066 const std::string &client_key_path)
7047- : host_ (host), port_ (port),
7048- host_and_port_ (adjust_host_string (host) + " :" + std::to_string (port)),
7049- client_cert_path_ (client_cert_path), client_key_path_ (client_key_path) {}
7067+ : host_ (detail::escape_abstract_namespace_unix_domain (host)), port_ (port),
7068+ host_and_port_ (adjust_host_string (host_) + " :" + std::to_string (port)),
7069+ client_cert_path_ (client_cert_path), client_key_path_ (client_key_path) {
7070+ }
70507071
70517072inline ClientImpl::~ClientImpl () {
70527073 std::lock_guard<std::mutex> guard (socket_mutex_);
0 commit comments