unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Using UNIX sockets
@ 2019-06-01 10:53 Zelphir Kaltstahl
  0 siblings, 0 replies; only message in thread
From: Zelphir Kaltstahl @ 2019-06-01 10:53 UTC (permalink / raw)
  To: Guile User

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



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-06-01 10:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-01 10:53 Using UNIX sockets Zelphir Kaltstahl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).