… | |
… | |
3 | IO::FDPass - pass a file descriptor over a socket |
3 | IO::FDPass - pass a file descriptor over a socket |
4 | |
4 | |
5 | =head1 SYNOPSIS |
5 | =head1 SYNOPSIS |
6 | |
6 | |
7 | use IO::FDPass; |
7 | use IO::FDPass; |
|
|
8 | |
|
|
9 | IO::FDPass::send fileno $socket, fileno $fh_to_pass |
|
|
10 | or die "send failed: $!"; |
|
|
11 | |
|
|
12 | my $fd = IO::FDPass::recv fileno $socket; |
|
|
13 | $fd >= 0 or die "recv failed: $!"; |
8 | |
14 | |
9 | =head1 DESCRIPTION |
15 | =head1 DESCRIPTION |
10 | |
16 | |
11 | This small low-level module only has one purpose: pass a file descriptor |
17 | This small low-level module only has one purpose: pass a file descriptor |
12 | to another process, using a (streaming) unix domain socket (on POSIX |
18 | to another process, using a (streaming) unix domain socket (on POSIX |
… | |
… | |
19 | =cut |
25 | =cut |
20 | |
26 | |
21 | package IO::FDPass; |
27 | package IO::FDPass; |
22 | |
28 | |
23 | BEGIN { |
29 | BEGIN { |
24 | $VERSION = '0.1'; |
30 | $VERSION = 0.2; |
25 | |
31 | |
26 | require XSLoader; |
32 | require XSLoader; |
27 | XSLoader::load (__PACKAGE__, $VERSION); |
33 | XSLoader::load (__PACKAGE__, $VERSION); |
28 | } |
34 | } |
29 | |
35 | |
… | |
… | |
75 | and 64 bit and Strawberry Perl 5.16.3 32 and 64 bit, and found to work, |
81 | and 64 bit and Strawberry Perl 5.16.3 32 and 64 bit, and found to work, |
76 | although ActivePerl 32 bit needed a newer MinGW version (that supports XP |
82 | although ActivePerl 32 bit needed a newer MinGW version (that supports XP |
77 | and higher). |
83 | and higher). |
78 | |
84 | |
79 | However, windows doesn't support asynchronous file descriptor passing, so |
85 | However, windows doesn't support asynchronous file descriptor passing, so |
80 | C<send> and C<recv> will have to "rendezvous", that is, they have to wait |
86 | the source process must still be around when the destination process wants |
81 | for each other. Therefore, on windows, it's advisable to run them at the |
87 | to receive the file handle. Also, if the target process fails to fetch the |
82 | same time to avoid any unnecessary delays. |
88 | handle, the handle will leak, so never do that. |
83 | |
89 | |
84 | Also, on windows, the passing process must give the receiving process the |
90 | Also, on windows, the receiving process must have the PROCESS_DUP_HANDLE |
85 | PROCESS_DUP_HANDLE access right for this module to work. |
91 | access right on the sender process for this module to work. |
86 | |
92 | |
87 | Cygwin is not supported at the moment, as file descriptor passing in |
93 | Cygwin is not supported at the moment, as file descriptor passing in |
88 | cygwin is not supported, and cannot be rolled on your own as cygwin has no |
94 | cygwin is not supported, and cannot be rolled on your own as cygwin has no |
89 | (working) method of opening a handle as fd. That is, it has one, but that |
95 | (working) method of opening a handle as fd. That is, it has one, but that |
90 | one isn't exposed to programs, and only used for stdin/out/err. Sigh. |
96 | one isn't exposed to programs, and only used for stdin/out/err. Sigh. |
… | |
… | |
95 | other file descriptor passing modules on CPAN: L<Linux::FDPasser> and |
101 | other file descriptor passing modules on CPAN: L<Linux::FDPasser> and |
96 | L<AnyEvent::FDPasser>. |
102 | L<AnyEvent::FDPasser>. |
97 | |
103 | |
98 | The former hasn't seen any release for over a decade, isn't 64 bit clean |
104 | The former hasn't seen any release for over a decade, isn't 64 bit clean |
99 | and it's author didn't respond to my mail with the fix. It does, however, |
105 | and it's author didn't respond to my mail with the fix. It does, however, |
100 | support a snumber of pre-standard unices. |
106 | support a number of pre-standard unices. |
101 | |
107 | |
102 | The latter seems to have similar support for antique unices, and doesn't |
108 | The latter seems to have similar support for antique unices, and doesn't |
103 | seem to suffer from 64 bit bugs, but inexplicably has a large perl part, |
109 | seem to suffer from 64 bit bugs, but inexplicably has a large perl part, |
104 | and requires AnyEvent. Presumably that makes it much more user friendly |
110 | and requires AnyEvent. Presumably that makes it much more user friendly |
105 | than this module. |
111 | than this module. |