nghttpx: Add host_unix field to DownstreamAddr to tell it is UNIX domain sock

This commit is contained in:
Tatsuhiro Tsujikawa 2015-02-22 17:12:00 +09:00
parent 0c4ae3dea5
commit da2376effd
3 changed files with 11 additions and 5 deletions

View File

@ -1990,14 +1990,14 @@ int main(int argc, char **argv) {
for (auto &addr : mod_config()->downstream_addrs) {
if (util::istartsWith(addr.host.get(), SHRPX_UNIX_PATH_PREFIX)) {
if (addr.host_unix) {
// for AF_UNIX socket, we use "localhost" as host for backend
// hostport. This is used as Host header field to backend and
// not going to be passed to any syscalls.
addr.hostport =
strcopy(util::make_hostport("localhost", get_config()->port));
auto path = addr.host.get() + str_size(SHRPX_UNIX_PATH_PREFIX);
auto path = addr.host.get();
auto pathlen = strlen(path);
if (pathlen + 1 > sizeof(addr.addr.un.sun_path)) {

View File

@ -523,8 +523,9 @@ int parse_config(const char *opt, const char *optarg) {
if (util::strieq(opt, SHRPX_OPT_BACKEND)) {
if (util::istartsWith(optarg, SHRPX_UNIX_PATH_PREFIX)) {
DownstreamAddr addr;
addr.host = strcopy(optarg);
addr.port = 0;
auto path = optarg + str_size(SHRPX_UNIX_PATH_PREFIX);
addr.host = strcopy(path);
addr.host_unix = true;
mod_config()->downstream_addrs.push_back(std::move(addr));

View File

@ -164,12 +164,17 @@ struct AltSvc {
};
struct DownstreamAddr {
DownstreamAddr() : addr{{0}}, addrlen(0), port(0) {}
DownstreamAddr() : addr{{0}}, addrlen(0), port(0), host_unix(false) {}
sockaddr_union addr;
// backend address. If |host_unix| is true, this is UNIX domain
// socket path.
std::unique_ptr<char[]> host;
std::unique_ptr<char[]> hostport;
size_t addrlen;
// backend port. 0 if |host_unix| is true.
uint16_t port;
// true if |host| contains UNIX domain socket path.
bool host_unix;
};
struct TicketKey {