# HG changeset patch # User Timo Sirainen # Date 1511692413 -7200 # Node ID e024078c62c987bb196c0f9b127a12a909e08af7 # Parent 7347dab76be08d474c2c4934cf90a10d340d6681 director: DIRECTOR-LIST - Return results sorted by host diff -r 7347dab76be0 -r e024078c62c9 src/director/doveadm-connection.c --- a/src/director/doveadm-connection.c Sun Nov 26 12:26:27 2017 +0200 +++ b/src/director/doveadm-connection.c Sun Nov 26 12:33:33 2017 +0200 @@ -263,28 +263,31 @@ t_array_init(&hosts, array_count(&dir->dir_hosts)); array_append_array(&hosts, &dir->dir_hosts); - - /* show each individual connection */ - array_foreach(&dir->connections, connp) { - const struct director_host *host = - director_connection_get_host(*connp); - /* NOTE: for incoming connections host is initially NULL */ + array_sort(&hosts, director_host_cmp_p); - array_foreach(&hosts, hostp) { - if (*hostp == host) { - array_delete(&hosts, - array_foreach_idx(&hosts, hostp), 1); - break; - } - } - doveadm_director_connection_append(dir, *connp, host, str); + /* first show incoming connections that have no known host yet */ + array_foreach(&dir->connections, connp) { + if (director_connection_get_host(*connp) == NULL) + doveadm_director_connection_append(dir, *connp, NULL, str); } - /* show the rest of the hosts that don't have any connections */ + /* show other connections and host without connections sorted by host */ array_foreach(&hosts, hostp) { const struct director_host *host = *hostp; - doveadm_director_host_append(dir, host, str); + bool have_connections = FALSE; + + array_foreach(&dir->connections, connp) { + const struct director_host *conn_host = + director_connection_get_host(*connp); + if (conn_host != host) + continue; + have_connections = TRUE; + doveadm_director_connection_append(dir, *connp, host, str); + } + if (!have_connections) + doveadm_director_host_append(dir, host, str); } + str_append_c(str, '\n'); o_stream_nsend(conn->output, str_data(str), str_len(str)); return DOVEADM_DIRECTOR_CMD_RET_OK;