… | |
… | |
14 | |
14 | |
15 | =head1 DESCRIPTION |
15 | =head1 DESCRIPTION |
16 | |
16 | |
17 | 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 |
18 | to another process, using a (streaming) unix domain socket (on POSIX |
18 | to another process, using a (streaming) unix domain socket (on POSIX |
19 | systems) or any (streaming) socket (on WIN32 systems). |
19 | systems) or any (streaming) socket (on WIN32 systems). The ability to pass |
|
|
20 | file descriptors on windows is currently the unique selling point of this |
|
|
21 | module. Have I mentioned that it is really small, too? |
20 | |
22 | |
21 | =head1 FUNCTIONS |
23 | =head1 FUNCTIONS |
22 | |
24 | |
23 | =over 4 |
25 | =over 4 |
24 | |
26 | |
… | |
… | |
53 | =item $fd = IO::FDPass::recv $socket_fd |
55 | =item $fd = IO::FDPass::recv $socket_fd |
54 | |
56 | |
55 | Receive a file descriptor from the socket and return it if successful. On |
57 | Receive a file descriptor from the socket and return it if successful. On |
56 | errors, return C<-1>. |
58 | errors, return C<-1>. |
57 | |
59 | |
58 | Note that I<both> C<$socket_fd> amd the returned file descriptor are, in |
60 | Note that I<both> C<$socket_fd> and the returned file descriptor are, in |
59 | fact, file descriptors, not handles. |
61 | fact, file descriptors, not handles. |
60 | |
62 | |
61 | When used on non-blocking sockets, this function might fail with C<$!> |
63 | When used on non-blocking sockets, this function might fail with C<$!> set |
62 | set to C<EAGAIN> or equivalent, in which case you are free to try. It |
64 | to C<EAGAIN> or equivalent, in which case you are free to try again. It |
63 | should succeed if called on a socket that indicates readability (e.g. via |
65 | should succeed if called on a socket that indicates readability (e.g. via |
64 | C<select>). |
66 | C<select>). |
65 | |
67 | |
66 | Example: receive a file desriptor from a blockign socket and convetr it to |
68 | Example: receive a file descriptor from a blocking socket and convert it |
67 | a file handle. |
69 | to a file handle. |
68 | |
70 | |
69 | my $fd = IO::FDPass::recv fileno $socket; |
71 | my $fd = IO::FDPass::recv fileno $socket; |
70 | $fd >= 0 or die "unable to receive file handle: $!"; |
72 | $fd >= 0 or die "unable to receive file handle: $!"; |
71 | open my $fh, "+<&=$fd" |
73 | open my $fh, "+<&=$fd" |
72 | or die "unable to convert file descriptor to handle: $!"; |
74 | or die "unable to convert file descriptor to handle: $!"; |
… | |
… | |
106 | and it's author didn't respond to my mail with the fix, so doesn't work on |
108 | and it's author didn't respond to my mail with the fix, so doesn't work on |
107 | many 64 bit machines. It does, however, support a number of pre-standard |
109 | 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. |
110 | unices, basically everything of relevance at the time it was written. |
109 | |
111 | |
110 | The latter seems to have similar support for antique unices, and doesn't |
112 | The latter seems to have similar support for antique unices, and doesn't |
111 | seem to suffer from 64 bit bugs, but inexplicably has a large perl part, |
113 | seem to suffer from 64 bit bugs, but inexplicably has a large perl |
|
|
114 | part, doesn't support mixing data and file descriptors, and requires |
112 | and requires AnyEvent. Presumably that makes it much more user friendly |
115 | AnyEvent. Presumably that makes it much more user friendly than this |
113 | than this module (skimming the manpage shows that a lot of thought has |
116 | module (skimming the manpage shows that a lot of thought has gone into |
114 | gone into it, and you are well advised to read it and maybe use it before |
117 | it, and you are well advised to read it and maybe use it before trying a |
115 | trying a low-level module such as this one). |
118 | low-level module such as this one). In fact, the manpage discusses even |
|
|
119 | more file descriptor passing modules on CPAN. |
116 | |
120 | |
117 | Neither seems to support native win32 perls. |
121 | Neither seems to support native win32 perls. |
118 | |
122 | |
119 | =head1 AUTHOR |
123 | =head1 AUTHOR |
120 | |
124 | |