cocoon/Makefile
xfy911 0dc2bb5b4e feat(server): 连接空闲超时 + 最大并发限制 + 分级日志
- 新增 log.c/log.h 分级日志系统(error/warn/info/debug)
- 新增连接空闲超时管理:使用 coco_timer + shutdown + coco_cancel
  自动清理长时间无数据的僵尸连接,默认 30 秒
- 新增最大并发连接数限制(-m <num>),超限返回 503
- 命令行新增选项:-m 最大连接数, -o 超时毫秒, -l 日志级别
- 替换所有 printf 为 log_info/log_error/log_debug 等分级输出
- 编译通过,单线程/多线程模式均正常
2026-06-03 18:13:29 +08:00

67 lines
1.3 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Cocoon - 基于 coco 协程库的静态资源 Web 服务器
# coco 库路径(默认使用 submodule可覆盖
COCO_DIR ?= coco
COCO_INCLUDE ?= $(COCO_DIR)/include
COCO_LIB ?= $(COCO_DIR)/build
CC = gcc
CFLAGS = -Wall -Wextra -O2 -std=c11 -I$(COCO_INCLUDE)
LDFLAGS = -L$(COCO_LIB) -lcoco -lpthread -lm -luring
# 调试模式
DEBUG ?= 0
ifeq ($(DEBUG),1)
CFLAGS += -g -O0 -DCOCOON_DEBUG
endif
# 安装路径
PREFIX ?= /usr/local
BINDIR = $(PREFIX)/bin
# 源文件
SRCS = main.c server.c http.c static.c log.c
OBJS = $(SRCS:.c=.o)
TARGET = cocoon
# 默认目标
all: $(TARGET)
# 链接
$(TARGET): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)
# 构建 coco 依赖(如果 submodule 已初始化)
deps:
@if [ ! -d "$(COCO_DIR)/build" ]; then \
echo "[Cocoon] 构建 coco 依赖..."; \
cd $(COCO_DIR) && mkdir -p build && cd build && cmake .. && $(MAKE); \
else \
echo "[Cocoon] coco 已构建,跳过"; \
fi
# 完整构建(先构建依赖,再构建项目)
build-all: deps $(TARGET)
# 编译规则
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# 安装
install: $(TARGET)
install -d $(BINDIR)
install -m 755 $(TARGET) $(BINDIR)/
# 卸载
uninstall:
rm -f $(BINDIR)/$(TARGET)
# 清理
clean:
rm -f $(OBJS) $(TARGET)
# 重新构建
rebuild: clean all
.PHONY: all clean install uninstall rebuild deps build-all