Implement windows async pool and notify support

Port the async pool and notify code to windows.

Reviewed-by: Rich Salz <rsalz@openssl.org>
This commit is contained in:
Matt Caswell
2015-09-16 23:43:45 +01:00
parent 5e6f9775a9
commit d63de0ebff
6 changed files with 121 additions and 13 deletions

View File

@@ -56,7 +56,13 @@
#ifdef ASYNC_WIN
# include <windows.h>
# include "cryptlib.h"
# include "internal/cryptlib.h"
struct winpool {
STACK_OF(ASYNC_JOB) *pool;
size_t curr_size;
size_t max_size;
};
void ASYNC_start_func(void);
@@ -81,4 +87,94 @@ VOID CALLBACK ASYNC_start_func_win(PVOID unused)
ASYNC_start_func();
}
int async_pipe(int *pipefds)
{
if (_pipe(pipefds, 256, _O_BINARY) == 0)
return 1;
return 0;
}
int async_write1(int fd, const void *buf)
{
if (_write(fd, buf, 1) > 0)
return 1;
return 0;
}
int async_read1(int fd, void *buf)
{
if (_read(fd, buf, 1) > 0)
return 1;
return 0;
}
STACK_OF(ASYNC_JOB) *async_get_pool(void)
{
struct winpool *pool;
pool = (struct winpool *)
CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL);
return pool->pool;
}
int async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size,
size_t max_size)
{
struct winpool *pool;
pool = OPENSSL_malloc(sizeof *pool);
if (!pool)
return 0;
pool->pool = poolin;
pool->curr_size = curr_size;
pool->max_size = max_size;
CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL, (void *)pool);
return 1;
}
void async_increment_pool_size(void)
{
struct winpool *pool;
pool = (struct winpool *)
CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL);
pool->curr_size++;
}
void async_release_job_to_pool(ASYNC_JOB *job)
{
struct winpool *pool;
pool = (struct winpool *)
CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL);
sk_ASYNC_JOB_push(pool->pool, job);
}
size_t async_pool_max_size(void)
{
struct winpool *pool;
pool = (struct winpool *)
CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL);
return pool->max_size;
}
void async_release_pool(void)
{
struct winpool *pool;
pool = (struct winpool *)
CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL);
sk_ASYNC_JOB_free(pool->pool);
OPENSSL_free(pool);
CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL, NULL);
}
int async_pool_can_grow(void)
{
struct winpool *pool;
pool = (struct winpool *)
CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_POOL);
return (pool->max_size == 0) || (pool->curr_size < pool->max_size);
}
#endif