Skip to content

Commit

Permalink
INTERNAL: do_lqdetect_write method simple
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesecrust committed Oct 30, 2024
1 parent 45d1e99 commit c573f16
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions lqdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,8 @@ static void do_lqdetect_write(char *client_ip, char *key,
struct tm *ptm;
struct timeval val;
struct lq_detect_buffer *buffer = &lqdetect.buffer[cmd];
uint32_t offset = buffer->offset;
uint32_t nsaved = buffer->nsaved;
char *bufptr = buffer->data + buffer->offset;
uint32_t nwrite, length, keylen = strlen(key);
uint32_t length, keylen = strlen(key);
char keybuf[251];
char *keyptr = key;

Expand All @@ -140,21 +138,19 @@ static void do_lqdetect_write(char *client_ip, char *key,

gettimeofday(&val, NULL);
ptm = localtime(&val.tv_sec);
length = ((nsaved+1) * LQ_INPUT_SIZE) - offset - 1;

snprintf(bufptr, length, "%02d:%02d:%02d.%06ld %s <%u> %s ",
ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (long)val.tv_usec, client_ip,
arg->overhead, command_str[cmd]);

nwrite = strlen(bufptr);
buffer->keypos[nsaved] = offset + nwrite;
length = ((nsaved+1) * LQ_INPUT_SIZE);

buffer->offset += snprintf(buffer->data + buffer->offset, length - buffer->offset,
"%02d:%02d:%02d.%06ld %s <%u> %s ",
ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (long)val.tv_usec,
client_ip, arg->overhead, command_str[cmd]);
buffer->keypos[nsaved] = (buffer->offset >= length) ? -1 : buffer->offset;
(buffer->offset >= length) ? buffer->offset = length - 1 : 0;
buffer->keylen[nsaved] = keylen;
length -= nwrite;
bufptr += nwrite;

snprintf(bufptr, length, "%s %s\n", keyptr, arg->query);
nwrite += strlen(bufptr);
buffer->offset += nwrite;
buffer->offset += snprintf(buffer->data + buffer->offset, length - buffer->offset,
"%s %s\n", keyptr, arg->query);
(buffer->offset >= length) ? buffer->offset = length - 1 : 0;
lqdetect.arg[cmd][nsaved] = *arg;
buffer->nsaved += 1;
}
Expand Down

0 comments on commit c573f16

Please sign in to comment.