Cross-platform, efficient, customizable, and robust asynchronous HTTP(S)/WebSocket server C++ library with the right balance between performance and ease of use
Other
1.13k
stars
92
forks
source link
What’s the implementation pattern of restinio ?? asynchronously or synchronously?? Is there any choice item to specify?? #133
Let's see how RESTinio works if it's launched on a single thread:
RESTinio initiates an event-loop on this worker thread. All I/O operations (accept, read, write) will be performed on this thread only;
when RESTinio reads a new incoming HTTP-message (remember, read is performed on worker thread) RESTinio calls the request_handler specified by a user. And that call is performed synchronously. E.g. request_handler is called on the context of the worker thread, and request_handler blocks this thread, no I/O operations can be performed until request_handler returns;
request_handler can process the incoming request right here. In that case, request_handler performs all necessary actions (regardless of how long it can take) and then returns request_accepted (or request_rejected) value. It allows RESTinio to know that the incoming message fully processed and RESTinio continues its I/O operations;
but request_handler can delegate the processing of the incoming request to another worker thread. In that case request_handler should return request_accepted. RESTinio will continue I/O operations. When another worker thread completed the processing it calls done() for the requests and RESTinio receives the notification. In that case necessary write operations will be scheduled on the working thread where RESTinio works.
The model is selected by a user.
Let's see how RESTinio works if it's launched on a single thread:
request_accepted
(orrequest_rejected
) value. It allows RESTinio to know that the incoming message fully processed and RESTinio continues its I/O operations;request_accepted
. RESTinio will continue I/O operations. When another worker thread completed the processing it callsdone()
for the requests and RESTinio receives the notification. In that case necessary write operations will be scheduled on the working thread where RESTinio works.An example of synchronous processing can see here: https://github.com/Stiffstream/restinio/blob/v.0.6.12/dev/sample/hello_world/main.cpp And an example of asynchronous processing can be seen here: https://github.com/Stiffstream/restinio/blob/v.0.6.12/dev/sample/hello_world_delayed/main.cpp or here: https://github.com/Stiffstream/restinio/blob/v.0.6.12/dev/sample/async_handling_with_sobjectizer/main.cpp or in this demo-project: https://github.com/Stiffstream/restinio-crud-example