8

I'd like to communicate with mpv using Unix sockets, but Perl 6 doesn't offer any high level interface for doing that. So I thought I could write a little module for that, started digging deeper, found the implementation of IO::Socket::INET, and learned about the NQP ops nqp::socket and nqp::connect.

However, I couldn't find any mention of those in the NQP operations list, and they seem to be quite distinct from the traditional BSD socket API. Hence I'd like to ask: are those two able to create a Unix socket and connect to it? If so, how? Or is there perhaps another way?

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
Ramillies
  • 181
  • 2

1 Answers1

3

I think the best way right now is to use the NativeCall interface to call the C level functions. There are some old design documentation that suggest an IO::Socket::UNIX was thought about. But it's not made it into contemporary releases of the language specification (yet).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Matt Oates
  • 778
  • 4
  • 6
  • 3
    Thanks, I solved it by using `IO::Socket::UNIX` from Perl 5 by means of `Inline::Perl5` which works like charm. I just wanted to know if there is a native solution. – Ramillies Sep 15 '17 at 17:08
  • 1
    I have been planning to add pipes and unix sockets added, but that will require moar hacking (which isn't quite trivial). – Leon Timmermans Sep 19 '17 at 07:13
  • @Ramillies cool glad thats working well enough for you. NativeCall on the C API would be the more native solution. The C functions look almost identical to the Perl 5 API so probably not too horrible to do. – Matt Oates Sep 26 '17 at 09:04
  • @MattOates: well, I was considering that, but I couldn't find how to turn a raw file descriptor into an `IO::Handle` or something like that (and perhaps it's not even possible). So I used Perl 5 since I was too lazy to reimplement everything from scratch using the BSD socket API, which I'm not overly fond of :—). – Ramillies Sep 27 '17 at 16:10
  • The design documentation you're referring to is likely [this grant proposal](http://news.perlfoundation.org/2018/12/grant-proposal-improve-perl-6-.html) I wrote last year, which was accepted, though I didn't start work on until recently. If all goes according to plan, you will be able to use UNIX sockets natively in Perl 6 by the end of the year (though it may not end up being designed like how I proposed, it's something I'll need to make an issue about on the problem solving repo once I reach that stage of the grant). – Kaiepi Sep 22 '19 at 09:27