mirror of
https://github.com/zeek/zeek.git
synced 2025-10-01 22:28:20 +00:00
Add flag to force synchronous mode when calling storage script-land functions
This commit is contained in:
parent
ee5ffdf42c
commit
7e3ed2010d
13 changed files with 186 additions and 14 deletions
|
@ -81,30 +81,46 @@ export {
|
|||
function open_backend(btype: Storage::Backend, options: Storage::BackendOptions,
|
||||
key_type: any, val_type: any): Storage::OperationResult
|
||||
{
|
||||
return Storage::Async::__open_backend(btype, options, key_type, val_type);
|
||||
if ( options$forced_sync )
|
||||
return Storage::Sync::__open_backend(btype, options, key_type, val_type);
|
||||
else
|
||||
return Storage::Async::__open_backend(btype, options, key_type, val_type);
|
||||
}
|
||||
|
||||
function close_backend(backend: opaque of Storage::BackendHandle)
|
||||
: Storage::OperationResult
|
||||
{
|
||||
return Storage::Async::__close_backend(backend);
|
||||
if ( Storage::is_forced_sync(backend) )
|
||||
return Storage::Sync::__close_backend(backend);
|
||||
else
|
||||
return Storage::Async::__close_backend(backend);
|
||||
}
|
||||
|
||||
function put(backend: opaque of Storage::BackendHandle, args: Storage::PutArgs)
|
||||
: Storage::OperationResult
|
||||
{
|
||||
return Storage::Async::__put(backend, args$key, args$value, args$overwrite,
|
||||
args$expire_time);
|
||||
if ( Storage::is_forced_sync(backend) )
|
||||
return Storage::Sync::__put(backend, args$key, args$value, args$overwrite,
|
||||
args$expire_time);
|
||||
else
|
||||
return Storage::Async::__put(backend, args$key, args$value, args$overwrite,
|
||||
args$expire_time);
|
||||
}
|
||||
|
||||
function get(backend: opaque of Storage::BackendHandle, key: any)
|
||||
: Storage::OperationResult
|
||||
{
|
||||
return Storage::Async::__get(backend, key);
|
||||
if ( Storage::is_forced_sync(backend) )
|
||||
return Storage::Sync::__get(backend, key);
|
||||
else
|
||||
return Storage::Async::__get(backend, key);
|
||||
}
|
||||
|
||||
function erase(backend: opaque of Storage::BackendHandle, key: any)
|
||||
: Storage::OperationResult
|
||||
{
|
||||
return Storage::Async::__erase(backend, key);
|
||||
if ( Storage::is_forced_sync(backend) )
|
||||
return Storage::Sync::__erase(backend, key);
|
||||
else
|
||||
return Storage::Async::__erase(backend, key);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
module Storage;
|
||||
|
||||
export {
|
||||
# Default value for the BackendOptions::forced_sync field.
|
||||
const default_forced_sync: bool = F &redef;
|
||||
|
||||
## Base record for backend options that can be passed to
|
||||
## :zeek:see:`Storage::Async::open_backend` and
|
||||
## :zeek:see:`Storage::Sync::open_backend`. Backend plugins can redef this record
|
||||
|
@ -10,6 +13,11 @@ export {
|
|||
type BackendOptions: record {
|
||||
## The serializer used for converting Zeek data.
|
||||
serializer: Storage::Serializer &default=Storage::STORAGE_SERIALIZER_JSON;
|
||||
|
||||
## Sets the backend into forced-synchronous mode. All operations will run
|
||||
## in synchronous mode, even if the async functions are called. This
|
||||
## should generally only be set to ``T`` during testing.
|
||||
forced_sync : bool &default=Storage::default_forced_sync;
|
||||
};
|
||||
|
||||
## Record for passing arguments to :zeek:see:`Storage::Async::put` and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue