diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..83fdf89 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +# Makefile for strict C89/C90 compatibility +# Compiles all samples in src/c90/ with -std=c90 -pedantic -Wall -Wextra -Werror + +.PHONY: all clean + +CC := gcc +CFLAGS := -std=c90 -pedantic -Wall -Wextra -Werror +SRCDIR := src/c90 +BINDIR := bin +SOURCES := $(wildcard $(SRCDIR)/*.c) +BINS := $(SOURCES:$(SRCDIR)/%.c=$(BINDIR)/%) + +all: $(BINS) + +$(BINDIR)/%: $(SRCDIR)/%.c | $(BINDIR) + $(CC) $(CFLAGS) -o $@ $< + +$(BINDIR): + mkdir -p $(BINDIR) + +clean: + rm -rf $(BINDIR) + +print: + @echo "Strict C90 binaries in bin/:" + @ls $(BINDIR) \ No newline at end of file diff --git a/bin/metric_client b/bin/metric_client new file mode 100755 index 0000000..11eb821 Binary files /dev/null and b/bin/metric_client differ diff --git a/bin/metric_client_ansi b/bin/metric_client_ansi new file mode 100755 index 0000000..093ec8d Binary files /dev/null and b/bin/metric_client_ansi differ diff --git a/bin/metric_client_sub b/bin/metric_client_sub new file mode 100755 index 0000000..07c0f25 Binary files /dev/null and b/bin/metric_client_sub differ diff --git a/bin/metric_client_udp b/bin/metric_client_udp new file mode 100755 index 0000000..7f68b94 Binary files /dev/null and b/bin/metric_client_udp differ diff --git a/bin/metric_server b/bin/metric_server new file mode 100755 index 0000000..d89aeb0 Binary files /dev/null and b/bin/metric_server differ diff --git a/bin/metric_server_fork b/bin/metric_server_fork new file mode 100755 index 0000000..e1dce67 Binary files /dev/null and b/bin/metric_server_fork differ diff --git a/bin/metric_server_fork_sub b/bin/metric_server_fork_sub new file mode 100755 index 0000000..a2de00a Binary files /dev/null and b/bin/metric_server_fork_sub differ diff --git a/bin/metric_server_udp b/bin/metric_server_udp new file mode 100755 index 0000000..8784658 Binary files /dev/null and b/bin/metric_server_udp differ diff --git a/bin/perf_client_udp b/bin/perf_client_udp new file mode 100755 index 0000000..8c1496c Binary files /dev/null and b/bin/perf_client_udp differ diff --git a/src/c90/metric_server.c b/src/c90/metric_server.c index 0cbb457..565bc5e 100644 --- a/src/c90/metric_server.c +++ b/src/c90/metric_server.c @@ -55,11 +55,10 @@ static void handle_client(int client_sock) { unsigned char payload[BUF_SIZE]; while (1) { + unsigned char type = 0; + unsigned short len = 0; if (recv_exact(client_sock, header, HEADER_SIZE) != HEADER_SIZE) break; - unsigned char type = header[0]; - unsigned short len = (header[1] << 8) | header[2]; - if (len > 0) { if (recv_exact(client_sock, payload, len) != len) break; } @@ -67,8 +66,9 @@ static void handle_client(int client_sock) { if (type == MSG_PING) { send_message(client_sock, MSG_PONG, NULL, 0); } else if (type == MSG_METRIC_REQ) { + double val; payload[len] = '\0'; /* null-terminate */ - double val = get_metric((char*)payload); + val = get_metric((char*)payload); if (val < 0) { const char *err = "Unknown metric"; send_message(client_sock, MSG_ERROR, err, strlen(err));