cmdmon: fix handling of client access command
Rework the loop to limit the number of iterations to MAX_CLIENT_ACCESSES and not waste CPU.
This commit is contained in:
parent
a79fbef21e
commit
27f8ad7fd1
1 changed files with 7 additions and 8 deletions
15
cmdmon.c
15
cmdmon.c
|
@ -1463,7 +1463,7 @@ handle_client_accesses_by_index(CMD_Request *rx_message, CMD_Reply *tx_message)
|
||||||
{
|
{
|
||||||
CLG_Status result;
|
CLG_Status result;
|
||||||
RPT_ClientAccessByIndex_Report report;
|
RPT_ClientAccessByIndex_Report report;
|
||||||
unsigned long first_index, n_indices, last_index, n_indices_in_table;
|
unsigned long first_index, n_indices, n_indices_in_table;
|
||||||
int i, j;
|
int i, j;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
|
||||||
|
@ -1471,16 +1471,15 @@ handle_client_accesses_by_index(CMD_Request *rx_message, CMD_Reply *tx_message)
|
||||||
|
|
||||||
first_index = ntohl(rx_message->data.client_accesses_by_index.first_index);
|
first_index = ntohl(rx_message->data.client_accesses_by_index.first_index);
|
||||||
n_indices = ntohl(rx_message->data.client_accesses_by_index.n_indices);
|
n_indices = ntohl(rx_message->data.client_accesses_by_index.n_indices);
|
||||||
last_index = first_index + n_indices - 1;
|
if (n_indices > MAX_CLIENT_ACCESSES)
|
||||||
|
n_indices = MAX_CLIENT_ACCESSES;
|
||||||
|
|
||||||
tx_message->status = htons(STT_SUCCESS);
|
tx_message->status = htons(STT_SUCCESS);
|
||||||
tx_message->reply = htons(RPY_CLIENT_ACCESSES_BY_INDEX);
|
tx_message->reply = htons(RPY_CLIENT_ACCESSES_BY_INDEX);
|
||||||
|
|
||||||
for (i = first_index, j = 0;
|
for (i = 0, j = 0; i < n_indices; i++) {
|
||||||
(i <= last_index) && (j < MAX_CLIENT_ACCESSES);
|
result = CLG_GetClientAccessReportByIndex(first_index + i, &report,
|
||||||
i++) {
|
now.tv_sec, &n_indices_in_table);
|
||||||
|
|
||||||
result = CLG_GetClientAccessReportByIndex(i, &report, now.tv_sec, &n_indices_in_table);
|
|
||||||
tx_message->data.client_accesses_by_index.n_indices = htonl(n_indices_in_table);
|
tx_message->data.client_accesses_by_index.n_indices = htonl(n_indices_in_table);
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
|
@ -1506,7 +1505,7 @@ handle_client_accesses_by_index(CMD_Request *rx_message, CMD_Reply *tx_message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tx_message->data.client_accesses_by_index.next_index = htonl(i);
|
tx_message->data.client_accesses_by_index.next_index = htonl(first_index + i);
|
||||||
tx_message->data.client_accesses_by_index.n_clients = htonl(j);
|
tx_message->data.client_accesses_by_index.n_clients = htonl(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue