… | |
… | |
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 for any reason (crashes, fails to call C<recv> etc.), the handle |
|
|
89 | will leak, so never do that. |
83 | |
90 | |
84 | Also, on windows, the passing process must give the receiving process the |
91 | Also, on windows, the receiving process must have the PROCESS_DUP_HANDLE |
85 | PROCESS_DUP_HANDLE access right for this module to work. |
92 | access right on the sender process for this module to work. |
86 | |
93 | |
87 | Cygwin is not supported at the moment, as file descriptor passing in |
94 | 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 |
95 | 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 |
96 | (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. |
97 | one isn't exposed to programs, and only used for stdin/out/err. Sigh. |
91 | |
98 | |
92 | =head1 OTHER MODULES |
99 | =head1 OTHER MODULES |
93 | |
100 | |
94 | At the time of this writing, the author of this module was aware of two |
101 | At the time of this writing, the author of this module was aware of two |
95 | other file descriptor passing modules on CPAN: L<Linux::FDPasser> and |
102 | other file descriptor passing modules on CPAN: L<File::FDPasser> and |
96 | L<AnyEvent::FDPasser>. |
103 | L<AnyEvent::FDPasser>. |
97 | |
104 | |
98 | The former hasn't seen any release for over a decade, isn't 64 bit clean |
105 | 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, |
106 | and it's author didn't respond to my mail with the fix, so doesn't work on |
100 | support a snumber of pre-standard unices. |
107 | many 64 bit machines. It does, however, support a number of pre-standard |
|
|
108 | unices, basically everything of relevance at the time it was written. |
101 | |
109 | |
102 | The latter seems to have similar support for antique unices, and doesn't |
110 | 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, |
111 | 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 |
112 | and requires AnyEvent. Presumably that makes it much more user friendly |
105 | than this module. |
113 | than this module (skimming the manpage shows that a lot of thought has |
|
|
114 | gone into it, and you are well advised to read it and maybe use it before |
|
|
115 | trying a low-level module such as this one). |
106 | |
116 | |
107 | Neither seems to support native win32 perls. |
117 | Neither seems to support native win32 perls. |
108 | |
118 | |
109 | =head1 AUTHOR |
119 | =head1 AUTHOR |
110 | |
120 | |