-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Support for unix sockets #721
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
Comments
@nqle, thanks for the question. I am using this library for HTTP support in my projects. I don't have any plan to support Unix socket because the projects don't need it. Hope it helps! |
@nqle If you still need it, I hacked something together (quick & dirty) for my own spare time project (communicating with docker sockets): In std::string hostName = host;
int sock = INVALID_SOCKET;
if (hostName.size() > 5 && hostName.substr(0, 5) == "unix:") {
sock = socket(AF_UNIX, SOCK_STREAM, 0);
sockaddr_un addr{};
addr.sun_family = AF_UNIX;
strncpy(
addr.sun_path,
hostName.substr(5, hostName.size() - 5).c_str(),
std::min(sizeof(addr.sun_path) - 1, hostName.size() - 5)
);
addrinfo info{};
info.ai_addr = (sockaddr *)&addr;
info.ai_addrlen = sizeof(addr);
info.ai_next = nullptr;
info.ai_socktype = SOCK_STREAM;
info.ai_family = AF_UNIX;
info.ai_canonname = nullptr;
info.ai_protocol = 0;
if (bind_or_connect(sock, info)) {
return sock;
}
return INVALID_SOCKET;
} Also, include Then you can run httplib::Client client("unix:/var/run/docker.sock");
client.set_default_headers({ { "Host", "localhost" } });
auto response = client.Get("/v1.24/containers/json"); for example to talk to the local docker socket. Maybe it helps! |
Thanks for your effort! I might use it at some point. |
Hey,
I didn't know where else to ask.
I was curious about whether there are future plans to support unix domain sockets for local interprocess communication or is this project rather focused on web applications and tcp sockets?
The text was updated successfully, but these errors were encountered: