Swap to using proper windows pipes
[openssl.git] / crypto / async / arch / async_win.c
index 2afa306bc0c5ee21b72f66e46ed31912e5cedf63..9841a9ca929aa8317f77bfd7c19559407cb07602 100644 (file)
@@ -64,15 +64,15 @@ struct winpool {
     size_t max_size;
 };
 
-void ASYNC_start_func(void);
+void async_start_func(void);
 
-int ASYNC_FIBRE_init_dispatcher(ASYNC_FIBRE *fibre)
+int async_fibre_init_dispatcher(async_fibre *fibre)
 {
     LPVOID dispatcher;
 
     dispatcher =
         (LPVOID) CRYPTO_get_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_DISPATCH);
-    if (!dispatcher) {
+    if (dispatcher == NULL) {
         fibre->fibre = ConvertThreadToFiber(NULL);
         CRYPTO_set_thread_local(CRYPTO_THREAD_LOCAL_ASYNC_DISPATCH,
                                 (void *)fibre->fibre);
@@ -82,30 +82,34 @@ int ASYNC_FIBRE_init_dispatcher(ASYNC_FIBRE *fibre)
     return 1;
 }
 
-VOID CALLBACK ASYNC_start_func_win(PVOID unused)
+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)
-        return 1;
+    if (CreatePipe(&pipefds[0], &pipefds[1], NULL, 256) == 0)
+        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 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 0;
@@ -125,7 +129,7 @@ int async_set_pool(STACK_OF(ASYNC_JOB) *poolin, size_t curr_size,
 {
     struct winpool *pool;
     pool = OPENSSL_malloc(sizeof *pool);
-    if (!pool)
+    if (pool == NULL)
         return 0;
 
     pool->pool = poolin;