Skip to content

Commit e9d3ea1

Browse files
committed
only prepend unix when using uds
1 parent 418a4c4 commit e9d3ea1

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/viam/sdk/rpc/dial.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <algorithm>
12
#include <viam/sdk/rpc/dial.hpp>
23

34
#include <istream>
@@ -148,20 +149,27 @@ std::shared_ptr<ViamChannel> ViamChannel::dial(const char* uri,
148149
if (opts.entity()) {
149150
entity = opts.entity()->c_str();
150151
}
151-
char* socket_path = ::dial(
152+
char* proxy_path = ::dial(
152153
uri, entity, type, payload, opts.allows_insecure_downgrade(), float_timeout.count(), ptr);
153-
if (socket_path == NULL) {
154+
if (proxy_path == NULL) {
154155
free_rust_runtime(ptr);
155156
throw Exception(ErrorCondition::k_connection, "Unable to establish connecting path");
156157
}
157158

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+
160168
const std::shared_ptr<grpc::Channel> channel =
161169
impl::create_viam_channel(address, grpc::InsecureChannelCredentials());
162170
const std::unique_ptr<viam::robot::v1::RobotService::Stub> st =
163171
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);
165173
};
166174

167175
unsigned int Options::refresh_interval() const {

0 commit comments

Comments
 (0)