From 1b34f889f90cd879367f233c90d98b18dd47d338 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 14 Jan 2004 18:08:39 +0000 Subject: initial commit git-svn-id: file:///home/lennart/svn/public/bidilink/trunk@3 9cde1c1d-e4d0-0310-8a68-bf217395ea82 --- src/stream.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/stream.c (limited to 'src/stream.c') diff --git a/src/stream.c b/src/stream.c new file mode 100644 index 0000000..80ad2c2 --- /dev/null +++ b/src/stream.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include + +#include "stream.h" +#include "std.h" +#include "exec.h" +#include "client-tty.h" +#include "server-tty.h" +#include "client-tcp.h" +#include "server-tcp.h" +#include "client-unix.h" +#include "server-unix.h" + +struct stream* stream_open(const char *spec) { + if (!spec || !strncmp(spec, "std:",4)) + return stream_std(spec+4); + else if (!strncmp(spec, "exec:", 5)) + return stream_exec(spec+5); + else if (!strncmp(spec, "tty:", 4)) + return stream_client_tty(spec+4); + else if (!strncmp(spec, "pty:", 4)) + return stream_server_tty(spec+4); + else if (!strncmp(spec, "tcp-client:", 11)) + return stream_client_tcp(spec+11); + else if (!strncmp(spec, "tcp-server:", 11)) + return stream_server_tcp(spec+11); + else if (!strncmp(spec, "unix-client:", 12)) + return stream_client_unix(spec+12); + else if (!strncmp(spec, "unix-server:", 12)) + return stream_server_unix(spec+12); + + fprintf(stderr, "Found no stream implementation for '%s'.\n", spec); + return NULL; +} + + +void stream_close(struct stream *s) { + assert(s); + + if (s->destruct) + s->destruct(s); + + if (s->input_fd != -1) + close(s->input_fd); + if (s->output_fd != -1 && s->input_fd != s->output_fd) + close(s->output_fd); + + free(s); +} -- cgit