fix declaration issue
This commit is contained in:
parent
9a60841a40
commit
38dc4a74bd
26
Makefile
Normal file
26
Makefile
Normal file
@ -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)
|
||||||
BIN
bin/metric_client
Executable file
BIN
bin/metric_client
Executable file
Binary file not shown.
BIN
bin/metric_client_ansi
Executable file
BIN
bin/metric_client_ansi
Executable file
Binary file not shown.
BIN
bin/metric_client_sub
Executable file
BIN
bin/metric_client_sub
Executable file
Binary file not shown.
BIN
bin/metric_client_udp
Executable file
BIN
bin/metric_client_udp
Executable file
Binary file not shown.
BIN
bin/metric_server
Executable file
BIN
bin/metric_server
Executable file
Binary file not shown.
BIN
bin/metric_server_fork
Executable file
BIN
bin/metric_server_fork
Executable file
Binary file not shown.
BIN
bin/metric_server_fork_sub
Executable file
BIN
bin/metric_server_fork_sub
Executable file
Binary file not shown.
BIN
bin/metric_server_udp
Executable file
BIN
bin/metric_server_udp
Executable file
Binary file not shown.
BIN
bin/perf_client_udp
Executable file
BIN
bin/perf_client_udp
Executable file
Binary file not shown.
@ -55,11 +55,10 @@ static void handle_client(int client_sock) {
|
|||||||
unsigned char payload[BUF_SIZE];
|
unsigned char payload[BUF_SIZE];
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
unsigned char type = 0;
|
||||||
|
unsigned short len = 0;
|
||||||
if (recv_exact(client_sock, header, HEADER_SIZE) != HEADER_SIZE) break;
|
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 (len > 0) {
|
||||||
if (recv_exact(client_sock, payload, len) != len) break;
|
if (recv_exact(client_sock, payload, len) != len) break;
|
||||||
}
|
}
|
||||||
@ -67,8 +66,9 @@ static void handle_client(int client_sock) {
|
|||||||
if (type == MSG_PING) {
|
if (type == MSG_PING) {
|
||||||
send_message(client_sock, MSG_PONG, NULL, 0);
|
send_message(client_sock, MSG_PONG, NULL, 0);
|
||||||
} else if (type == MSG_METRIC_REQ) {
|
} else if (type == MSG_METRIC_REQ) {
|
||||||
|
double val;
|
||||||
payload[len] = '\0'; /* null-terminate */
|
payload[len] = '\0'; /* null-terminate */
|
||||||
double val = get_metric((char*)payload);
|
val = get_metric((char*)payload);
|
||||||
if (val < 0) {
|
if (val < 0) {
|
||||||
const char *err = "Unknown metric";
|
const char *err = "Unknown metric";
|
||||||
send_message(client_sock, MSG_ERROR, err, strlen(err));
|
send_message(client_sock, MSG_ERROR, err, strlen(err));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user