I've been looking through the sockets code while writing a PIR socket library and I've noticed one major deficiency: if you pass 0 as the port you wish to bind to, the OS will choose a port for you. But there's no way in Parrot to find out which port that is.
Right now, bind just returns 0 on success (and -1 on failure). I'd like to change bind to return the port it's bound to on success. The patch below adds this code for the unix sockets code. The windows code looks like it'd be the same, but I can't test it so I'd have to find someone to help with that. -- Matt Diephouse http://matt.diephouse.com Index: src/io/io_unix.c =================================================================== --- src/io/io_unix.c (revision 16202) +++ src/io/io_unix.c (working copy) @@ -776,7 +776,18 @@ return -1; } - return 0; + /* bind was successful. return the port number we're bound to. */ + if (io->local.sin_port) + return ntohs(io->local.sin_port); + else { + struct sockaddr_in server; + int length; + + if (getsockname(io->fd, (struct sockaddr *)&server, &length) == -1) + return 0; + else + return ntohs(server.sin_port); + } } /*