SWI-Prolog / packages-clib

Assorted external libraries: processes, sockets, MIME, CGI, etc.
8 stars 19 forks source link

Add the ability to create Unix-domain sockets #29

Closed jamesnvc closed 4 years ago

jamesnvc commented 4 years ago

As mentioned on the Discourse.

This seems to be working for me now, although I'm not sure why the pldoc comments aren't showing up.

Tested by starting a socket with nc -lU /tmp/foo.sock in a terminal, then running

?-  unix_socket(Sock),
     unix_connect(Sock, "/tmp/foo.sock"),
     setup_call_cleanup(
         tcp_open_socket(Sock, Stream),
         format(Stream, "hello!~n", []),
          close(Stream)
       ).
JanWielemaker commented 4 years ago

This pull request has been mentioned on SWI-Prolog. There might be relevant details there:

https://swi-prolog.discourse.group/t/unix-sockets-with-swi/2123/4

jamesnvc commented 4 years ago

Test usage now looks like:

?-  unix_domain_socket(Sock),
     tcp_connect(Sock, "/tmp/foo.sock"),
     setup_call_cleanup(
         tcp_open_socket(Sock, Stream),
         format(Stream, "hello!~n", []),
          close(Stream)
       ).
JanWielemaker commented 4 years ago

Thanks. Merged after squash. Added another patch to deal with the server side and which reorganizes things a bit to reuse more code.

jamesnvc commented 4 years ago

Thanks Jan!