diff options
Diffstat (limited to '')
-rw-r--r-- | src/assuan-pipe-server.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c index 82bb322..73d9de2 100644 --- a/src/assuan-pipe-server.c +++ b/src/assuan-pipe-server.c @@ -21,6 +21,7 @@ #include <config.h> #include <stdlib.h> #include <stdio.h> +#include <unistd.h> #include "assuan-defs.h" @@ -44,12 +45,34 @@ finish_connection (ASSUAN_CONTEXT ctx) return 0; } +/* Read from the pipe server. */ +static ssize_t +pipe_reader (ASSUAN_CONTEXT ctx, void *buf, size_t buflen) +{ +#pragma weak pth_read + extern ssize_t pth_read (int, void *, size_t); + + return (pth_read ? pth_read : read) (ctx->inbound.fd, buf, buflen); +} + +/* Write to the pipe server. */ +static ssize_t +pipe_writer (ASSUAN_CONTEXT ctx, const void *buf, size_t buflen) +{ +#pragma weak pth_write + + extern ssize_t pth_write (int, const void *, size_t); + + return (pth_write ? pth_write : write) (ctx->outbound.fd, buf, buflen); +} /* Create a new context. Note that the handlers are set up for a pipe server/client - this way we don't need extra dummy functions */ int _assuan_new_context (ASSUAN_CONTEXT *r_ctx) { + static struct assuan_io io = { pipe_reader, pipe_writer }; + ASSUAN_CONTEXT ctx; int rc; @@ -62,10 +85,11 @@ _assuan_new_context (ASSUAN_CONTEXT *r_ctx) ctx->inbound.fd = -1; ctx->outbound.fd = -1; + ctx->io = &io; ctx->listen_fd = -1; ctx->client_pid = (pid_t)-1; - /* use the pipe server handler as a default */ + /* Use the pipe server handler as a default. */ ctx->deinit_handler = deinit_pipe_server; ctx->accept_handler = accept_connection; ctx->finish_handler = finish_connection; @@ -116,7 +140,7 @@ assuan_deinit_server (ASSUAN_CONTEXT ctx) if (ctx) { /* We use this function pointer to avoid linking other server - when not needed but still allow for a generic deinit function */ + when not needed but still allow for a generic deinit function. */ ctx->deinit_handler (ctx); ctx->deinit_handler = NULL; _assuan_release_context (ctx); |