muduo是一个网络库,主要是来处理网络通信的,虽然也是做了一个http的例子。我们不同的地方是我主要是写的一个HTTP服务器,支持长短连接,cgi处理,静态页面处理;同时对具体业务和网络框架本身做了解耦,很方便的增加自己的cgi服务😝
An implementation of HTTP server based on c++11, which is easily to add a Cgi instance. It can handle static resources, support HTTP long connections, and so on. We also implement the Asynchronous Log to record the status of the server.
Test page :ExampleCgi, LoginCgi and UploadCgi
a) To Compile source files into binary executables (in the root folder)
bash install.sh
b) Run the program (in the build folder)
cd build
./httpcgiservermain
a) Write a Cgi instance class, which inherits the BaseCgi class, like ExampleCgi.
b) Add the Cgi instance into the CgiInstanceFactory.
c) Add the header file into the CgiHeader.
d) Modify the CMakeLists.txt.
e) Then build and run.
Test result by webBench is shown in Here.
See implDoc.md for a brief overview of the implementation. Guide to header files:
-
base/log.h Interface for log system, which is from Asynchronous Log.
-
epoller.h Encapsulate related functions of epoll.
-
netutil.h Encapsulate related functions of socket fd.
-
simplebuffer.h Application layer buffer(we only implement the LT model now).
-
channel.h Encapsulate channel(event) related callback functions (read/write/error functions).
-
minheap.h Use min heap to manage the expired time of connection.
-
eventloop.h It manages the channel(event), which is registed to the epoller, and process the active channels(events).
-
eventloopthread.h It manage a connect queue, and the main accept thread push connection socket fd into the queue, then this thread add the socket fds to its eventLoop.
-
eventloopthreadpool.h It manage several threads, the main accept thread push connection socket fd into the threadpool, it dispatches the socket to its threads.
-
tcpserver.h Accept connection socket fd, and when a read event happends on the connection socket, it automatically read the byte stream into the application buffer of the channel, and execute the read callback function. The same as write and error events happend.
-
httpmessage.h Parse the HTTP request, build HTTP respond message. Here, we use a state machine to process HTTP requests.
-
basecgi.h The abstract class of Cgi instance class. It provides a Process interface, we use it to process the cgi request.
-
includecgiheader.h Include the Cgi instance class, which is used for cgidispatch.
-
cgidispatch.h The Cgi dispatcher, which use the url to find the Cgi instance, to execute the cgi program.
-
httpcgiserver.h When read event happend, it firstly parses the http request in the application buffer of the channel, then finds the cgi instance and process the request.
-
httpcgiservermain.cpp HTTP server main.
-
exampleCgi/examplecgi.h and loginCgi/logincgi.h Example of how to write a Cgi instance class. webFile/login includes the .html, .js, .css files needed by the LoginCgi class.