Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client_command_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void cmd_ping(const command_args_t args, void (*response_cb)(client_t *client))
{
if (!strcasecmp(args.cmd, "PING")) {
size_t cmd_len;
char *value = NULL;
const char *value = NULL;
// TODO: I'm not happy with this solution, refactor this in future and
// handle edge cases, when value has a space
// in the middle, e.g, PING "hello world"
Expand Down Expand Up @@ -155,9 +155,9 @@ void cmd_ping(const command_args_t args, void (*response_cb)(client_t *client))
void cmd_unknown(const command_args_t args,
void (*response_cb)(client_t *client))
{
if (strcasecmp(args.cmd, "INCR") &&
strcasecmp(args.cmd, "INCRBY") & strcasecmp(args.cmd, "GET") &
strcasecmp(args.cmd, "SET") & strcasecmp(args.cmd, "PING")) {
if (strcasecmp(args.cmd, "INCR") && strcasecmp(args.cmd, "INCRBY") &&
strcasecmp(args.cmd, "GET") && strcasecmp(args.cmd, "SET") &&
strcasecmp(args.cmd, "PING")) {
printf("Unknown command \n");
}
}
Expand Down
2 changes: 1 addition & 1 deletion command_registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void send_reply(const int client_fd, const unsigned char *buffer,
const size_t core_cmd_len = bytes_read + 3;
const size_t full_frame_length = core_cmd_len + 2;

unsigned char *reply = malloc(core_cmd_len);
unsigned char *reply = malloc(full_frame_length);

reply[0] = (core_cmd_len >> 8) & 0xFF;
reply[1] = core_cmd_len & 0xFF;
Expand Down
1 change: 0 additions & 1 deletion event_dispatcher_epoll.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#if defined(__linux__)

#include "client.h"
#include "command_registry.h"
#include "event_dispatcher.h"
#include "list.h"
#include "networking.h"
Expand Down
2 changes: 0 additions & 2 deletions event_dispatcher_kqueue.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#ifdef __APPLE__

#include "client.h"
#include "command_registry.h"
#include "event_dispatcher.h"
#include "list.h"
#include "networking.h"
#include "server.h"
#include "utils.h"
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
Expand Down
2 changes: 1 addition & 1 deletion networking.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void try_process_frames(client_t *c)
{
// Parse as many complete frames as possible.
if (server.verbose) {
printf("Attempting to process frames");
printf("Attempting to process frame \n");
}
for (;;) {
if (c->buf_used < 2)
Expand Down
2 changes: 1 addition & 1 deletion server_command_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void handle_set_command(int client_fd, unsigned char *buffer, size_t bytes_read)

set_value(table, &buffer[pos_key], key_len, &buffer[pos_value], value_len);

send_reply(client_fd, buffer, value_len);
send_reply(client_fd, &buffer[pos_value], value_len);
free(data);
}

Expand Down
26 changes: 13 additions & 13 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ static void warn(const char *ctx, const char *file, int line)
perror(ctx);
}

static void print_binary_data(const unsigned char *data, const size_t len)
{
for (size_t j = 0; j < len; j++) {
const unsigned char c = data[j];
if (c >= 32 && c <= 126) {
putchar(c); // printable ASCII
} else {
printf("\\x%02x", c); // escape non-printable
}
}
putchar('\n');
}

#ifdef SERVER

// TODO: When process is running as a daemon, ensure we don't print to standard
Expand All @@ -45,19 +58,6 @@ static void _log(char *ctx)
server.daemonize ? append_to_log_file(ctx) : log_std_out(ctx);
}

static void print_binary_data(const unsigned char *data, const size_t len)
{
for (size_t j = 0; j < len; j++) {
const unsigned char c = data[j];
if (c >= 32 && c <= 126) {
putchar(c); // printable ASCII
} else {
printf("\\x%02x", c); // escape non-printable
}
}
putchar('\n');
}

static bool is_integer(const unsigned char *str, const size_t len)
{
if (len == 0) {
Expand Down