avatar
文章
4
标签
7
分类
1

主页
归档
标签
分类
鱼头的个人博客
主页
归档
标签
分类

鱼头的个人博客

【理论篇】从0到1实现基于协程的WebServer(3) —— socket与IO多路复用(epoll)
发表于2024-06-27|WebServer
epoll
【理论篇】从0到1实现基于协程的WebServer(2) —— socket与IO多路复用(select和poll)
发表于2024-06-19|WebServer
如何建立网络通信在 linux 系统中,如果想要在客户端和服务器之间建立网络连接比如 TCP 或者 UDP 连接,需要借助 socket 相关系统调用来设置地址和端口并建立连接。 建立服务端程序一个简易的 echoserver 程序如下所示,该服务端程序可以接受一个客户端发来的消息并返回回去。 #include <arpa/inet.h>#include <cerrno>#include <iostream>#include <netinet/in.h>#include <sys/socket.h>#include <unistd.h>int main() { int fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { return 0; } int opt_val = 1; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt_val, sizeof(opt_val ...
【理论篇】从0到1实现基于协程的WebServer(1) —— coroutine协程
发表于2024-06-19|WebServer
什么是协程 协程是能暂停执行以在之后恢复的函数。 协程分为有栈协程和无栈协程。有栈协程在协程之间存在函数调用栈,保存了单独的上下文环境,可在嵌套函数中暂停执行。而无栈协程所有协程共享一个执行栈,本质上是一个状态机。 C++20中的协程 C++20 的协程是无栈协程,它们通过返回到调用方暂停执行,并且恢复执行所需的数据与栈分离存储。协程函数中需包含 co_await、co_yield、co_return 三个表达式的中的至少一个。 使用 co_return 的协程co_return 用于结束协程,并可返回一个值。 无返回值的协程#include <coroutine>#include <iostream>struct Promise { auto initial_suspend() noexcept { std::cout << "initial_suspend" << std::endl; return std::suspend_always{}; } ...
Hello World
发表于1970-01-01
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post$ hexo new "My New Post" More info: Writing Run server$ hexo server More info: Server Generate static files$ hexo generate More info: Generating Deploy to remote sites$ hexo deploy More info: Deployment
1
avatar
鱼头
文章
4
标签
7
分类
1
Follow Me
公告
This is my Blog
最新文章
【理论篇】从0到1实现基于协程的WebServer(3) —— socket与IO多路复用(epoll)2024-06-27
【理论篇】从0到1实现基于协程的WebServer(2) —— socket与IO多路复用(select和poll)2024-06-19
【理论篇】从0到1实现基于协程的WebServer(1) —— coroutine协程2024-06-19
Hello World1970-01-01
分类
  • WebServer3
标签
select 协程 poll epoll C++ socket IO多路复用
归档
  • 六月 20243
  • 一月 19701
网站资讯
文章数目 :
4
本站访客数 :
本站总访问量 :
最后更新时间 :
©2024 By 鱼头
框架 Hexo|主题 Butterfly