
linux
caijizhuo
正在学习的大菜逼
展开
-
【内存泄漏定位】
内存泄漏原创 2022-12-08 10:58:43 · 369 阅读 · 0 评论 -
nslookup程序(getaddrinfo和getnameinfo示例)
getaddrinfo 和 getnameinfo示例原创 2022-09-26 00:52:34 · 242 阅读 · 0 评论 -
半同步/半反应堆线程池实现
#ifndef THREADPOOL_H#define THREADPOOL_H#include <list>#include <cstdio>#include <exception>#include <pthread.h>#include "locker.h"// 线程池类,定义为模板类是为了代码复用,模板参数T是任务类template< typename T >class threadpool{public:原创 2022-05-16 22:27:21 · 309 阅读 · 0 评论 -
服务器压力测试客户端
#include <stdlib.h>#include <stdio.h>#include <assert.h>#include <unistd.h>#include <sys/types.h>#include <sys/epoll.h>#include <fcntl.h>#include <sys/socket.h>#include <netinet/in.h>#include &原创 2022-05-15 21:13:25 · 278 阅读 · 0 评论 -
cgi简单服务器
CGI 是Web 服务器运行时外部程序的规范,按CGI 编写的程序可以扩展服务器功能。CGI(Common Gateway Interface) 是WWW技术中最重要的技术之一,有着不可替代的重要地位。CGI是外部应用程序(CGI程序)与WEB服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的过程。CGI规范允许Web服务器执行外部程序,并将它们的输出发送给Web浏览器,CGI将Web的一组简单的静态超媒体文档变成一个完整的新的交互式媒体。CGI的处理步骤:通过Internet把用户原创 2022-05-04 02:45:30 · 1642 阅读 · 0 评论 -
线程同步机制包装类
#ifndef LOCKER_H#define LOCKER_H#include <exception>#include <pthread.h>#include <semaphore.h>class sem { public: sem() { if (sem_init(&m_sem, 0, 0) != 0) { throw std::exception(); } } ~sem() { sem_dest原创 2022-04-19 18:11:53 · 109 阅读 · 0 评论 -
不相干进程之间传递文件描述符
#include <sys/socket.h>#include <fcntl.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <assert.h>#include <string.h>static const int CONTROL_LEN = CMSG_LEN(sizeof(int));// 发送文件描述符,fd参数适用原创 2022-04-04 15:17:24 · 266 阅读 · 0 评论 -
基于共享内存的聊天室服务程序
服务器代码如下:#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <assert.h>#include <stdio.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <fcntl.h>#incl原创 2022-03-17 17:23:32 · 249 阅读 · 0 评论 -
父子进程信号量
#include <sys/sem.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <sys/wait.h>union semun { // 此结构体为semctl系统调用的第四个参数的推荐格式,由sys/sem.h给出 int val; // 用于SETVAL命令原创 2022-03-16 17:14:29 · 327 阅读 · 0 评论 -
基于时间堆的定时器
#ifndef MIN_HEAP#define MIN_HEAP#include <iostream>#include <netinet/in.h>#include <time.h>using std::exception;#define BUFFER_SIZE 64class heap_timer;struct client_data { sockaddr_in address; int sockfd; char buf[B原创 2022-03-10 10:57:58 · 1000 阅读 · 0 评论 -
基于时间轮的定时器
#ifndef TIME_WHEEL_TIMER#define TIME_WHEEL_TIMER#include <time.h>#include <netinet/in.h>#include <stdio.h>#define BUFFER_SIZE 64class tw_timer;struct client_data { sockaddr_in address; int sockfd; char buf[BUFFER_SIZE原创 2022-03-08 17:01:43 · 150 阅读 · 0 评论 -
处理非活动连接
其中依赖的lst_timer.h见上篇文章#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <assert.h>#include <stdio.h>#include <signal.h>#include <unistd.h>#include <原创 2022-03-07 15:40:26 · 416 阅读 · 0 评论 -
基于升序链表的定时器
#ifndef LST_TIMER#define LST_TIMER#include <time.h>#define BUFFER_SIZE 64class util_timer;struct client_data { sockaddr_in address; int sockfd; char buf[BUFFER_SIZE]; util_timer* timer; };class util_timer {public: ut原创 2022-03-03 19:48:29 · 384 阅读 · 0 评论 -
Linux服务器编程 用SIGURG检测带外数据是否到达
带外数据带外数据用于迅速告知对方本端发生的重要的事件。它比普通的数据(带内数据)拥有更高的优先级,不论发送缓冲区中是否有排队等待发送的数据,它总是被立即发送。带外数据的传输可以使用一条独立的传输层连接,也可以映射到传输普通数据的连接中。SIGURG信号的作用在linux环境下,内核通知应用程序带外数据到达的方式有两种:一种就是利用I/O复用技术的系统调用(如select)在接受到带外数据时将返回,并向应用程序报告socket上的异常事件。另一种方法就是使用SIGURG信号。(下面代码)代码:原创 2022-02-28 00:23:39 · 296 阅读 · 0 评论 -
LINUX IO复用高级应用二:聊天室程序
客户端:#define _GNU_SOURCE 1#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <assert.h>#include <stdio.h>#include <unistd.h>#include <string.h>#include原创 2022-02-16 01:17:41 · 654 阅读 · 0 评论 -
Linux 服务器高级编程ET LT代码
linux 服务器高级编程ET LT代码#include<sys/types.h>#include<sys/socket.h>#include<netinet/in.h>#include<arpa/inet.h>#include<assert.h>#include<stdio.h>#include<unistd.h>#include<errno.h>#include<string.h>原创 2022-02-11 00:37:06 · 762 阅读 · 0 评论