2013/2/6 shugo (Shugo Maeda) <redmine / ruby-lang.org>:

>>  If someone uses UNIXServer.open("\0foo") and UNIXSocket.open("\0foo") for
>>  current Ruby, how they should be modified with compatible fasion?
>
> The following code uses the name "\0foo\0\0\0....." even if the patch is applied.
>   require "socket"
>
>   OFFSET_OF_SUN_PATH = 2
>   UNIX_PATH_MAX = 108
>   SIZE_OF_SOCKADDR_UN = OFFSET_OF_SUN_PATH + UNIX_PATH_MAX
>   name = "\0foo"
>   begin
>     addr = Socket.pack_sockaddr_un(name)
>     if addr.bytesize < SIZE_OF_SOCKADDR_UN
>       # append extra NULs for broken abstract namespace handling.
>       sun_path = name + "\0" * (UNIX_PATH_MAX - name.bytesize)
>     else
>       sun_path = name
>     end
>   rescue ArgumentError
>     sun_path = name
>   end
>   UNIXSocket.open(sun_path) do
>     # ...
>   end
>
> However, if the longest path in sockaddr_un is not supported, this code doesn't work.

It seems not so trivial.

Also, is the code work well with Ruby 1.9.2 (or earlier Ruby 1.9.3)
and Ruby 2.0?
-- 
Tanaka Akira