Skip to content

Commit

Permalink
Split ipv4 and ipv6 listening code out
Browse files Browse the repository at this point in the history
In case one of the protocols is disabled allow the daemon to continue
as long as one works.

Bug: 1663125
Change-Id: Id5fc8b96fe09bf5d4bd6f87d3f1469e9a6fb3d5c
  • Loading branch information
p3ck committed Jan 9, 2019
1 parent e7a1680 commit c62e8c8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ int main(int argc, char *argv[]) {
app_data->cancellable = g_cancellable_new ();
app_data->aborted = ABORTED_NONE;
gint port = 8081;
gint ipv6_enabled = FALSE;
gint ipv4_enabled = FALSE;
app_data->config_file = NULL;
gchar *config_port = g_strdup("config.conf");
SoupServer *soup_server = NULL;
Expand Down Expand Up @@ -633,8 +635,16 @@ int main(int argc, char *argv[]) {

// Tell our soup server to listen on any interface
// This includes ipv4 and ipv6 if available.
if (! soup_server_listen_local (soup_server, port, 0, NULL)) {
g_printerr ("Unable to bind to server port %d\n", port);
ipv6_enabled = soup_server_listen_local( soup_server, port, SOUP_SERVER_LISTEN_IPV6_ONLY, NULL);
ipv4_enabled = soup_server_listen_local( soup_server, port, SOUP_SERVER_LISTEN_IPV4_ONLY, NULL);
if (ipv6_enabled) {
g_print ("Server listening on port %d for ipV6\n", port);
}
if (ipv4_enabled) {
g_print ("Server listening on port %d for ipV4\n", port);
}
if (!ipv4_enabled && !ipv6_enabled) {
g_printerr ("Unable to listen on either ipV4 or ipV6 protocols, exiting...\n");
exit (1);
}

Expand Down

0 comments on commit c62e8c8

Please sign in to comment.