C
Nuan_Feng
蓝桥杯国赛一等奖。唯有志存千里,方能风行天下。
展开
-
零拷贝原理详解
引言传统的 Linux 操作系统的标准 I/O 接口是基于数据拷贝操作的,即 I/O 操作会导致数据在操作系统内核地址空间的缓冲区和应用程序地址空间定义的缓冲区之间进行传输。这样做最大的好处是可以减少磁盘 I/O 的操作,因为如果所请求的数据已经存放在操作系统的高速缓冲存储器中,那么就不需要再进行实际的物理磁盘 I/O 操作。但是数据传输过程中的数据拷贝操作却导致了极大的 CPU 开销,限制了操作系统有效进行数据传输操作的能力。零拷贝( zero-copy )技术可以有效地改善数据传输的性能,在内核转载 2020-10-21 18:09:24 · 554 阅读 · 0 评论 -
分别采用epoll和libevent实现web服务器
文章目录epolllibeventepollmain.c#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include "epoll_http.h"int main(int argc, const char* argv[]){ if(argc < 3) { printf("eg: ./a.out port path\n"); ex原创 2020-10-03 15:51:42 · 433 阅读 · 0 评论 -
libevent案例
文章目录常规事件缓冲事件常规事件server#include <sys/stat.h>#include <unistd.h>#include <fcntl.h>#include <event2/event.h>void read_cb(evutil_socket_t fd, short what, void *arg) { char buf[1024]; int len = read(fd, buf, sizeof(buf))原创 2020-10-02 19:44:43 · 309 阅读 · 0 评论 -
安装libevent
文章目录安装gccyum -y install gcc安装 opensslyum install -y openssl openssl-devel安装nc,用于tcp/udp连接yum install nmap-ncat.x86_64 -y下载libeventwget https://github.com/libevent/libevent.git解压libeventtar -xzvf libevent-2.1.12-stable.tar.gz测试democd libeven原创 2020-09-30 22:44:46 · 462 阅读 · 0 评论 -
Cselect、poll、epoll、以及手写简易libevent反应堆源码
文章目录selectpollepoll反应堆select#include <stdio.h>#include <sys/socket.h>#include <stdlib.h>#include <unistd.h>#include <ctype.h>#include <arpa/inet.h>#include "warp_socket.h"#define PORT 8080/** * select * 缺点原创 2020-09-29 23:44:01 · 480 阅读 · 0 评论 -
C采用多线程和多进程实现TCP/UDP网络连接
文章目录基础版多进程版本多线程版本基础版封装的socket.hwarp_socket.h#ifndef _WRAP__#define _WRAP__#include <sys/socket.h>#define SOCKET_ERROR "socket error"#define CONNECT_ERROR "connect error"#define LISTEN_ERROR "listen error"#define BIND_ERROR "bind error原创 2020-09-28 17:42:09 · 1244 阅读 · 3 评论 -
C线程,线程池,信号量,锁以及使用条件变量相关
文章目录线程互斥锁使用条件变量+互斥锁实现生产者消费者使用信号量实现生产者消费者线程#include <pthread.h>#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>/** * 线程,linux下也称之为轻量级进程 * 在内核层面看来,进程和线程是一样的,但线程PCB独立,三级页表(虚拟地址,三级为:页面-页表-页目录)相原创 2020-09-27 16:50:17 · 390 阅读 · 0 评论 -
Cfork进程以及守护进程
#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <sys/fcntl.h>#include <sys/wait.h>/** * 进程 * 虚拟内存通过MMU映射到物理磁盘 * pcb进程控制块存储在内核空间,在磁盘中共享同一片区域,方便进程通信 * 而用户空间存储的值,在磁盘中不共享同一片区域 * * fork时,创建一个进程,这个进程原创 2020-09-26 12:56:59 · 282 阅读 · 0 评论 -
C关于MMAP的思考
文章目录mmap进程通信mmap#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/mman.h>#include <unistd.h>#include <sys/fcntl.h>/** * mmap * @return */int main() { int fd = open("test.txt", O_RDWR原创 2020-09-26 12:55:24 · 337 阅读 · 0 评论 -
C进程通信(管道,信号,有名,匿名管道,信号,mmap,本地套接字)
#include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <sys/fcntl.h>#include <sys/wait.h>#include <errno.h>#include <string.h>/** * 进程通信(IPC) * 因为整个操作系统中,内核只有一块,所以采用内核共享缓冲区,实现进程通信 * * * 管道 *原创 2020-09-26 12:47:01 · 411 阅读 · 0 评论