ASYNC_start_job.3ossl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. .\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
  2. .\"
  3. .\" Standard preamble:
  4. .\" ========================================================================
  5. .de Sp \" Vertical space (when we can't use .PP)
  6. .if t .sp .5v
  7. .if n .sp
  8. ..
  9. .de Vb \" Begin verbatim text
  10. .ft CW
  11. .nf
  12. .ne \\$1
  13. ..
  14. .de Ve \" End verbatim text
  15. .ft R
  16. .fi
  17. ..
  18. .\" Set up some character translations and predefined strings. \*(-- will
  19. .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
  20. .\" double quote, and \*(R" will give a right double quote. \*(C+ will
  21. .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
  22. .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
  23. .\" nothing in troff, for use with C<>.
  24. .tr \(*W-
  25. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  26. .ie n \{\
  27. . ds -- \(*W-
  28. . ds PI pi
  29. . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
  30. . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
  31. . ds L" ""
  32. . ds R" ""
  33. . ds C` ""
  34. . ds C' ""
  35. 'br\}
  36. .el\{\
  37. . ds -- \|\(em\|
  38. . ds PI \(*p
  39. . ds L" ``
  40. . ds R" ''
  41. . ds C`
  42. . ds C'
  43. 'br\}
  44. .\"
  45. .\" Escape single quotes in literal strings from groff's Unicode transform.
  46. .ie \n(.g .ds Aq \(aq
  47. .el .ds Aq '
  48. .\"
  49. .\" If the F register is >0, we'll generate index entries on stderr for
  50. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  51. .\" entries marked with X<> in POD. Of course, you'll have to process the
  52. .\" output yourself in some meaningful fashion.
  53. .\"
  54. .\" Avoid warning from groff about undefined register 'F'.
  55. .de IX
  56. ..
  57. .nr rF 0
  58. .if \n(.g .if rF .nr rF 1
  59. .if (\n(rF:(\n(.g==0)) \{\
  60. . if \nF \{\
  61. . de IX
  62. . tm Index:\\$1\t\\n%\t"\\$2"
  63. ..
  64. . if !\nF==2 \{\
  65. . nr % 0
  66. . nr F 2
  67. . \}
  68. . \}
  69. .\}
  70. .rr rF
  71. .\"
  72. .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
  73. .\" Fear. Run. Save yourself. No user-serviceable parts.
  74. . \" fudge factors for nroff and troff
  75. .if n \{\
  76. . ds #H 0
  77. . ds #V .8m
  78. . ds #F .3m
  79. . ds #[ \f1
  80. . ds #] \fP
  81. .\}
  82. .if t \{\
  83. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  84. . ds #V .6m
  85. . ds #F 0
  86. . ds #[ \&
  87. . ds #] \&
  88. .\}
  89. . \" simple accents for nroff and troff
  90. .if n \{\
  91. . ds ' \&
  92. . ds ` \&
  93. . ds ^ \&
  94. . ds , \&
  95. . ds ~ ~
  96. . ds /
  97. .\}
  98. .if t \{\
  99. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  100. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  101. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  102. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  103. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  104. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  105. .\}
  106. . \" troff and (daisy-wheel) nroff accents
  107. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  108. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  109. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  110. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  111. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  112. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  113. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  114. .ds ae a\h'-(\w'a'u*4/10)'e
  115. .ds Ae A\h'-(\w'A'u*4/10)'E
  116. . \" corrections for vroff
  117. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  118. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  119. . \" for low resolution devices (crt and lpr)
  120. .if \n(.H>23 .if \n(.V>19 \
  121. \{\
  122. . ds : e
  123. . ds 8 ss
  124. . ds o a
  125. . ds d- d\h'-1'\(ga
  126. . ds D- D\h'-1'\(hy
  127. . ds th \o'bp'
  128. . ds Th \o'LP'
  129. . ds ae ae
  130. . ds Ae AE
  131. .\}
  132. .rm #[ #] #H #V #F C
  133. .\" ========================================================================
  134. .\"
  135. .IX Title "ASYNC_START_JOB 3ossl"
  136. .TH ASYNC_START_JOB 3ossl "2024-09-03" "3.3.2" "OpenSSL"
  137. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  138. .\" way too many mistakes in technical documents.
  139. .if n .ad l
  140. .nh
  141. .SH "NAME"
  142. ASYNC_get_wait_ctx,
  143. ASYNC_init_thread, ASYNC_cleanup_thread, ASYNC_start_job, ASYNC_pause_job,
  144. ASYNC_get_current_job, ASYNC_block_pause, ASYNC_unblock_pause, ASYNC_is_capable,
  145. ASYNC_stack_alloc_fn, ASYNC_stack_free_fn, ASYNC_set_mem_functions, ASYNC_get_mem_functions
  146. \&\- asynchronous job management functions
  147. .SH "SYNOPSIS"
  148. .IX Header "SYNOPSIS"
  149. .Vb 1
  150. \& #include <openssl/async.h>
  151. \&
  152. \& int ASYNC_init_thread(size_t max_size, size_t init_size);
  153. \& void ASYNC_cleanup_thread(void);
  154. \&
  155. \& int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *ctx, int *ret,
  156. \& int (*func)(void *), void *args, size_t size);
  157. \& int ASYNC_pause_job(void);
  158. \&
  159. \& ASYNC_JOB *ASYNC_get_current_job(void);
  160. \& ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job);
  161. \& void ASYNC_block_pause(void);
  162. \& void ASYNC_unblock_pause(void);
  163. \&
  164. \& int ASYNC_is_capable(void);
  165. \&
  166. \& typedef void *(*ASYNC_stack_alloc_fn)(size_t *num);
  167. \& typedef void (*ASYNC_stack_free_fn)(void *addr);
  168. \& int ASYNC_set_mem_functions(ASYNC_stack_alloc_fn alloc_fn,
  169. \& ASYNC_stack_free_fn free_fn);
  170. \& void ASYNC_get_mem_functions(ASYNC_stack_alloc_fn *alloc_fn,
  171. \& ASYNC_stack_free_fn *free_fn);
  172. .Ve
  173. .SH "DESCRIPTION"
  174. .IX Header "DESCRIPTION"
  175. OpenSSL implements asynchronous capabilities through an \fB\s-1ASYNC_JOB\s0\fR. This
  176. represents code that can be started and executes until some event occurs. At
  177. that point the code can be paused and control returns to user code until some
  178. subsequent event indicates that the job can be resumed.
  179. .PP
  180. The creation of an \fB\s-1ASYNC_JOB\s0\fR is a relatively expensive operation. Therefore,
  181. for efficiency reasons, jobs can be created up front and reused many times. They
  182. are held in a pool until they are needed, at which point they are removed from
  183. the pool, used, and then returned to the pool when the job completes. If the
  184. user application is multi-threaded, then \fBASYNC_init_thread()\fR may be called for
  185. each thread that will initiate asynchronous jobs. Before
  186. user code exits per-thread resources need to be cleaned up. This will normally
  187. occur automatically (see \fBOPENSSL_init_crypto\fR\|(3)) but may be explicitly
  188. initiated by using \fBASYNC_cleanup_thread()\fR. No asynchronous jobs must be
  189. outstanding for the thread when \fBASYNC_cleanup_thread()\fR is called. Failing to
  190. ensure this will result in memory leaks.
  191. .PP
  192. The \fImax_size\fR argument limits the number of \fB\s-1ASYNC_JOB\s0\fRs that will be held in
  193. the pool. If \fImax_size\fR is set to 0 then no upper limit is set. When an
  194. \&\fB\s-1ASYNC_JOB\s0\fR is needed but there are none available in the pool already then one
  195. will be automatically created, as long as the total of \fB\s-1ASYNC_JOB\s0\fRs managed by
  196. the pool does not exceed \fImax_size\fR. When the pool is first initialised
  197. \&\fIinit_size\fR \fB\s-1ASYNC_JOB\s0\fRs will be created immediately. If \fBASYNC_init_thread()\fR
  198. is not called before the pool is first used then it will be called automatically
  199. with a \fImax_size\fR of 0 (no upper limit) and an \fIinit_size\fR of 0 (no
  200. \&\fB\s-1ASYNC_JOB\s0\fRs created up front).
  201. .PP
  202. An asynchronous job is started by calling the \fBASYNC_start_job()\fR function.
  203. Initially \fI*job\fR should be \s-1NULL.\s0 \fIctx\fR should point to an \fB\s-1ASYNC_WAIT_CTX\s0\fR
  204. object created through the \fBASYNC_WAIT_CTX_new\fR\|(3) function. \fIret\fR should
  205. point to a location where the return value of the asynchronous function should
  206. be stored on completion of the job. \fIfunc\fR represents the function that should
  207. be started asynchronously. The data pointed to by \fIargs\fR and of size \fIsize\fR
  208. will be copied and then passed as an argument to \fIfunc\fR when the job starts.
  209. ASYNC_start_job will return one of the following values:
  210. .IP "\fB\s-1ASYNC_ERR\s0\fR" 4
  211. .IX Item "ASYNC_ERR"
  212. An error occurred trying to start the job. Check the OpenSSL error queue (e.g.
  213. see \fBERR_print_errors\fR\|(3)) for more details.
  214. .IP "\fB\s-1ASYNC_NO_JOBS\s0\fR" 4
  215. .IX Item "ASYNC_NO_JOBS"
  216. There are no jobs currently available in the pool. This call can be retried
  217. again at a later time.
  218. .IP "\fB\s-1ASYNC_PAUSE\s0\fR" 4
  219. .IX Item "ASYNC_PAUSE"
  220. The job was successfully started but was \*(L"paused\*(R" before it completed (see
  221. \&\fBASYNC_pause_job()\fR below). A handle to the job is placed in \fI*job\fR. Other work
  222. can be performed (if desired) and the job restarted at a later time. To restart
  223. a job call \fBASYNC_start_job()\fR again passing the job handle in \fI*job\fR. The
  224. \&\fIfunc\fR, \fIargs\fR and \fIsize\fR parameters will be ignored when restarting a job.
  225. When restarting a job \fBASYNC_start_job()\fR \fBmust\fR be called from the same thread
  226. that the job was originally started from.
  227. .IP "\fB\s-1ASYNC_FINISH\s0\fR" 4
  228. .IX Item "ASYNC_FINISH"
  229. The job completed. \fI*job\fR will be \s-1NULL\s0 and the return value from \fIfunc\fR will
  230. be placed in \fI*ret\fR.
  231. .PP
  232. At any one time there can be a maximum of one job actively running per thread
  233. (you can have many that are paused). \fBASYNC_get_current_job()\fR can be used to get
  234. a pointer to the currently executing \fB\s-1ASYNC_JOB\s0\fR. If no job is currently
  235. executing then this will return \s-1NULL.\s0
  236. .PP
  237. If executing within the context of a job (i.e. having been called directly or
  238. indirectly by the function \*(L"func\*(R" passed as an argument to \fBASYNC_start_job()\fR)
  239. then \fBASYNC_pause_job()\fR will immediately return control to the calling
  240. application with \fB\s-1ASYNC_PAUSE\s0\fR returned from the \fBASYNC_start_job()\fR call. A
  241. subsequent call to ASYNC_start_job passing in the relevant \fB\s-1ASYNC_JOB\s0\fR in the
  242. \&\fI*job\fR parameter will resume execution from the \fBASYNC_pause_job()\fR call. If
  243. \&\fBASYNC_pause_job()\fR is called whilst not within the context of a job then no
  244. action is taken and \fBASYNC_pause_job()\fR returns immediately.
  245. .PP
  246. \&\fBASYNC_get_wait_ctx()\fR can be used to get a pointer to the \fB\s-1ASYNC_WAIT_CTX\s0\fR
  247. for the \fIjob\fR. \fB\s-1ASYNC_WAIT_CTX\s0\fRs contain two different ways to notify
  248. applications that a job is ready to be resumed. One is a \*(L"wait\*(R" file
  249. descriptor, and the other is a \*(L"callback\*(R" mechanism.
  250. .PP
  251. The \*(L"wait\*(R" file descriptor associated with \fB\s-1ASYNC_WAIT_CTX\s0\fR is used for
  252. applications to wait for the file descriptor to be ready for \*(L"read\*(R" using a
  253. system function call such as select or poll (being ready for \*(L"read\*(R" indicates
  254. that the job should be resumed). If no file descriptor is made available then
  255. an application will have to periodically \*(L"poll\*(R" the job by attempting to restart
  256. it to see if it is ready to continue.
  257. .PP
  258. \&\fB\s-1ASYNC_WAIT_CTX\s0\fRs also have a \*(L"callback\*(R" mechanism to notify applications. The
  259. callback is set by an application, and it will be automatically called when an
  260. engine completes a cryptography operation, so that the application can resume
  261. the paused work flow without polling. An engine could be written to look whether
  262. the callback has been set. If it has then it would use the callback mechanism
  263. in preference to the file descriptor notifications. If a callback is not set
  264. then the engine may use file descriptor based notifications. Please note that
  265. not all engines may support the callback mechanism, so the callback may not be
  266. used even if it has been set. See \fBASYNC_WAIT_CTX_new()\fR for more details.
  267. .PP
  268. The \fBASYNC_block_pause()\fR function will prevent the currently active job from
  269. pausing. The block will remain in place until a subsequent call to
  270. \&\fBASYNC_unblock_pause()\fR. These functions can be nested, e.g. if you call
  271. \&\fBASYNC_block_pause()\fR twice then you must call \fBASYNC_unblock_pause()\fR twice in
  272. order to re-enable pausing. If these functions are called while there is no
  273. currently active job then they have no effect. This functionality can be useful
  274. to avoid deadlock scenarios. For example during the execution of an \fB\s-1ASYNC_JOB\s0\fR
  275. an application acquires a lock. It then calls some cryptographic function which
  276. invokes \fBASYNC_pause_job()\fR. This returns control back to the code that created
  277. the \fB\s-1ASYNC_JOB\s0\fR. If that code then attempts to acquire the same lock before
  278. resuming the original job then a deadlock can occur. By calling
  279. \&\fBASYNC_block_pause()\fR immediately after acquiring the lock and
  280. \&\fBASYNC_unblock_pause()\fR immediately before releasing it then this situation cannot
  281. occur.
  282. .PP
  283. Some platforms cannot support async operations. The \fBASYNC_is_capable()\fR function
  284. can be used to detect whether the current platform is async capable or not.
  285. .PP
  286. Custom memory allocation functions are supported for the \s-1POSIX\s0 platform.
  287. Custom memory allocation functions allow alternative methods of allocating
  288. stack memory such as mmap, or using stack memory from the current thread.
  289. Using an ASYNC_stack_alloc_fn callback also allows manipulation of the stack
  290. size, which defaults to 32k.
  291. The stack size can be altered by allocating a stack of a size different to
  292. the requested size, and passing back the new stack size in the callback's \fI*num\fR
  293. parameter.
  294. .SH "RETURN VALUES"
  295. .IX Header "RETURN VALUES"
  296. ASYNC_init_thread returns 1 on success or 0 otherwise.
  297. .PP
  298. ASYNC_start_job returns one of \fB\s-1ASYNC_ERR\s0\fR, \fB\s-1ASYNC_NO_JOBS\s0\fR, \fB\s-1ASYNC_PAUSE\s0\fR or
  299. \&\fB\s-1ASYNC_FINISH\s0\fR as described above.
  300. .PP
  301. ASYNC_pause_job returns 0 if an error occurred or 1 on success. If called when
  302. not within the context of an \fB\s-1ASYNC_JOB\s0\fR then this is counted as success so 1
  303. is returned.
  304. .PP
  305. ASYNC_get_current_job returns a pointer to the currently executing \fB\s-1ASYNC_JOB\s0\fR
  306. or \s-1NULL\s0 if not within the context of a job.
  307. .PP
  308. \&\fBASYNC_get_wait_ctx()\fR returns a pointer to the \fB\s-1ASYNC_WAIT_CTX\s0\fR for the job.
  309. .PP
  310. \&\fBASYNC_is_capable()\fR returns 1 if the current platform is async capable or 0
  311. otherwise.
  312. .PP
  313. ASYNC_set_mem_functions returns 1 if custom stack allocators are supported by
  314. the current platform and no allocations have already occurred or 0 otherwise.
  315. .SH "NOTES"
  316. .IX Header "NOTES"
  317. On Windows platforms the \fI<openssl/async.h>\fR header is dependent on some
  318. of the types customarily made available by including \fI<windows.h>\fR. The
  319. application developer is likely to require control over when the latter
  320. is included, commonly as one of the first included headers. Therefore,
  321. it is defined as an application developer's responsibility to include
  322. \&\fI<windows.h>\fR prior to \fI<openssl/async.h>\fR.
  323. .SH "EXAMPLES"
  324. .IX Header "EXAMPLES"
  325. The following example demonstrates how to use most of the core async APIs:
  326. .PP
  327. .Vb 7
  328. \& #ifdef _WIN32
  329. \& # include <windows.h>
  330. \& #endif
  331. \& #include <stdio.h>
  332. \& #include <unistd.h>
  333. \& #include <openssl/async.h>
  334. \& #include <openssl/crypto.h>
  335. \&
  336. \& int unique = 0;
  337. \&
  338. \& void cleanup(ASYNC_WAIT_CTX *ctx, const void *key, OSSL_ASYNC_FD r, void *vw)
  339. \& {
  340. \& OSSL_ASYNC_FD *w = (OSSL_ASYNC_FD *)vw;
  341. \&
  342. \& close(r);
  343. \& close(*w);
  344. \& OPENSSL_free(w);
  345. \& }
  346. \&
  347. \& int jobfunc(void *arg)
  348. \& {
  349. \& ASYNC_JOB *currjob;
  350. \& unsigned char *msg;
  351. \& int pipefds[2] = {0, 0};
  352. \& OSSL_ASYNC_FD *wptr;
  353. \& char buf = \*(AqX\*(Aq;
  354. \&
  355. \& currjob = ASYNC_get_current_job();
  356. \& if (currjob != NULL) {
  357. \& printf("Executing within a job\en");
  358. \& } else {
  359. \& printf("Not executing within a job \- should not happen\en");
  360. \& return 0;
  361. \& }
  362. \&
  363. \& msg = (unsigned char *)arg;
  364. \& printf("Passed in message is: %s\en", msg);
  365. \&
  366. \& if (pipe(pipefds) != 0) {
  367. \& printf("Failed to create pipe\en");
  368. \& return 0;
  369. \& }
  370. \& wptr = OPENSSL_malloc(sizeof(OSSL_ASYNC_FD));
  371. \& if (wptr == NULL) {
  372. \& printf("Failed to malloc\en");
  373. \& return 0;
  374. \& }
  375. \& *wptr = pipefds[1];
  376. \& ASYNC_WAIT_CTX_set_wait_fd(ASYNC_get_wait_ctx(currjob), &unique,
  377. \& pipefds[0], wptr, cleanup);
  378. \&
  379. \& /*
  380. \& * Normally some external event would cause this to happen at some
  381. \& * later point \- but we do it here for demo purposes, i.e.
  382. \& * immediately signalling that the job is ready to be woken up after
  383. \& * we return to main via ASYNC_pause_job().
  384. \& */
  385. \& write(pipefds[1], &buf, 1);
  386. \&
  387. \& /* Return control back to main */
  388. \& ASYNC_pause_job();
  389. \&
  390. \& /* Clear the wake signal */
  391. \& read(pipefds[0], &buf, 1);
  392. \&
  393. \& printf ("Resumed the job after a pause\en");
  394. \&
  395. \& return 1;
  396. \& }
  397. \&
  398. \& int main(void)
  399. \& {
  400. \& ASYNC_JOB *job = NULL;
  401. \& ASYNC_WAIT_CTX *ctx = NULL;
  402. \& int ret;
  403. \& OSSL_ASYNC_FD waitfd;
  404. \& fd_set waitfdset;
  405. \& size_t numfds;
  406. \& unsigned char msg[13] = "Hello world!";
  407. \&
  408. \& printf("Starting...\en");
  409. \&
  410. \& ctx = ASYNC_WAIT_CTX_new();
  411. \& if (ctx == NULL) {
  412. \& printf("Failed to create ASYNC_WAIT_CTX\en");
  413. \& abort();
  414. \& }
  415. \&
  416. \& for (;;) {
  417. \& switch (ASYNC_start_job(&job, ctx, &ret, jobfunc, msg, sizeof(msg))) {
  418. \& case ASYNC_ERR:
  419. \& case ASYNC_NO_JOBS:
  420. \& printf("An error occurred\en");
  421. \& goto end;
  422. \& case ASYNC_PAUSE:
  423. \& printf("Job was paused\en");
  424. \& break;
  425. \& case ASYNC_FINISH:
  426. \& printf("Job finished with return value %d\en", ret);
  427. \& goto end;
  428. \& }
  429. \&
  430. \& /* Wait for the job to be woken */
  431. \& printf("Waiting for the job to be woken up\en");
  432. \&
  433. \& if (!ASYNC_WAIT_CTX_get_all_fds(ctx, NULL, &numfds)
  434. \& || numfds > 1) {
  435. \& printf("Unexpected number of fds\en");
  436. \& abort();
  437. \& }
  438. \& ASYNC_WAIT_CTX_get_all_fds(ctx, &waitfd, &numfds);
  439. \& FD_ZERO(&waitfdset);
  440. \& FD_SET(waitfd, &waitfdset);
  441. \& select(waitfd + 1, &waitfdset, NULL, NULL, NULL);
  442. \& }
  443. \&
  444. \& end:
  445. \& ASYNC_WAIT_CTX_free(ctx);
  446. \& printf("Finishing\en");
  447. \&
  448. \& return 0;
  449. \& }
  450. .Ve
  451. .PP
  452. The expected output from executing the above example program is:
  453. .PP
  454. .Vb 8
  455. \& Starting...
  456. \& Executing within a job
  457. \& Passed in message is: Hello world!
  458. \& Job was paused
  459. \& Waiting for the job to be woken up
  460. \& Resumed the job after a pause
  461. \& Job finished with return value 1
  462. \& Finishing
  463. .Ve
  464. .SH "SEE ALSO"
  465. .IX Header "SEE ALSO"
  466. \&\fBcrypto\fR\|(7), \fBERR_print_errors\fR\|(3)
  467. .SH "HISTORY"
  468. .IX Header "HISTORY"
  469. ASYNC_init_thread, ASYNC_cleanup_thread,
  470. ASYNC_start_job, ASYNC_pause_job, ASYNC_get_current_job, \fBASYNC_get_wait_ctx()\fR,
  471. \&\fBASYNC_block_pause()\fR, \fBASYNC_unblock_pause()\fR and \fBASYNC_is_capable()\fR were first
  472. added in OpenSSL 1.1.0.
  473. .SH "COPYRIGHT"
  474. .IX Header "COPYRIGHT"
  475. Copyright 2015\-2022 The OpenSSL Project Authors. All Rights Reserved.
  476. .PP
  477. Licensed under the Apache License 2.0 (the \*(L"License\*(R"). You may not use
  478. this file except in compliance with the License. You can obtain a copy
  479. in the file \s-1LICENSE\s0 in the source distribution or at
  480. <https://www.openssl.org/source/license.html>.