1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Control Sat Jul 25 00:26:45 2020 +0200
1.3 @@ -0,0 +1,3 @@
1.4 +requires: libc libfsclient
1.5 +provides: pipetest
1.6 +maintainer: paul@boddie.org.uk
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/Makefile Sat Jul 25 00:26:45 2020 +0200
2.3 @@ -0,0 +1,11 @@
2.4 +PKGDIR ?= .
2.5 +L4DIR ?= $(PKGDIR)/../..
2.6 +
2.7 +TARGET = pipetest
2.8 +MODE = shared
2.9 +
2.10 +SRC_CC = pipetest.cc
2.11 +
2.12 +REQUIRES_LIBS = libstdc++ l4re_c l4re_c-util libfsclient
2.13 +
2.14 +include $(L4DIR)/mk/prog.mk
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/conf/pipetest.cfg Sat Jul 25 00:26:45 2020 +0200
3.3 @@ -0,0 +1,27 @@
3.4 +-- vim:set ft=lua:
3.5 +
3.6 +local L4 = require("L4");
3.7 +
3.8 +local l = L4.default_loader;
3.9 +
3.10 +-- Pipe server.
3.11 +
3.12 +local pipeserver = l:new_channel();
3.13 +
3.14 +l:start({
3.15 + caps = {
3.16 + export = pipeserver:svr(),
3.17 + },
3.18 + log = { "pipeserver", "y" },
3.19 + },
3.20 + "rom/pipeserver");
3.21 +
3.22 +-- Client programs.
3.23 +
3.24 +l:start({
3.25 + caps = {
3.26 + pipes = pipeserver,
3.27 + },
3.28 + log = { "pipetest", "g" },
3.29 + },
3.30 + "rom/pipetest");
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/conf/pipetest.list Sat Jul 25 00:26:45 2020 +0200
4.3 @@ -0,0 +1,27 @@
4.4 +entry pipetest
4.5 +roottask moe rom/pipetest.cfg
4.6 +module pipetest.cfg
4.7 +module l4re
4.8 +module ned
4.9 +module pipetest
4.10 +module pipeserver
4.11 +module lib4re-c.so
4.12 +module lib4re-c-util.so
4.13 +module lib4re.so
4.14 +module lib4re-util.so
4.15 +module libc_be_l4refile.so
4.16 +module libc_be_l4re.so
4.17 +module libc_be_socket_noop.so
4.18 +module libc_support_misc.so
4.19 +module libdl.so
4.20 +module libfsclient.so
4.21 +module libfsserver.so
4.22 +module libipc.so
4.23 +module libl4sys-direct.so
4.24 +module libl4sys.so
4.25 +module libl4util.so
4.26 +module libld-l4.so
4.27 +module libpthread.so
4.28 +module libstdc++.so
4.29 +module libsupc++.so
4.30 +module libuc_c.so
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/pipetest.cc Sat Jul 25 00:26:45 2020 +0200
5.3 @@ -0,0 +1,86 @@
5.4 +/*
5.5 + * Test pipes.
5.6 + *
5.7 + * Copyright (C) 2020 Paul Boddie <paul@boddie.org.uk>
5.8 + *
5.9 + * This program is free software; you can redistribute it and/or
5.10 + * modify it under the terms of the GNU General Public License as
5.11 + * published by the Free Software Foundation; either version 2 of
5.12 + * the License, or (at your option) any later version.
5.13 + *
5.14 + * This program is distributed in the hope that it will be useful,
5.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5.17 + * GNU General Public License for more details.
5.18 + *
5.19 + * You should have received a copy of the GNU General Public License
5.20 + * along with this program; if not, write to the Free Software
5.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
5.22 + * Boston, MA 02110-1301, USA
5.23 + */
5.24 +
5.25 +#include <l4/re/env.h>
5.26 +
5.27 +#include <stdio.h>
5.28 +#include <string.h>
5.29 +
5.30 +#include <fsclient/client.h>
5.31 +
5.32 +
5.33 +
5.34 +static void show(char *s, unsigned long length)
5.35 +{
5.36 + char buffer[length + 1];
5.37 +
5.38 + memcpy(buffer, s, length);
5.39 + buffer[length] = '\0';
5.40 + printf("Received (%ld): %s\n", length, buffer);
5.41 +}
5.42 +
5.43 +int main(void)
5.44 +{
5.45 + file_descriptor_t *reader, *writer;
5.46 + char buffer[128];
5.47 + ssize_t nread, tread;
5.48 + ssize_t nwritten;
5.49 +
5.50 + if (client_pipe(&reader, &writer))
5.51 + {
5.52 + printf("Failed to open pipe.\n");
5.53 + return 1;
5.54 + }
5.55 +
5.56 + printf("Read pipe: %ld\n", reader->obj.buffer.size);
5.57 + printf("Write pipe: %ld\n", writer->obj.buffer.size);
5.58 +
5.59 + printf("Read address: %p\n", reader->obj.buffer.addr);
5.60 + printf("Write address: %p\n", writer->obj.buffer.addr);
5.61 +
5.62 + nwritten = 0;
5.63 + while (nwritten < 8192)
5.64 + {
5.65 + memset(buffer, (int) 'a' + ((nwritten / 128) % 26), 128);
5.66 + nwritten += client_write(writer, buffer, 128);
5.67 + }
5.68 +
5.69 + printf("Written: %ld\n", nwritten);
5.70 + client_flush(writer);
5.71 +
5.72 + tread = 0;
5.73 +
5.74 + do
5.75 + {
5.76 + nread = client_read(reader, buffer, 128);
5.77 + show(buffer, nread);
5.78 + tread += nread;
5.79 + }
5.80 + while (nread);
5.81 +
5.82 + printf("Read: %ld\n", tread);
5.83 +
5.84 + client_close(reader);
5.85 + client_close(writer);
5.86 +
5.87 + printf("Terminating.\n");
5.88 + return 0;
5.89 +}