async.h 3.2 KB

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