Proactor[1]¶
连接¶
The Web Server instructs the Acceptor to initiate an asynchronous accept;
The Acceptor initiates an asynchronous accept with the OS and passes itself as a Completion Handler and a reference to the Completion Dispatcher that will be used to notify the Acceptor upon completion of the asynchronous accept;
The Web Server invokes the event loop of the Completion Dispatcher;
The client connects to the Web Server;
When the asynchronous accept operation completes, the Operating System notifies the Completion Dispatcher;
The Completion Dispatcher notifies the Acceptor;
The Acceptor creates an HTTP Handler;
The HTTP Handler initiates an asynchronous operation to read the request data from the client and passes itself as a Completion Handler and a reference to the Completion Dispatcher that will be used to notify the HTTP Handler upon completion of the asynchronous read.
读写¶
The client sends an HTTP GET request;
The read operation completes and the Operating System notifies the Completion Dispatcher;
The Completion Dispatcher notifies the HTTP Handler (steps 2 and 3 will repeat until the entire request has been received);
The HTTP Handler parses the request;
The HTTP Handler synchronously reads the requested file;
The HTTP Handler initiates an asynchronous operation to write the file data to the client connection and passes itself as a Completion Handler and a reference to the Completion Dispatcher that will be used to notify the HTTP Handler upon completion of the asynchronous write;
When the write operation completes, the Operating System notifies the Completion Dispatcher;
The Completion Dispatcher then notifies the Completion Handler (steps 6-8 continue until the file has been delivered completely).