Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for unix sockets #244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/c++/library/http_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,20 @@ InferenceServerHttpClient::Create(

InferenceServerHttpClient::InferenceServerHttpClient(
const std::string& url, bool verbose, const HttpSslOptions& ssl_options)
: InferenceServerClient(verbose), url_(url), ssl_options_(ssl_options),
: InferenceServerClient(verbose), ssl_options_(ssl_options),
easy_handle_(reinterpret_cast<void*>(curl_easy_init())),
multi_handle_(curl_multi_init())
{
std::string unix_socket_prefix("unix://");

if (strncmp(url.c_str(), unix_socket_prefix.c_str(), unix_socket_prefix.length()) == 0) {
// Unix domain socket
unix_socket_ = url.substr(unix_socket_prefix.length());
url_ = "http://localhost";
} else {
// TCP socket
url_ = url;
}
}

InferenceServerHttpClient::~InferenceServerHttpClient()
Expand Down Expand Up @@ -1796,7 +1806,12 @@ InferenceServerHttpClient::PreRunProcessing(
curl_easy_setopt(curl, CURLOPT_URL, request_uri.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L);

if (unix_socket_.empty()) {
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L);
} else {
curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, unix_socket_.c_str());
}

if (options.client_timeout_ != 0) {
uint64_t timeout_ms = (options.client_timeout_ / 1000);
Expand Down Expand Up @@ -2018,7 +2033,13 @@ InferenceServerHttpClient::Get(

curl_easy_setopt(curl, CURLOPT_URL, request_uri.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L);

if (unix_socket_.empty()) {
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L);
} else {
curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, unix_socket_.c_str());
}

if (verbose_) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
}
Expand Down Expand Up @@ -2094,9 +2115,15 @@ InferenceServerHttpClient::Post(

curl_easy_setopt(curl, CURLOPT_URL, request_uri.c_str());
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, request.size());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request.c_str());

if (unix_socket_.empty()) {
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1L);
} else {
curl_easy_setopt(curl, CURLOPT_UNIX_SOCKET_PATH, unix_socket_.c_str());
}

if (verbose_) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
}
Expand Down
4 changes: 3 additions & 1 deletion src/c++/library/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ class InferenceServerHttpClient : public InferenceServerClient {
void* contents, size_t size, size_t nmemb, void* userp);

// The server url
const std::string url_;
std::string url_;
// The server unix socket
std::string unix_socket_;
// The options for authorizing and authenticating SSL/TLS connections
HttpSslOptions ssl_options_;

Expand Down