aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-10 11:42:26 +0200
committerMax Kellermann <max@duempel.org>2008-09-10 11:42:26 +0200
commit48191d5661d1fa312f4e1e44569223ceb7bba596 (patch)
tree66fa35f87369130771daffdd940180835c595e55
parenta580f5fe688e7f987d3cf6ee21f27faed2557b01 (diff)
downloadmpd-48191d5661d1fa312f4e1e44569223ceb7bba596.tar.gz
mpd-48191d5661d1fa312f4e1e44569223ceb7bba596.tar.xz
mpd-48191d5661d1fa312f4e1e44569223ceb7bba596.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.
-rw-r--r--src/client.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/src/client.c b/src/client.c
index 5637c5d82..2ec39dca1 100644
--- a/src/client.c
+++ b/src/client.c
@@ -343,10 +343,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)
command_success(client);
@@ -368,8 +366,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)
command_success(client);
@@ -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;
@@ -532,10 +525,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) &&