Implement Server #1

Merged
eburk merged 8 commits from tcpsrv into master 2024-07-09 21:03:23 +00:00
4 changed files with 9 additions and 50 deletions
Showing only changes of commit 0ac251279a - Show all commits

View File

@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.17)
project(flint C) project(flint C)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if ((${CMAKE_SYSTEM_NAME} STREQUAL "Linux"))
add_compile_definitions(flint __USE_XOPEN_EXTENDED)
endif()
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
include_directories(include) include_directories(include)
@ -21,7 +25,7 @@ set(SOURCES
) )
if ((${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")) if ((${CMAKE_SYSTEM_NAME} STREQUAL "Darwin"))
add_library(flint ${SOURCES} src/macos/macos.c) add_library(flint ${SOURCES} src/macos.c)
else() else()
add_library(flint ${SOURCES}) add_library(flint ${SOURCES})
endif() endif()

View File

@ -1,49 +0,0 @@
.PHONY : clean tests all manual
CFLAGS = -std=c99 -Iinclude -pedantic
WARNINGS= -Wall -Wextra
LDFLAGS = -fPIC -shared
MACROS= -D_POSIX_C_SOURCE=1
TARGET = libflint.so
SRC != ls src/*.c
OBJ = $(SRC:./src/$.c=./obj/%.o)
PREFIX = $(DESTDIR)/usr/local
LIBDIR = $(PREFIX)/lib
OS_NAME != uname -s | tr A-Z a-z
all: $(TARGET)
./clanggen.sh
$(TARGET): $(OBJ)
ifeq ($(OS_NAME),"openbsd")
@echo "Building for openbsd"
endif
cc $(CFLAGS) $(WARNINGS) $(LDFLAGS) -o $(TARGET) $(OBJ)
./obj/%.o: ./src/%.c
cc $(CFLAGS) -c $< -o $@
install: $(TARGET)
cp $(TARGET) $(LIBDIR)
uninstall:
rm -f $(LIBDIR)/$(TARGET)
clean:
rm -f $(TARGET)
rm -f testrunner
rm -f tcptest
rm -f netmanual
rm -f compile_commands.json
tests:
cc $(CFLAGS) -o testrunner tests/tests.c src/*.c
cc $(CFLAGS) -o tcptest tests/tcptest.c src/*.c
./run_tests.sh
manual:
cc $(CFLAGS) -o netmanual tests/netmanual.c src/*.c

View File

@ -92,6 +92,9 @@ int serve(Server *s, int backlog_size) {
return 1; return 1;
} }
// Linux doesn't handle SA_RESTART properly, and I don't know about Windows (nor do I care)
// This is just for macOS and BSDs
#if !defined(__linux__) && !defined(_WIN32)
struct sigaction sa; struct sigaction sa;
sa.sa_handler = sighandler; sa.sa_handler = sighandler;
sa.sa_flags = SA_RESTART; sa.sa_flags = SA_RESTART;
@ -99,6 +102,7 @@ int serve(Server *s, int backlog_size) {
fprintf(stderr, "Failed to set sigaction\n"); fprintf(stderr, "Failed to set sigaction\n");
return 1; return 1;
} }
#endif
s->handler(s); s->handler(s);