aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-28 20:20:10 +0200
committerEric Wong <normalperson@yhbt.net>2008-09-01 18:35:19 -0700
commit9567f849e514940da6c2c6da52dde932b7b2fb48 (patch)
tree89c2827177a63ea5abea1916677472a0f4de9f29
parent827d346899cf0d0d95f8320660944c8f38488b57 (diff)
downloadmpd-9567f849e514940da6c2c6da52dde932b7b2fb48.tar.gz
mpd-9567f849e514940da6c2c6da52dde932b7b2fb48.tar.xz
mpd-9567f849e514940da6c2c6da52dde932b7b2fb48.zip
client: moved "expired" accesses into inline function
Hiding this flag allows us later to remove it easily.
-rw-r--r--src/client.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/client.c b/src/client.c
index f03dd407b..f1e3685c0 100644
--- a/src/client.c
+++ b/src/client.c
@@ -131,6 +131,16 @@ static void set_send_buf_size(struct client *client)
}
}
+static inline int client_is_expired(const struct client *client)
+{
+ return client->expired;
+}
+
+static inline void client_set_expired(struct client *client)
+{
+ client->expired = 1;
+}
+
static void client_init(struct client *client, int fd)
{
static unsigned int next_client_num;
@@ -307,19 +317,25 @@ static int client_process_line(struct client *client)
if (client->cmd_list_OK >= 0) {
if (strcmp(line, CLIENT_LIST_MODE_END) == 0) {
+ int expired;
+
DEBUG("client %i: process command "
"list\n", client->num);
ret = processListOfCommands(client->fd,
&(client->permission),
- &(client->expired),
+ &(expired),
client->cmd_list_OK,
client->cmd_list);
DEBUG("client %i: process command "
"list returned %i\n", client->num, ret);
+
+ if (expired)
+ client_set_expired(client);
+
if (ret == 0)
commandSuccess(client->fd);
else if (ret == COMMAND_RETURN_CLOSE
- || client->expired)
+ || client_is_expired(client))
client_close(client);
client_write_output(client);
@@ -361,7 +377,7 @@ static int client_process_line(struct client *client)
if (ret == 0)
commandSuccess(client->fd);
else if (ret == COMMAND_RETURN_CLOSE
- || client->expired) {
+ || client_is_expired(client)) {
client_close(client);
}
client_write_output(client);
@@ -387,7 +403,7 @@ static int client_input_received(struct client *client, int bytesRead)
*(buf_tail - 1) = '\0';
}
ret = client_process_line(client);
- if (client->expired)
+ if (client_is_expired(client))
return ret;
client->bufferPos = client->bufferLength;
}
@@ -445,7 +461,7 @@ static void client_manager_register_read_fd(fd_set * fds, int *fdmax)
addListenSocketsToFdSet(fds, fdmax);
list_for_each_entry(client, &clients, siblings) {
- if (!client->expired && !client->deferred_send) {
+ if (!client_is_expired(client) && !client->deferred_send) {
FD_SET(client->fd, fds);
if (*fdmax < client->fd)
*fdmax = client->fd;
@@ -460,7 +476,7 @@ static void client_manager_register_write_fd(fd_set * fds, int *fdmax)
FD_ZERO(fds);
list_for_each_entry(client, &clients, siblings) {
- if (client->fd >= 0 && !client->expired
+ if (client->fd >= 0 && !client_is_expired(client)
&& client->deferred_send) {
FD_SET(client->fd, fds);
if (*fdmax < client->fd)
@@ -590,7 +606,7 @@ void client_manager_expire(void)
struct client *client, *n;
list_for_each_entry_safe(client, n, &clients, siblings) {
- if (client->expired) {
+ if (client_is_expired(client)) {
DEBUG("client %i: expired\n", client->num);
client_close(client);
} else if (time(NULL) - client->lastTime >
@@ -637,7 +653,7 @@ static void client_write_deferred(struct client *client)
/* cause client to close */
DEBUG("client %i: problems flushing buffer\n",
client->num);
- client->expired = 1;
+ client_set_expired(client);
}
}
@@ -664,10 +680,10 @@ int client_print(int fd, const char *buffer, size_t buflen)
return -1;
/* if fd isn't found or client is going to be closed, do nothing */
- if (client->expired)
+ if (client_is_expired(client))
return 0;
- while (buflen > 0 && !client->expired) {
+ while (buflen > 0 && !client_is_expired(client)) {
size_t left;
assert(client->send_buf_size >= client->send_buf_used);
@@ -701,7 +717,7 @@ static void client_defer_output(struct client *client,
(unsigned long)client->deferred_bytes,
(unsigned long)client_max_output_buffer_size);
/* cause client to close */
- client->expired = 1;
+ client_set_expired(client);
return;
}
@@ -723,7 +739,7 @@ static void client_write(struct client *client,
client_defer_output(client, data, length);
} else {
DEBUG("client %i: problems writing\n", client->num);
- client->expired = 1;
+ client_set_expired(client);
return;
}
} else if ((size_t)ret < client->send_buf_used) {
@@ -736,7 +752,7 @@ static void client_write(struct client *client,
static void client_write_output(struct client *client)
{
- if (client->expired || !client->send_buf_used)
+ if (client_is_expired(client) || !client->send_buf_used)
return;
if (client->deferred_send != NULL)