diff options
Diffstat (limited to 'assuan/assuan-pipe-server.c')
| -rw-r--r-- | assuan/assuan-pipe-server.c | 28 | 
1 files changed, 25 insertions, 3 deletions
diff --git a/assuan/assuan-pipe-server.c b/assuan/assuan-pipe-server.c index ba269b04..beff9a3e 100644 --- a/assuan/assuan-pipe-server.c +++ b/assuan/assuan-pipe-server.c @@ -22,9 +22,14 @@  #include <stdlib.h>  #include <stdio.h>  #include <unistd.h> +#ifdef HAVE_W32_SYSTEM +#include <windows.h> +#include <fcntl.h> +#endif  #include "assuan-defs.h" +  static void  deinit_pipe_server (ASSUAN_CONTEXT ctx)  { @@ -69,7 +74,6 @@ _assuan_new_context (ASSUAN_CONTEXT *r_ctx)    ctx->io = &io;    ctx->listen_fd = -1; -  ctx->client_pid = (pid_t)-1;    /* Use the pipe server handler as a default.  */    ctx->deinit_handler = deinit_pipe_server;    ctx->accept_handler = accept_connection; @@ -84,7 +88,6 @@ _assuan_new_context (ASSUAN_CONTEXT *r_ctx)  } -  int  assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2])  { @@ -94,11 +97,30 @@ assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2])    if (!rc)      {        ASSUAN_CONTEXT ctx = *r_ctx; +      const char *s; +      unsigned long ul;        ctx->is_server = 1; -      ctx->inbound.fd = filedes[0]; +#ifdef HAVE_W32_SYSTEM +      /* MS Windows has so many different types of handle that one +         needs to tranlsate them at many place forth and back.  Also +         make sure that the fiel descriptos are in binary mode.  */ +      setmode (filedes[0], O_BINARY); +      setmode (filedes[1], O_BINARY); +      ctx->inbound.fd  = _get_osfhandle (filedes[0]); +      ctx->outbound.fd = _get_osfhandle (filedes[1]); +#else +      ctx->inbound.fd  = filedes[0];        ctx->outbound.fd = filedes[1]; +#endif        ctx->pipe_mode = 1; + +      s = getenv ("_assuan_pipe_connect_pid"); +      if (s && (ul=strtoul (s, NULL, 10)) && ul) +        ctx->pid = (pid_t)ul; +      else +        ctx->pid = (pid_t)-1; +      }    return rc;  }  | 
