| 98 | } |
| 99 | |
| 100 | int ProcessImpl::connect(const fs::path& data_dir, |
| 101 | const std::string& dest_exe_name, |
| 102 | std::string& address) |
| 103 | { |
| 104 | struct sockaddr_un addr; |
| 105 | std::string error; |
| 106 | if (!ParseAddress(address, data_dir, dest_exe_name, addr, error)) { |
| 107 | throw std::invalid_argument(error); |
| 108 | } |
| 109 | |
| 110 | int fd; |
| 111 | if ((fd = ::socket(addr.sun_family, SOCK_STREAM, 0)) == -1) { |
| 112 | throw std::system_error(errno, std::system_category()); |
| 113 | } |
| 114 | if (::connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) { |
| 115 | return fd; |
| 116 | } |
| 117 | int connect_error = errno; |
| 118 | if (::close(fd) != 0) { |
| 119 | LogWarning("Error closing file descriptor %i '%s': %s", fd, address, SysErrorString(errno)); |
| 120 | } |
| 121 | throw std::system_error(connect_error, std::system_category()); |
| 122 | } |
| 123 | |
| 124 | int ProcessImpl::bind(const fs::path& data_dir, const std::string& exe_name, std::string& address) |
| 125 | { |