xref: /src/crypto/openssl/include/openssl/async.h (revision f25b8c9fb4f58cf61adb47d7570abe7caa6d385d)
1 /*
2  * Copyright 2015-2022 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include <stdlib.h>
11 
12 #ifndef OPENSSL_ASYNC_H
13 #define OPENSSL_ASYNC_H
14 #pragma once
15 
16 #include <openssl/macros.h>
17 #ifndef OPENSSL_NO_DEPRECATED_3_0
18 #define HEADER_ASYNC_H
19 #endif
20 
21 #if defined(_WIN32)
22 #if defined(BASETYPES) || defined(_WINDEF_H)
23 /* application has to include <windows.h> to use this */
24 #define OSSL_ASYNC_FD HANDLE
25 #define OSSL_BAD_ASYNC_FD INVALID_HANDLE_VALUE
26 #endif
27 #else
28 #define OSSL_ASYNC_FD int
29 #define OSSL_BAD_ASYNC_FD -1
30 #endif
31 #include <openssl/asyncerr.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 typedef struct async_job_st ASYNC_JOB;
38 typedef struct async_wait_ctx_st ASYNC_WAIT_CTX;
39 typedef int (*ASYNC_callback_fn)(void *arg);
40 
41 #define ASYNC_ERR 0
42 #define ASYNC_NO_JOBS 1
43 #define ASYNC_PAUSE 2
44 #define ASYNC_FINISH 3
45 
46 #define ASYNC_STATUS_UNSUPPORTED 0
47 #define ASYNC_STATUS_ERR 1
48 #define ASYNC_STATUS_OK 2
49 #define ASYNC_STATUS_EAGAIN 3
50 
51 int ASYNC_init_thread(size_t max_size, size_t init_size);
52 void ASYNC_cleanup_thread(void);
53 
54 #ifdef OSSL_ASYNC_FD
55 ASYNC_WAIT_CTX *ASYNC_WAIT_CTX_new(void);
56 void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx);
57 int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key,
58     OSSL_ASYNC_FD fd,
59     void *custom_data,
60     void (*cleanup)(ASYNC_WAIT_CTX *, const void *,
61         OSSL_ASYNC_FD, void *));
62 int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key,
63     OSSL_ASYNC_FD *fd, void **custom_data);
64 int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd,
65     size_t *numfds);
66 int ASYNC_WAIT_CTX_get_callback(ASYNC_WAIT_CTX *ctx,
67     ASYNC_callback_fn *callback,
68     void **callback_arg);
69 int ASYNC_WAIT_CTX_set_callback(ASYNC_WAIT_CTX *ctx,
70     ASYNC_callback_fn callback,
71     void *callback_arg);
72 int ASYNC_WAIT_CTX_set_status(ASYNC_WAIT_CTX *ctx, int status);
73 int ASYNC_WAIT_CTX_get_status(ASYNC_WAIT_CTX *ctx);
74 int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd,
75     size_t *numaddfds, OSSL_ASYNC_FD *delfd,
76     size_t *numdelfds);
77 int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key);
78 #endif
79 
80 int ASYNC_is_capable(void);
81 
82 typedef void *(*ASYNC_stack_alloc_fn)(size_t *num);
83 typedef void (*ASYNC_stack_free_fn)(void *addr);
84 
85 int ASYNC_set_mem_functions(ASYNC_stack_alloc_fn alloc_fn,
86     ASYNC_stack_free_fn free_fn);
87 void ASYNC_get_mem_functions(ASYNC_stack_alloc_fn *alloc_fn,
88     ASYNC_stack_free_fn *free_fn);
89 
90 int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *ctx, int *ret,
91     int (*func)(void *), void *args, size_t size);
92 int ASYNC_pause_job(void);
93 
94 ASYNC_JOB *ASYNC_get_current_job(void);
95 ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job);
96 void ASYNC_block_pause(void);
97 void ASYNC_unblock_pause(void);
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 #endif
103