nghttpx: Add host_unix field to DownstreamAddr to tell it is UNIX domain sock
This commit is contained in:
parent
0c4ae3dea5
commit
da2376effd
|
@ -1990,14 +1990,14 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
for (auto &addr : mod_config()->downstream_addrs) {
|
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
|
// for AF_UNIX socket, we use "localhost" as host for backend
|
||||||
// hostport. This is used as Host header field to backend and
|
// hostport. This is used as Host header field to backend and
|
||||||
// not going to be passed to any syscalls.
|
// not going to be passed to any syscalls.
|
||||||
addr.hostport =
|
addr.hostport =
|
||||||
strcopy(util::make_hostport("localhost", get_config()->port));
|
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);
|
auto pathlen = strlen(path);
|
||||||
|
|
||||||
if (pathlen + 1 > sizeof(addr.addr.un.sun_path)) {
|
if (pathlen + 1 > sizeof(addr.addr.un.sun_path)) {
|
||||||
|
|
|
@ -523,8 +523,9 @@ int parse_config(const char *opt, const char *optarg) {
|
||||||
if (util::strieq(opt, SHRPX_OPT_BACKEND)) {
|
if (util::strieq(opt, SHRPX_OPT_BACKEND)) {
|
||||||
if (util::istartsWith(optarg, SHRPX_UNIX_PATH_PREFIX)) {
|
if (util::istartsWith(optarg, SHRPX_UNIX_PATH_PREFIX)) {
|
||||||
DownstreamAddr addr;
|
DownstreamAddr addr;
|
||||||
addr.host = strcopy(optarg);
|
auto path = optarg + str_size(SHRPX_UNIX_PATH_PREFIX);
|
||||||
addr.port = 0;
|
addr.host = strcopy(path);
|
||||||
|
addr.host_unix = true;
|
||||||
|
|
||||||
mod_config()->downstream_addrs.push_back(std::move(addr));
|
mod_config()->downstream_addrs.push_back(std::move(addr));
|
||||||
|
|
||||||
|
|
|
@ -164,12 +164,17 @@ struct AltSvc {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DownstreamAddr {
|
struct DownstreamAddr {
|
||||||
DownstreamAddr() : addr{{0}}, addrlen(0), port(0) {}
|
DownstreamAddr() : addr{{0}}, addrlen(0), port(0), host_unix(false) {}
|
||||||
sockaddr_union addr;
|
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[]> host;
|
||||||
std::unique_ptr<char[]> hostport;
|
std::unique_ptr<char[]> hostport;
|
||||||
size_t addrlen;
|
size_t addrlen;
|
||||||
|
// backend port. 0 if |host_unix| is true.
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
|
// true if |host| contains UNIX domain socket path.
|
||||||
|
bool host_unix;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TicketKey {
|
struct TicketKey {
|
||||||
|
|
Loading…
Reference in New Issue