⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.c

📁 类似apache2.0的多线程技术,目的在于解决网络服务器在并发客户数很大的情况下服务器进程分配(fork)而带来的效率瓶颈.
💻 C
字号:
#include <stdio.h>#include <sys/stat.h>#include <sys/types.h>#include <string.h>#include <stdlib.h>#include <time.h>#include <pthread.h>#include "service.h"#include "s_io.h"int main_test(int fd){    char buf[] = "hello, world!\n";    write(fd, buf, sizeof(buf));    close(fd);    return 0;}int main(){    struct server_info ser_info;    struct handler_info han_info;    ser_info.type = I_NET;    ser_info.port = 1231;    //ser_info.type = U_DOMAIN;    //strcpy(ser_info.path, "/var/eyou/mfs.sock");    ser_info.thread_num = 32;    ser_info.max_service = 2048;    han_info.main_handler = main_test;    han_info.init_handler = NULL;    han_info.exit_handler = NULL;    start_server(&ser_info, &han_info);    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -