160766af36ddca46747b6a610409160596f3205a
[openssl.git] / include / openssl / async.h
1 /*
2  * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the OpenSSL license (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 HEADER_ASYNC_H
13 # define HEADER_ASYNC_H
14
15 #if defined(_WIN32)
16 #include <windows.h>
17 #define OSSL_ASYNC_FD       HANDLE
18 #define OSSL_BAD_ASYNC_FD   INVALID_HANDLE_VALUE
19 #else
20 #define OSSL_ASYNC_FD       int
21 #define OSSL_BAD_ASYNC_FD   -1
22 #endif
23
24
25 # ifdef  __cplusplus
26 extern "C" {
27 # endif
28
29 typedef struct async_job_st ASYNC_JOB;
30 typedef struct async_wait_ctx_st ASYNC_WAIT_CTX;
31
32 #define ASYNC_ERR      0
33 #define ASYNC_NO_JOBS  1
34 #define ASYNC_PAUSE    2
35 #define ASYNC_FINISH   3
36
37 int ASYNC_init_thread(size_t max_size, size_t init_size);
38 void ASYNC_cleanup_thread(void);
39
40 ASYNC_WAIT_CTX *ASYNC_WAIT_CTX_new(void);
41 void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx);
42 int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key,
43                                OSSL_ASYNC_FD fd,
44                                void *custom_data,
45                                void (*cleanup)(ASYNC_WAIT_CTX *, const void *,
46                                                OSSL_ASYNC_FD, void *));
47 int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key,
48                         OSSL_ASYNC_FD *fd, void **custom_data);
49 int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd,
50                                size_t *numfds);
51 int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd,
52                                    size_t *numaddfds, OSSL_ASYNC_FD *delfd,
53                                    size_t *numdelfds);
54 int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key);
55
56 int ASYNC_is_capable(void);
57
58 int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *ctx, int *ret,
59                     int (*func)(void *), void *args, size_t size);
60 int ASYNC_pause_job(void);
61
62 ASYNC_JOB *ASYNC_get_current_job(void);
63 ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job);
64 void ASYNC_block_pause(void);
65 void ASYNC_unblock_pause(void);
66
67 /* BEGIN ERROR CODES */
68 /*
69  * The following lines are auto generated by the script mkerr.pl. Any changes
70  * made after this point may be overwritten when the script is next run.
71  */
72
73 void ERR_load_ASYNC_strings(void);
74
75 /* Error codes for the ASYNC functions. */
76
77 /* Function codes. */
78 # define ASYNC_F_ASYNC_CTX_NEW                            100
79 # define ASYNC_F_ASYNC_INIT_THREAD                        101
80 # define ASYNC_F_ASYNC_JOB_NEW                            102
81 # define ASYNC_F_ASYNC_PAUSE_JOB                          103
82 # define ASYNC_F_ASYNC_START_FUNC                         104
83 # define ASYNC_F_ASYNC_START_JOB                          105
84
85 /* Reason codes. */
86 # define ASYNC_R_FAILED_TO_SET_POOL                       101
87 # define ASYNC_R_FAILED_TO_SWAP_CONTEXT                   102
88 # define ASYNC_R_INIT_FAILED                              105
89 # define ASYNC_R_INVALID_POOL_SIZE                        103
90
91 # ifdef  __cplusplus
92 }
93 # endif
94 #endif