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 29, 2024
1 parent 45d1e99 commit f0f3686
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lqdetect.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void do_lqdetect_write(char *client_ip, char *key,
struct lq_detect_buffer *buffer = &lqdetect.buffer[cmd];
uint32_t offset = buffer->offset;
uint32_t nsaved = buffer->nsaved;
char *bufptr = buffer->data + buffer->offset;
char *bufptr = buffer->data + offset;
uint32_t nwrite, length, keylen = strlen(key);
char keybuf[251];
char *keyptr = key;
Expand All @@ -142,18 +142,13 @@ static void do_lqdetect_write(char *client_ip, char *key,
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;
nwrite = 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]);
buffer->keypos[nsaved] = buffer->offset + nwrite;
buffer->keylen[nsaved] = keylen;
length -= nwrite;
bufptr += nwrite;

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

0 comments on commit f0f3686

Please sign in to comment.