@@ -3250,6 +3250,24 @@ inline int shutdown_socket(socket_t sock) {
3250
3250
#endif
3251
3251
}
3252
3252
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
+
3253
3271
template <typename BindOrConnect>
3254
3272
socket_t create_socket (const std::string &host, const std::string &ip, int port,
3255
3273
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,
3290
3308
if (sock != INVALID_SOCKET) {
3291
3309
sockaddr_un addr{};
3292
3310
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 );
3294
3314
3295
3315
hints.ai_addr = reinterpret_cast <sockaddr *>(&addr);
3296
3316
hints.ai_addrlen = static_cast <socklen_t >(
@@ -7044,9 +7064,10 @@ inline ClientImpl::ClientImpl(const std::string &host, int port)
7044
7064
inline ClientImpl::ClientImpl (const std::string &host, int port,
7045
7065
const std::string &client_cert_path,
7046
7066
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
+ }
7050
7071
7051
7072
inline ClientImpl::~ClientImpl () {
7052
7073
std::lock_guard<std::mutex> guard (socket_mutex_);
0 commit comments