alcjzk / Webserv

0 stars 0 forks source link

Async I/O & Composite Tasks #47

Closed alcjzk closed 7 months ago

alcjzk commented 7 months ago

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 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

TODO: