Issues with ASYNC_pause_job() wake up
Valerio Di Gregorio (vadigreg)
vadigreg at cisco.com
Tue Feb 11 13:05:19 UTC 2020
Hello,
This is my first post here. I need help with ASYNC_pause_job(). I'm writing an async engine to delegate certificate validation to a different process. Validation happens asynchronously through IPCs. To explain what I'm doing I'll use some "pseudo" code:
// this happens in process #1
ctx = OPENSSL_malloc(sizeof(async_engine_ctx_t));
ctx->job = ASYNC_get_current_job()
ctx->wait_ctx = ASYNC_get_wait_ctx(job)
pipe(ctx->fds);
ASYNC_WAIT_CTX_set_wait_fd(ctx->wait_ctx, ctx, ctx->fds[0], ctx, async_engine_cleanup_cb);
async_validation_request(ctx->fds[1], cert, cert_len); // this starts async validation via IPC
printf("pause")
ASYNC_pause_job();
printf("resume")
read(ctx->fds[0], &validation_result, sizeof(validation_result));
For simplicity I omitted error checks (in my runs I have no error in any of the mentioned functions). When async response comes in, via IPC, what I do is:
// this happens in process #1
write(write_fd, &status, sizeof(status)); // I verified write_fd == ctx->fds[1]
I see 2 different issues with this:
1. ASYNC_pause_job() can wake up before write(). It will then block on the read(), which is too bad in my single-threaded code.
2. I fixed case 1 by making read() non-blocking, I then run ASYNC_pause_job() again and again until write() is actually performed. So now I hit another issue. Time between printf("pause") and write() is ~100/200 milliseconds. However time between write() and printf("resume") is usually ~4.5 seconds and this way too much.
Is there a reliable way (only when data is really ready) and a prompt way (in order of micro/milli-seconds) to wake up from ASYNC_pause_job()?
Many thanks, any help would be much appreciated.
Kind Regards,
Valerio Di Gregorio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mta.openssl.org/pipermail/openssl-users/attachments/20200211/db222c40/attachment.html>
More information about the openssl-users
mailing list