diff --git a/crystal/makefile b/crystal/makefile index 9862085..b4fce25 100644 --- a/crystal/makefile +++ b/crystal/makefile @@ -9,8 +9,8 @@ CRYSTAL_BUILD_OPTIONS += $(CRYSTAL_STATIC_BUILD) LIBIPC_RUNDIR ?= /tmp/libipc-run -all: build -build: build-pongd build-pong +all: run +build: build-pongd build-pong build-input2ipc build-fromipc run: run-pongd include ../mk/makefile.utils @@ -27,3 +27,11 @@ build-pong: run-pong: $(LD_LIBRARY_PATH) ./bin/pong + +-include makefile.user + +build-input2ipc: + $(CRYSTAL_LIBRARY_PATH) shards build input2ipc $(CRYSTAL_BUILD_OPTIONS) + +build-fromipc: + $(CRYSTAL_LIBRARY_PATH) shards build fromipc $(CRYSTAL_BUILD_OPTIONS) diff --git a/crystal/shard.yml b/crystal/shard.yml index 58f7bf4..9fcba59 100644 --- a/crystal/shard.yml +++ b/crystal/shard.yml @@ -13,11 +13,20 @@ targets: pongd: main: src/pongd.cr + # Those two examples show what it is required to serialize and deserialize + # an IPC message, which only is to add (and remove) the message length in + # the first 4 bytes of the message. + # They can be used to handle messages from a simple shell script. + fromipc: + main: src/fromipc.cr + input2ipc: + main: src/input2ipc.cr + dependencies: ipc: git: https://git.baguette.netlib.re/Baguette/ipc.cr branch: master -crystal: 1.7.1 +crystal: 1.8.2 license: ISC diff --git a/crystal/src/fromipc.cr b/crystal/src/fromipc.cr new file mode 100644 index 0000000..e2d9447 --- /dev/null +++ b/crystal/src/fromipc.cr @@ -0,0 +1,4 @@ +# Read an IPC network packet and remove the first 4 bytes. +buffer = Bytes.new 1_000_000 +len = STDIN.read buffer +STDOUT.write buffer[4.. len -1] diff --git a/crystal/src/input2ipc.cr b/crystal/src/input2ipc.cr new file mode 100644 index 0000000..53beb6f --- /dev/null +++ b/crystal/src/input2ipc.cr @@ -0,0 +1,5 @@ +# Input to IPC network packets. +buffer = Bytes.new 1_000_000 +len = STDIN.read buffer +STDOUT.write_bytes len, IO::ByteFormat::BigEndian +STDOUT.write buffer[0.. len -1]