This PR refactors the original Task into a pure interface and separates it's default properties & overrides into two new abstract base classes; BasicTask and CompositeTask. This leaves CompositeTask free to forward the appropriate getters to it's subtasks, while allowing for retaining original function via BasicTask.
BasicTask provides the same properties and overrides as the previous task implementation. It serves as the new base for all the original task implementations (like AcceptTask etc).
CompositeTask is a templated alternative for BasicTask, that provides a state pattern implementation, useful for combining multiple tasks into one. This is necessary when a task may consist of a variable number of steps with intermediate poll() calls, such as serving a file or CGI response.
ErrorResponseTask
The impl for serving error responses has here been refactored into a derived CompositeTask, with the ability to asynchronously read and serve any configured error page. This is done by combining a ReadTask and a SendResponseTask.
FileResponseTask
FileResponseTask implements asynchronous file serving as a derived CompositeTask, by combining a ReadTask, SendResponseTask and an ErrorResponseTask.
ReadTask
ReadTask implements asynchronous reading from an arbitrary file descriptor. Currently used for reading files, can probably be used for reading from CGI.
Other Changes
Removed internal Type from Path, in favor of returning a Path::Status struct that also provides size (essentially a struct stat wrapper). This removes the need to call stat() twice for the same file when both filetype & size is needed.
Task Refactor & CompositeTask
This PR refactors the original
Task
into a pure interface and separates it's default properties & overrides into two new abstract base classes;BasicTask
andCompositeTask
. This leavesCompositeTask
free to forward the appropriate getters to it's subtasks, while allowing for retaining original function viaBasicTask
.BasicTask provides the same properties and overrides as the previous task implementation. It serves as the new base for all the original task implementations (like
AcceptTask
etc).CompositeTask is a templated alternative for BasicTask, that provides a state pattern implementation, useful for combining multiple tasks into one. This is necessary when a task may consist of a variable number of steps with intermediate
poll()
calls, such as serving a file or CGI response.ErrorResponseTask
The impl for serving error responses has here been refactored into a derived
CompositeTask
, with the ability to asynchronously read and serve any configured error page. This is done by combining aReadTask
and aSendResponseTask
.FileResponseTask
FileResponseTask
implements asynchronous file serving as a derivedCompositeTask
, by combining aReadTask
,SendResponseTask
and anErrorResponseTask
.ReadTask
ReadTask
implements asynchronous reading from an arbitrary file descriptor. Currently used for reading files, can probably be used for reading from CGI.Other Changes
Type
fromPath
, in favor of returning aPath::Status
struct that also provides size (essentially a struct stat wrapper). This removes the need to callstat()
twice for the same file when both filetype & size is needed.TODO: