Skip to content

Commit

Permalink
bring in C code
Browse files Browse the repository at this point in the history
  • Loading branch information
linomp committed Aug 10, 2024
1 parent c95e9d7 commit 88f8bbd
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 5 deletions.
31 changes: 31 additions & 0 deletions c/msys_server/Makefile
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions c/msys_server/webserver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdio.h>

#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#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;
}
31 changes: 31 additions & 0 deletions c/server/Makefile
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions c/server/webserver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>

// maximum application buffer
#define APP_MAX_BUFFER 1024
#define PORT 8080

int main() { return 0; }
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
version: '3.8'

services:
server:
go-server:
build:
context: .
context: ./go
dockerfile: Dockerfile
ports:
- "8001:8001"
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile → go/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 88f8bbd

Please sign in to comment.