Resources are data sets that application uses in its processing logic. For a DNS authoritative server this could be, amongst others, a GeoIP location DB, along with DNS records DB (zone data).
Resources are loaded, and reloaded in a dedicated thread to avoid blocking and time consuming operations in DNS query processing threads. Once loaded into memory resources are treated as read only and shared amongst query processing threads. For data validity purpose each thread keeps a reference to the shared object. When a resource changes, processing thread is notified and updates the reference (pointer) to such a resource. This update is done once all pending queries have us been processed which ensures data validity (data does not change under in the middle of resolving a query).
When all processing threads have updated their resource reference, the old resource data can safely be disposed of.
◆ resource_check_load_fn
| typedef int(* resource_check_load_fn) (resource_t *resource, void **buf, size_t *buf_len, char *err, size_t err_len) |
Function definition for custom function to be used when checking if resource changed and loading the resource on change.
- Parameters
-
| resource | Resource object to check and update. |
| buf | Where to store pointer to loaded data. |
| buf_len | Size of buffer where new data was loaded into. |
| err | Where to store error message if error was encountered. |
| err_len | Length of err buffer. |
- Returns
- On success returns 0, otherwise an error occurred.
◆ resource_loop_args_t
Structure holds arguments passed to resource_loop function. Since resource_loop function is started by pthread it can only receive one argument hence placing all arguments into one structure.
◆ resource_release_fn
| typedef void(* resource_release_fn) (resource_t *resource, void *buf) |
Function definition for custom function used to release resource data.
- Parameters
-
| resource | Resource object this resource data is for. |
| buf | Data to release. |
◆ resource_t
Structure describes a resource which is a file on disk. A resource is loaded at application start and used by other parts of the application. Resource could be periodically checked for change and updated resource data loaded.
◆ resource_check_load_raw_file()
| int resource_check_load_raw_file |
( |
resource_t * |
resource, |
|
|
void ** |
buf, |
|
|
size_t * |
buf_len, |
|
|
char * |
err, |
|
|
size_t |
err_len |
|
) |
| |
Function checks for change and if changed loads a file into memory buffer as raw data.
Change is checked for by stating the file for change time.
- Parameters
-
| resource | Resource to check |
| buf | Where to store pointer to loaded data, on change. |
| buf_len | Length of buf available to use. |
| err | Buffer where to store error string if error was encountered. |
| err_len | Length of err buffer available to use. |
- Returns
- 1 - Resource changed and was successfully loaded into buf 0 - Resource has not changed. -1 - There was an error either checking of loading the resource file. Error message is populated.
◆ resource_loop()
| void * resource_loop |
( |
void * |
args | ) |
|
Resource loop function. It periodically checks resources for change. On resource change it loads the new resource into memory and notifies each vectorloop thread that resource changed.
- Note
- This loop runs indefinitely and is meant to be run from the main() function, not on vectorloop thread, or any other tread.
- Parameters
-
| args | Object with arguments passed to resource loop. |
◆ resource_release_raw_file()
| void resource_release_raw_file |
( |
resource_t * |
resource, |
|
|
void * |
buf |
|
) |
| |
Function releases resource data of type raw file.
- Parameters
-
| resource | Resource this data applies to. |
| buf | Data to be released. |