32 lines
1.0 KiB
Bash
Executable File
32 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# NOTE: you have to build the localserv command using `make exe` before you can use this
|
|
|
|
if [[ -z "${1-}" ]]; then
|
|
echo "provide a socket path"
|
|
exit -1
|
|
fi
|
|
|
|
# set up named pipes in same place as the socket
|
|
recv="$1.in.pipe"
|
|
resp="$1.out.pipe"
|
|
# -m=600: make the pipes user permissions only
|
|
mkfifo -m=600 $recv $resp
|
|
# they will be removed when the script exits
|
|
trap "rm -f $recv $resp" EXIT
|
|
|
|
# get input line by line (each line will be a request string)
|
|
# TODO: do note that this doesn't handle multiline requests correctly yet!
|
|
while read -r line; do
|
|
# do whatever you want with line here and just write it to stdout
|
|
# this example just capitalizes everything
|
|
# the server will send back the first full line (i.e. up to a newline) it receives
|
|
echo $line | tr a-z A-Z;
|
|
# this sets up the stdin & stdout to our pipes and
|
|
# backgrounds the process so it can run at the same time as the server
|
|
done <$recv >$resp &
|
|
|
|
# run the server, hooked up to the pipes and at the socket address the user gave
|
|
bin/localserv server -a $1 >$recv <$resp
|