aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-10 11:42:26 +0200
committerEric Wong <normalperson@yhbt.net>2008-09-10 23:34:54 -0700
commit70199776b4c925268105df7998905ee36c79846b (patch)
treea242cf198c0d0b74ca7c98be03d763c0ed8bde94 /src
parent6452dab44c6a170d8081b1a15223fb28ea9ab230 (diff)
downloadmpd-70199776b4c925268105df7998905ee36c79846b.tar.gz
mpd-70199776b4c925268105df7998905ee36c79846b.tar.xz
mpd-70199776b4c925268105df7998905ee36c79846b.zip
client: check for COMMAND_RETURN_CLOSE
Don't close the client within client_process_line(), return COMMAND_RETURN_CLOSE instead. This is the signal for the caller chain to actually close it. This makes dealing with the client pointer a lot safer, since the caller always knows whether it is still valid.
Diffstat (limited to '')
-rw-r--r--src/client.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/client.c b/src/client.c
index 9b70116bd..03e9ad0dc 100644
--- a/src/client.c
+++ b/src/client.c
@@ -342,10 +342,8 @@ static int client_process_line(struct client *client)
"list returned %i\n", client->num, ret);
if (ret == COMMAND_RETURN_CLOSE ||
- client_is_expired(client)) {
- client_close(client);
+ client_is_expired(client))
return COMMAND_RETURN_CLOSE;
- }
if (ret == 0)
commandSuccess(client->fd);
@@ -367,8 +365,7 @@ static int client_process_line(struct client *client)
(unsigned long)client->cmd_list_size,
(unsigned long)
client_max_command_list_size);
- client_close(client);
- ret = COMMAND_RETURN_CLOSE;
+ return COMMAND_RETURN_CLOSE;
} else
new_cmd_list_ptr(client, line, len);
}
@@ -388,10 +385,8 @@ static int client_process_line(struct client *client)
client->num, ret);
if (ret == COMMAND_RETURN_CLOSE ||
- client_is_expired(client)) {
- client_close(client);
+ client_is_expired(client))
return COMMAND_RETURN_CLOSE;
- }
if (ret == 0)
commandSuccess(client->fd);
@@ -422,16 +417,14 @@ static int client_input_received(struct client *client, int bytesRead)
if (ret == COMMAND_RETURN_KILL ||
ret == COMMAND_RETURN_CLOSE)
return ret;
- if (client_is_expired(client))
- return ret;
+ assert(!client_is_expired(client));
client->bufferPos = client->bufferLength;
}
if (client->bufferLength == CLIENT_MAX_BUFFER_LENGTH) {
if (client->bufferPos == 0) {
ERROR("client %i: buffer overflow\n",
client->num);
- client_close(client);
- return 1;
+ return COMMAND_RETURN_CLOSE;
}
if (client->cmd_list_OK >= 0 &&
client->cmd_list &&
@@ -461,7 +454,7 @@ static int client_read(struct client *client)
if (bytesRead > 0)
return client_input_received(client, bytesRead);
else if (bytesRead == 0 || (bytesRead < 0 && errno != EINTR)) {
- client_close(client);
+ return COMMAND_RETURN_CLOSE;
} else
return 0;
@@ -530,10 +523,16 @@ int client_manager_io(void)
list_for_each_entry_safe(client, n, &clients, siblings) {
if (FD_ISSET(client->fd, &rfds)) {
- if (COMMAND_RETURN_KILL ==
- client_read(client)) {
+ ret = client_read(client);
+ if (ret == COMMAND_RETURN_KILL)
return COMMAND_RETURN_KILL;
+ if (ret == COMMAND_RETURN_CLOSE) {
+ client_close(client);
+ continue;
}
+
+ assert(!client_is_expired(client));
+
client->lastTime = time(NULL);
}
if (!client_is_expired(client) &&