Created
August 10, 2020 19:31
-
-
Save bakpakin/15bb384114f0e80b5bf89db0dc0312f3 to your computer and use it in GitHub Desktop.
Broken pipe handling in server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(with [conn (net/connect "127.0.0.1" "8000")] | |
(printf "Connected to %q!" conn) | |
(:write conn "Echo...") | |
(print "Wrote to connection...") | |
(def res (:read conn 1024)) | |
(print "client done") | |
(pp res)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Start server | |
janet server.janet & | |
SERVER_PID=$! | |
sleep 1 | |
# Start client | |
janet client.janet & | |
CLIENT_PID=$! | |
# Wait a bit, and then kill client before it completes to trigger broken pipe. | |
sleep 0.5 | |
kill -SIGINT $CLIENT_PID | |
wait $SERVER_PID | |
echo "Done" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(net/server | |
"127.0.0.1" "8000" | |
(fn handler | |
[stream] | |
(defer (:close stream) | |
(def b @"") | |
(while (:read stream 1024 b) | |
(for i 0 5 | |
(os/sleep 2) | |
(print "write return value " i ": " (:write stream b)))) | |
(os/exit 0)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment