main.scm 877 B

123456789101112131415161718192021
  1. (use-modules (ice-9 iconv))
  2. (define* (connect-to-unix-socket #:key (socket-path "/var/run/docker.sock"))
  3. (let ([sock-addr (make-socket-address AF_UNIX socket-path)]
  4. [sock (socket PF_UNIX SOCK_STREAM 0)])
  5. ;; socket options:
  6. ;; https://www.gnu.org/software/libc/manual/html_node/Socket_002dLevel-Options.html
  7. (setsockopt sock SOL_SOCKET SO_REUSEADDR 1)
  8. ;; usage of connect:
  9. ;; https://www.gnu.org/software/guile/manual/html_node/Network-Sockets-and-Communication.html#Network-Sockets-and-Communication
  10. ;; server side would use `bind`, `accept` and `listen`.
  11. ;; client side uses `connect` and `close`.
  12. (connect sock sock-addr)
  13. sock))
  14. ;; Syntax for a request is:
  15. ;; PROTOCOL://unix:SOCKET_PATH:ENDPOINT_PATH
  16. ;; https://www.gnu.org/software/guile/docs/docs-2.0/guile-ref/Network-Sockets-and-Communication.html
  17. ;; (send sock message)