From 88f8bbd75a8d6d0473e4d6b2ba303eeb1bb8589a Mon Sep 17 00:00:00 2001 From: linomp Date: Sat, 10 Aug 2024 13:39:00 +0200 Subject: [PATCH] bring in C code --- c/msys_server/Makefile | 31 +++++++++++++++++++++++++++++++ c/msys_server/webserver.c | 28 ++++++++++++++++++++++++++++ c/server/Makefile | 31 +++++++++++++++++++++++++++++++ c/server/webserver.c | 12 ++++++++++++ docker-compose.yml | 4 ++-- Dockerfile => go/Dockerfile | 6 +++--- {src => go}/go.mod | 0 {src => go}/go.sum | 0 {src => go}/main.go | 0 {src => go}/oauthdemo.go | 0 {src => go}/server_metrics.go | 0 11 files changed, 107 insertions(+), 5 deletions(-) create mode 100644 c/msys_server/Makefile create mode 100644 c/msys_server/webserver.c create mode 100644 c/server/Makefile create mode 100644 c/server/webserver.c rename Dockerfile => go/Dockerfile (55%) rename {src => go}/go.mod (100%) rename {src => go}/go.sum (100%) rename {src => go}/main.go (100%) rename {src => go}/oauthdemo.go (100%) rename {src => go}/server_metrics.go (100%) diff --git a/c/msys_server/Makefile b/c/msys_server/Makefile new file mode 100644 index 0000000..f2b7e94 --- /dev/null +++ b/c/msys_server/Makefile @@ -0,0 +1,31 @@ +# Define the compiler +CC = gcc + +# Define the flags +CFLAGS = -Wall -Wextra + +# Define the library flags +LDFLAGS = -lws2_32 + +# Define the target executable +TARGET = server + +# Define the source file +SRC = webserver.c + +# Default target +all: $(TARGET) + +# Build step +$(TARGET): $(SRC) + $(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS) + +# Run the server +run: $(TARGET) + ./$(TARGET) + +# Clean step to remove the executable +clean: + rm -f $(TARGET) + +.PHONY: all run clean diff --git a/c/msys_server/webserver.c b/c/msys_server/webserver.c new file mode 100644 index 0000000..3482e86 --- /dev/null +++ b/c/msys_server/webserver.c @@ -0,0 +1,28 @@ +#include + +#ifdef _WIN32 +#include +#include +#pragma comment(lib, "ws2_32.lib") +#else +#include +#include +#include +#endif + +int main() { +#ifdef _WIN32 + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) { + fprintf(stderr, "WSAStartup failed.\n"); + return 1; + } +#endif + + printf("hello world"); + +#ifdef _WIN32 + WSACleanup(); +#endif + return 0; +} diff --git a/c/server/Makefile b/c/server/Makefile new file mode 100644 index 0000000..69da7b6 --- /dev/null +++ b/c/server/Makefile @@ -0,0 +1,31 @@ +# Define the compiler +CC = gcc + +# Define the flags +CFLAGS = -Wall -Wextra + +# Define the library flags +LDFLAGS = + +# Define the target executable +TARGET = server + +# Define the source file +SRC = webserver.c + +# Default target +all: $(TARGET) + +# Build step +$(TARGET): $(SRC) + $(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS) + +# Run the server +run: $(TARGET) + ./$(TARGET) + +# Clean step to remove the executable +clean: + rm -f $(TARGET) + +.PHONY: all run clean diff --git a/c/server/webserver.c b/c/server/webserver.c new file mode 100644 index 0000000..f9adfc4 --- /dev/null +++ b/c/server/webserver.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include +#include +#include + +// maximum application buffer +#define APP_MAX_BUFFER 1024 +#define PORT 8080 + +int main() { return 0; } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 135c799..dcaa8c2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,9 @@ version: '3.8' services: - server: + go-server: build: - context: . + context: ./go dockerfile: Dockerfile ports: - "8001:8001" diff --git a/Dockerfile b/go/Dockerfile similarity index 55% rename from Dockerfile rename to go/Dockerfile index 0dadef2..b92e2ad 100644 --- a/Dockerfile +++ b/go/Dockerfile @@ -1,11 +1,11 @@ FROM golang:bookworm -WORKDIR /app +WORKDIR /go_server -COPY ./src /app +COPY . /go_server RUN go mod tidy RUN go build -o main -CMD ["./main"] +CMD ["./main"] \ No newline at end of file diff --git a/src/go.mod b/go/go.mod similarity index 100% rename from src/go.mod rename to go/go.mod diff --git a/src/go.sum b/go/go.sum similarity index 100% rename from src/go.sum rename to go/go.sum diff --git a/src/main.go b/go/main.go similarity index 100% rename from src/main.go rename to go/main.go diff --git a/src/oauthdemo.go b/go/oauthdemo.go similarity index 100% rename from src/oauthdemo.go rename to go/oauthdemo.go diff --git a/src/server_metrics.go b/go/server_metrics.go similarity index 100% rename from src/server_metrics.go rename to go/server_metrics.go