|
| 1 | +#include <algorithm> |
1 | 2 | #include <viam/sdk/rpc/dial.hpp> |
2 | 3 |
|
3 | 4 | #include <istream> |
@@ -148,20 +149,27 @@ std::shared_ptr<ViamChannel> ViamChannel::dial(const char* uri, |
148 | 149 | if (opts.entity()) { |
149 | 150 | entity = opts.entity()->c_str(); |
150 | 151 | } |
151 | | - char* socket_path = ::dial( |
| 152 | + char* proxy_path = ::dial( |
152 | 153 | uri, entity, type, payload, opts.allows_insecure_downgrade(), float_timeout.count(), ptr); |
153 | | - if (socket_path == NULL) { |
| 154 | + if (proxy_path == NULL) { |
154 | 155 | free_rust_runtime(ptr); |
155 | 156 | throw Exception(ErrorCondition::k_connection, "Unable to establish connecting path"); |
156 | 157 | } |
157 | 158 |
|
158 | | - std::string address("unix://"); |
159 | | - address += socket_path; |
| 159 | + std::string localhost_prefix("127.0.0.1"); |
| 160 | + auto tcp_check = std::mismatch(localhost_prefix.begin(), localhost_prefix.end(), proxy_path); |
| 161 | + std::string address; |
| 162 | + if (tcp_check.first != localhost_prefix.end()) { |
| 163 | + // proxy path is not a localhost address and is therefore a UDS socket |
| 164 | + address += "unix://"; |
| 165 | + } |
| 166 | + address += proxy_path; |
| 167 | + |
160 | 168 | const std::shared_ptr<grpc::Channel> channel = |
161 | 169 | impl::create_viam_channel(address, grpc::InsecureChannelCredentials()); |
162 | 170 | const std::unique_ptr<viam::robot::v1::RobotService::Stub> st = |
163 | 171 | viam::robot::v1::RobotService::NewStub(channel); |
164 | | - return std::make_shared<ViamChannel>(channel, socket_path, ptr); |
| 172 | + return std::make_shared<ViamChannel>(channel, proxy_path, ptr); |
165 | 173 | }; |
166 | 174 |
|
167 | 175 | unsigned int Options::refresh_interval() const { |
|
0 commit comments