diff options
author | Max Kellermann <max@duempel.org> | 2008-08-28 20:20:10 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-09-01 18:35:19 -0700 |
commit | 692cfc5c36ddff07888d1c2e7ecefda8be8ead47 (patch) | |
tree | aa3e80c6b16c60fe38833b386d30ea0b6966176f /src | |
parent | 9e35e50f856038e231e06a5f3d85ff1545053438 (diff) | |
download | mpd-692cfc5c36ddff07888d1c2e7ecefda8be8ead47.tar.gz mpd-692cfc5c36ddff07888d1c2e7ecefda8be8ead47.tar.xz mpd-692cfc5c36ddff07888d1c2e7ecefda8be8ead47.zip |
client: moved code to sockaddr_to_tmp_string()
Unclutter the client_new() constructor by moving unrelated complex
code into a separate function.
Diffstat (limited to 'src')
-rw-r--r-- | src/client.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/client.c b/src/client.c index ba15a90de..f34d64b88 100644 --- a/src/client.c +++ b/src/client.c @@ -258,16 +258,10 @@ static void client_close(struct client *client) free(client); } -void client_new(int fd, const struct sockaddr *addr) +static const char * +sockaddr_to_tmp_string(const struct sockaddr *addr) { const char *hostname; - struct client *client; - - if (num_clients >= client_max_connections) { - ERROR("Max Connections Reached!\n"); - xclose(fd); - return; - } switch (addr->sa_family) { #ifdef HAVE_TCP @@ -303,11 +297,25 @@ void client_new(int fd, const struct sockaddr *addr) hostname = "unknown"; } + return hostname; +} + +void client_new(int fd, const struct sockaddr *addr) +{ + struct client *client; + + if (num_clients >= client_max_connections) { + ERROR("Max Connections Reached!\n"); + xclose(fd); + return; + } + client = xcalloc(1, sizeof(*client)); list_add(&client->siblings, &clients); ++num_clients; client_init(client, fd); - SECURE("client %i: opened from %s\n", client->num, hostname); + SECURE("client %i: opened from %s\n", client->num, + sockaddr_to_tmp_string(addr)); } static int client_process_line(struct client *client) |