21st Century Digital Boy

April 9, 2007

I don’t understand AF_UNIX

Filed under: Perl, Unix — 21cdb @ 12:06 pm

Using IO::Socket, one can make a Unix domain socket. (Specifically, it’s a SOCK_DGRAM).

Here’s my problem: The protocol requires that you read 2 bytes, which is the length of the message that follows. So I can do read() on 2 bytes, then read() on the remainder of the string.

OK, so what’s the problem? I don’t know what to do next. Further connections fail; it apparently isn’t putting the pointer in the right place (it reads 2 bytes into the string, which is always in the wrong place). shutdown() and close() don’t work, because, the latter closes the connection (no further reads) and the former …. closes the connecton (one cannot un-shutdown).

Am I supposed to open() it again? Wouldn’t that mean I’m open()-ing the socket constantly?

AF_UNIX apparently doesn’t like accept(), so looping over accept() and handing off to a child process, no worky.

Yes, I’ve googled. Everything - everything - points to doing it all by hand, with the low-level socket functions. IO::Socket::UNIX is supposed to make this “easy”. (Also I don’t do much socket programming)

Update. I do not understand why my $client = $server->accept() or die "Can't accept: $!\n"; returns Invalid argument since the man page says the package is optional and the code has 1 or 2 optional arguments, the first of which is the socket itself. I’m just missing some big piece of enlightenment and understanding here.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Blog at WordPress.com.