guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using UNIX sockets


From: Zelphir Kaltstahl
Subject: Using UNIX sockets
Date: Sat, 1 Jun 2019 12:53:59 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0

Hi Guile users!

I am currently trying to communicate with a UNIX socket (UNIX socket of
Docker) using Guile.

Here is what I have so far:

(use-modules (ice-9 iconv))

(define* (connect-to-docker-socket #:key (socket-path "/var/run/docker.sock"))
  (let ([sock (socket PF_UNIX SOCK_STREAM 0)])
    (connect sock AF_UNIX "/var/run/docker.sock")
    sock))

(define (send-msg-to-socket msg sock)
  (send sock (string->bytevector msg "utf-8")))

(let ([dock-sock (connect-to-docker-socket)])
  (send-msg-to-socket (scm->json-string
                       '(("all" . #t)))
                      dock-sock))

I am not even sure, that I am sending correct data to the correct places
with this socket (because I cannot find Docker's documentation for its
UNIX socket at all …), but at least it does not give an error when
sending data and gives back the number of sent bytes, I believe.

However: How would I read any response, if there is any from Docker,
from the socket?

I tried to use the `guile-json` library and `json->scm` on the socket,
but that simply waits forever, possibly because I sent the wrong stuff
to the socket.

I am also unsure whether I am doing this correctly, because in the
Python Docker-py library at
https://github.com/docker/docker-py/blob/master/docker/transport/unixconn.py#L81
I can see, that there is something http+unix going on. So is Docker
doing HTTP over UNIX socket maybe? And how would I talk to such an API
using Guile?

I already had trouble figuring out, that I should be using protocol `0`
in `(socket PF_UNIX SOCK_STREAM 0)`, because that is labeled `IP`
instead of `UNIX` in the output of `(getprotoent)`. Only by chance I was
able to find an example of this in an old forum. But what would I use,
if I were to do HTTP over UNIX socket?

Thank you for any help!

Regards,

Zelphir



reply via email to

[Prev in Thread] Current Thread [Next in Thread]