Commit 2b2c78d4 authored by Matt Caswell's avatar Matt Caswell
Browse files

Swap to using proper windows pipes



We were using _pipe to create a pipe on windows. This uses the "int" type
for its file descriptor for compatibility. However most windows functions
expect to use a "HANDLE". Probably we could get away with just casting but
it seems more robust to use the proper type and main stream windows
functions.

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
parent e38565f5
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -91,17 +91,17 @@ int async_pool_can_grow(void) {
    return 0;
    return 0;
}
}


int async_pipe(int *pipefds)
int async_pipe(OSSL_ASYNC_FD *pipefds)
{
{
    return -1;
    return -1;
}
}


int async_write1(int fd, const void *buf)
int async_write1(OSSL_ASYNC_FD fd, const void *buf)
{
{
    return -1;
    return -1;
}
}


int async_read1(int fd, void *buf)
int async_read1(OSSL_ASYNC_FD fd, void *buf)
{
{
    return -1;
    return -1;
}
}
+3 −3
Original line number Original line Diff line number Diff line
@@ -95,7 +95,7 @@ void async_fibre_free(async_fibre *fibre)
        OPENSSL_free(fibre->fibre.uc_stack.ss_sp);
        OPENSSL_free(fibre->fibre.uc_stack.ss_sp);
}
}


int async_pipe(int *pipefds)
int async_pipe(OSSL_ASYNC_FD *pipefds)
{
{
    if (pipe(pipefds) == 0)
    if (pipe(pipefds) == 0)
        return 1;
        return 1;
@@ -103,7 +103,7 @@ int async_pipe(int *pipefds)
    return 0;
    return 0;
}
}


int async_write1(int fd, const void *buf)
int async_write1(OSSL_ASYNC_FD fd, const void *buf)
{
{
    if (write(fd, buf, 1) > 0)
    if (write(fd, buf, 1) > 0)
        return 1;
        return 1;
@@ -111,7 +111,7 @@ int async_write1(int fd, const void *buf)
    return 0;
    return 0;
}
}


int async_read1(int fd, void *buf)
int async_read1(OSSL_ASYNC_FD fd, void *buf)
{
{
    if (read(fd, buf, 1) > 0)
    if (read(fd, buf, 1) > 0)
        return 1;
        return 1;
+12 −8
Original line number Original line Diff line number Diff line
@@ -87,25 +87,29 @@ VOID CALLBACK async_start_func_win(PVOID unused)
    async_start_func();
    async_start_func();
}
}


int async_pipe(int *pipefds)
int async_pipe(OSSL_ASYNC_FD *pipefds)
{
{
    if (_pipe(pipefds, 256, _O_BINARY) == 0)
    if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0)
        return 1;

        return 0;
        return 0;

    return 1;
}
}


int async_write1(int fd, const void *buf)
int async_write1(OSSL_ASYNC_FD fd, const void *buf)
{
{
    if (_write(fd, buf, 1) > 0)
    DWORD numwritten = 0;

    if (WriteFile(fd, buf, 1, &numwritten, NULL) && numwritten == 1)
        return 1;
        return 1;


    return 0;
    return 0;
}
}


int async_read1(int fd, void *buf)
int async_read1(OSSL_ASYNC_FD fd, void *buf)
{
{
    if (_read(fd, buf, 1) > 0)
    DWORD numread = 0;

    if (ReadFile(fd, buf, 1, &numread, NULL) && numread == 1)
        return 1;
        return 1;


    return 0;
    return 0;
+2 −2
Original line number Original line Diff line number Diff line
@@ -109,7 +109,7 @@ static int async_ctx_free(void)
static ASYNC_JOB *async_job_new(void)
static ASYNC_JOB *async_job_new(void)
{
{
    ASYNC_JOB *job = NULL;
    ASYNC_JOB *job = NULL;
    int pipefds[2];
    OSSL_ASYNC_FD pipefds[2];


    job = OPENSSL_malloc(sizeof (ASYNC_JOB));
    job = OPENSSL_malloc(sizeof (ASYNC_JOB));
    if (job == NULL) {
    if (job == NULL) {
@@ -387,7 +387,7 @@ ASYNC_JOB *ASYNC_get_current_job(void)
    return ctx->currjob;
    return ctx->currjob;
}
}


int ASYNC_get_wait_fd(ASYNC_JOB *job)
OSSL_ASYNC_FD ASYNC_get_wait_fd(ASYNC_JOB *job)
{
{
    return job->wait_fd;
    return job->wait_fd;
}
}
+5 −5
Original line number Original line Diff line number Diff line
@@ -73,8 +73,8 @@ struct async_job_st {
    int ret;
    int ret;
    int status;
    int status;
    int wake_set;
    int wake_set;
    int wait_fd;
    OSSL_ASYNC_FD wait_fd;
    int wake_fd;
    OSSL_ASYNC_FD wake_fd;
};
};


DECLARE_STACK_OF(ASYNC_JOB)
DECLARE_STACK_OF(ASYNC_JOB)
@@ -88,6 +88,6 @@ void async_release_job_to_pool(ASYNC_JOB *job);
size_t async_pool_max_size(void);
size_t async_pool_max_size(void);
void async_release_pool(void);
void async_release_pool(void);
int async_pool_can_grow(void);
int async_pool_can_grow(void);
int async_pipe(int *pipefds);
int async_pipe(OSSL_ASYNC_FD *pipefds);
int async_write1(int fd, const void *buf);
int async_write1(OSSL_ASYNC_FD fd, const void *buf);
int async_read1(int fd, void *buf);
int async_read1(OSSL_ASYNC_FD fd, void *buf);
Loading