From f18ceea9bfad7579e1eec33f6c9654cc71e062b1 Mon Sep 17 00:00:00 2001 From: Unbit Date: Sat, 4 Jan 2014 10:12:03 +0100 Subject: [PATCH] fixed resubscription when different sockets type are in place --- core/subscription.c | 30 ++++++++++++++++++++++++++++-- plugins/corerouter/cr_common.c | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/core/subscription.c b/core/subscription.c index 77c4e28b..b017173c 100644 --- a/core/subscription.c +++ b/core/subscription.c @@ -601,7 +601,7 @@ static void send_subscription(int sfd, char *host, char *message, uint16_t messa char *udp_port = strchr(host, ':'); - if (fd < 0) { + if (fd == -1) { if (udp_port) { fd = socket(AF_INET, SOCK_DGRAM, 0); } @@ -614,6 +614,32 @@ static void send_subscription(int sfd, char *host, char *message, uint16_t messa } uwsgi_socket_nb(fd); } + else if (fd == -2) { + static int unix_fd = -1; + static int inet_fd = -1; + if (udp_port) { + if (inet_fd == -1) { + inet_fd = socket(AF_INET, SOCK_DGRAM, 0); + if (inet_fd < 0) { + uwsgi_error("send_subscription()/socket()"); + return; + } + uwsgi_socket_nb(inet_fd); + } + fd = inet_fd; + } + else { + if (unix_fd == -1) { + unix_fd = socket(AF_UNIX, SOCK_DGRAM, 0); + if (unix_fd < 0) { + uwsgi_error("send_subscription()/socket()"); + return; + } + uwsgi_socket_nb(unix_fd); + } + fd = unix_fd; + } + } if (udp_port) { udp_port[0] = 0; @@ -642,7 +668,7 @@ static void send_subscription(int sfd, char *host, char *message, uint16_t messa uwsgi_error("send_subscription()/sendto()"); } - if (sfd < 0) + if (sfd == -1) close(fd); } diff --git a/plugins/corerouter/cr_common.c b/plugins/corerouter/cr_common.c index 590a89da..c5762fd1 100644 --- a/plugins/corerouter/cr_common.c +++ b/plugins/corerouter/cr_common.c @@ -217,7 +217,7 @@ void uwsgi_corerouter_manage_subscription(struct uwsgi_corerouter *ucr, int id, sni_ca = uwsgi_concat2n(usr.sni_ca, usr.sni_ca_len, "", 0); } uwsgi_foreach(usl, ucr->resubscribe) { - uwsgi_send_subscription_from_fd(ugs->fd, usl->value, usr.key, usr.keylen, usr.modifier1, usr.modifier2, bbuf[3], address, NULL, sni_key, sni_cert, sni_ca); + uwsgi_send_subscription_from_fd(-2, usl->value, usr.key, usr.keylen, usr.modifier1, usr.modifier2, bbuf[3], address, NULL, sni_key, sni_cert, sni_ca); } if (sni_key) free(sni_key); if (sni_cert) free(sni_cert);