This tutorial is the process of learning C++ when I was a student. After working, I no longer have the energy to write the rest. Looking back on the code back then, there are many imperfections and even flaws. Those who are willing can freely modify, develop, and continue the project. For a more perfect C language basic library, please move to wheelib
Let me start with the conclusion: No matter what language is used, the foundation of all backend development is C/C++ server development for Linux.
Almost all high-concurrency servers run in the Linux environment. The author has written servers in Java and node before, but in the end I found that I only learned a technology and a language, but did not understand the underlying basic principles. The process of an HTTP request, why high concurrency can be achieved, how to control TCP connections, how to handle the logic of data transmission, etc., can only be understood in depth by programming in C/C++.
This tutorial imitates "30 Days to Make Your Own Operating System" and is aimed at novices with zero experience. It will teach you how to get started with Linux server development in 30 days. This tutorial is more practical and will focus on how to write code without spending too much space explaining the basic computer principles behind it. Specific chapters of the corresponding books will be given where relevant, but this does not mean that This theoretical knowledge is not important. In fact, the theoretical foundation is very important. Without theoretical support, it is nonsense to build a high-performance server.
This tutorial hopes readers:
After completing this tutorial, you will easily understand the muduo source code.
One of the difficulties in learning C/C++ is that you can't make actual things when you first learn. There is no feedback and the program runs in a dark command line. Unlike web development, you can see the results of your learning at any time. The code of this tutorial is placed in the code folder. After studying every day, you can get a server that can be compiled and run, and iterative development is continued.
There is a code folder for each day in the code folder. Enter the folder and use the make
command to compile. Two executable files will be generated. Enter the command ./server
to see today's learning results! Then create a new Terminal and enter ./client
to run the client and interact with the server.
day01-Start with the simplest socket
day02-Don’t let any mistakes go
day03-For high concurrency, epoll must be used
day04- Let’s take a look at our first class
day05-epoll advanced usage-Channel debut
day06-Server and event-driven core classes appear
day07-Add an Acceptor to our server
day08-Everything is a class, even TCP connections are no exception
day09-buffer-big role
day10-join the thread pool to the server
day11-Improve the thread pool and add a simple test program
day12-Rewrite the server into master-slave Reactor multi-thread mode
day13-C++ engineering, code analysis, performance optimization
day14-Support business logic customization and improve the Connection class
day15-macOS supports and improves business logic customization
day16-Refactor the server and use smart pointers
timer
Logging system
HTTP protocol support
webbench test
File download resumes at breakpoints
Static resource storage
...
The Wlgls/30daysCppWebServer project attempts to write subsequent parts for reference.
My ability is average and my level is limited. If you find that my tutorials are incorrect or worthy of improvement, please feel free to raise an issue or directly PR.
Everyone is welcome to contribute your own code to this project. If you have code that you think is better, please submit an issue or directly PR. All suggestions will be considered.
To contribute code, please go to the pine project, which is the network library developed in this tutorial and is also the latest code version.