askovpen
askovpen

Reputation: 2494

AnyEvent::Socket and abstract UNIX socket

With Socket i can use:

socket(my $socket, AF_UNIX, SOCK_STREAM, 0)
    or die "socket: $!";
my $sock_addr = sockaddr_un(chr(0).'/abstract/socket');
connect($socket, $sock_addr)  or die "connect: $!";

all ok. i connect and can transmit/receive;

With AnyEvent::Socket:

tcp_connect "unix/",chr(0).'/abstract/socket' , sub {
    my ($fh) = @_
        or die "unable to connect: $!";
    ...
}

and get error: unable to connect: No such device or address at file.pl line X.

How to use abstract UNIX sockets with Anyevent::Socket?

Upvotes: 2

Views: 336

Answers (1)

Paul Grove
Paul Grove

Reputation: 248

Hi I dug into this one a bit, the short answer is that AnyEvent::Socket doesnt support abstract sockets.

The Longer answer is that it really should, and as far as I can see its a small oversight preventing it from working.

The sub resolve_sockaddr is the culprit, line 718 in my version:

   if ($node eq "unix/") {
      return $cb->() if $family || $service !~ /^\//; # no can do

      return $cb->([AF_UNIX, defined $type ? $type : SOCK_STREAM, 0, Socket::pack_sockaddr_un $service]);
   }

The part of the line which reads $service !~ /^\//; # no can do is what is preventing it from working.

In my case I just commented out that line, and it worked, but really the regex should be modified to allow for \0 at the front to denote the abstract socket path.

You have a few options:

  • Modify your local copy of the library
  • Push the change upstream to Marc Lehmann and hope he accepts a patch
  • Monkey patch the function
  • Implement your own module which supports abstract domain sockets

Good luck.

Upvotes: 1

Related Questions