为提高性能,改用c替换原本的flask

This commit is contained in:
2025-09-28 12:02:26 +08:00
parent a0e9bf1b44
commit 3c574e489d
24 changed files with 7240 additions and 0 deletions

34
c/network/swap.c Normal file
View File

@ -0,0 +1,34 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <linux/memfd.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include "network.h"
int make_swap(void *message)
{
rbt_msg *msg = (rbt_msg*)message;
printf("gid=%s uid=%s nick=%s raw=%s type=%c\n",
msg->gid, msg->uid, msg->nickname,
msg->raw_message, msg->message_type);
}
int create_swap(const char *name)
{
int fd = memfd_create(name,0);
//申请共享内存
ftruncate(fd, sizeof(rbt_msg));
//调整大小
rbt_msg *init_msg = (rbt_msg*)mmap(NULL, sizeof(rbt_msg), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
char buf[MAX_MESSAGE_BUF] = {'\0'};
memcpy(init_msg->raw_message,buf,MAX_MESSAGE_BUF);
memcpy(init_msg->nickname,buf,64);
munmap((void*)init_msg,sizeof(rbt_msg));
//初始化
return fd;
}