async.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include <stdlib.h>
  10. #ifndef OPENSSL_ASYNC_H
  11. #define OPENSSL_ASYNC_H
  12. #pragma once
  13. #include <openssl/macros.h>
  14. #ifndef OPENSSL_NO_DEPRECATED_3_0
  15. #define HEADER_ASYNC_H
  16. #endif
  17. #if defined(_WIN32)
  18. #if defined(BASETYPES) || defined(_WINDEF_H)
  19. /* application has to include <windows.h> to use this */
  20. #define OSSL_ASYNC_FD HANDLE
  21. #define OSSL_BAD_ASYNC_FD INVALID_HANDLE_VALUE
  22. #endif
  23. #else
  24. #define OSSL_ASYNC_FD int
  25. #define OSSL_BAD_ASYNC_FD -1
  26. #endif
  27. #include <openssl/asyncerr.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. typedef struct async_job_st ASYNC_JOB;
  32. typedef struct async_wait_ctx_st ASYNC_WAIT_CTX;
  33. typedef int (*ASYNC_callback_fn)(void *arg);
  34. #define ASYNC_ERR 0
  35. #define ASYNC_NO_JOBS 1
  36. #define ASYNC_PAUSE 2
  37. #define ASYNC_FINISH 3
  38. #define ASYNC_STATUS_UNSUPPORTED 0
  39. #define ASYNC_STATUS_ERR 1
  40. #define ASYNC_STATUS_OK 2
  41. #define ASYNC_STATUS_EAGAIN 3
  42. int ASYNC_init_thread(size_t max_size, size_t init_size);
  43. void ASYNC_cleanup_thread(void);
  44. #ifdef OSSL_ASYNC_FD
  45. ASYNC_WAIT_CTX *ASYNC_WAIT_CTX_new(void);
  46. void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx);
  47. int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key,
  48. OSSL_ASYNC_FD fd,
  49. void *custom_data,
  50. void (*cleanup)(ASYNC_WAIT_CTX *, const void *,
  51. OSSL_ASYNC_FD, void *));
  52. int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key,
  53. OSSL_ASYNC_FD *fd, void **custom_data);
  54. int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd,
  55. size_t *numfds);
  56. int ASYNC_WAIT_CTX_get_callback(ASYNC_WAIT_CTX *ctx,
  57. ASYNC_callback_fn *callback,
  58. void **callback_arg);
  59. int ASYNC_WAIT_CTX_set_callback(ASYNC_WAIT_CTX *ctx,
  60. ASYNC_callback_fn callback,
  61. void *callback_arg);
  62. int ASYNC_WAIT_CTX_set_status(ASYNC_WAIT_CTX *ctx, int status);
  63. int ASYNC_WAIT_CTX_get_status(ASYNC_WAIT_CTX *ctx);
  64. int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd,
  65. size_t *numaddfds, OSSL_ASYNC_FD *delfd,
  66. size_t *numdelfds);
  67. int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key);
  68. #endif
  69. int ASYNC_is_capable(void);
  70. typedef void *(*ASYNC_stack_alloc_fn)(size_t *num);
  71. typedef void (*ASYNC_stack_free_fn)(void *addr);
  72. int ASYNC_set_mem_functions(ASYNC_stack_alloc_fn alloc_fn,
  73. ASYNC_stack_free_fn free_fn);
  74. void ASYNC_get_mem_functions(ASYNC_stack_alloc_fn *alloc_fn,
  75. ASYNC_stack_free_fn *free_fn);
  76. int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *ctx, int *ret,
  77. int (*func)(void *), void *args, size_t size);
  78. int ASYNC_pause_job(void);
  79. ASYNC_JOB *ASYNC_get_current_job(void);
  80. ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job);
  81. void ASYNC_block_pause(void);
  82. void ASYNC_unblock_pause(void);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif