View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Patrick LeBoutillier > File-FDkeeper > File::FDkeeper



Annotate this POD

View/Report Bugs
Module Version: 0.06   Source  


File::FDkeeper - Store open filehandles in another process for later use


  # "server"
  my $fdk = new File::FDkeeper(Local => "/tmp/fdkeeper.sock") ; 
  $fdk->run() ;

  # "client"
  my $fdk = new File::FDkeeper(Peer => "/tmp/fdkeeper.sock") ;
  my $id = $fdk->put($some_fh) ;
  $fh = $fdk->get($id) ;
  $fdk->del($id) ;


File::FDkeeper allows you to store open filehandles in a "server" process and retrieve them at a later time from another process.

When a filehandle is stored, an id is returned. This id can then be used by any other process to retrieve the filehandle (as long as they have permission to open the fifo).


new ( [ARGS] )

Creates an File::FDkeeper object. new expects the following argument groups, in key-value pairs:

  Local                 Path to local fifo
  AccessTimeout         Filehandles not accessed since this number of seconds 
                          will be closed. Default is 0 (infinity).
  AccessTimeoutCheck    Frequency (in seconds) to check for expired 
                          filehandles. Default is 0 (never).

  Peer                  Path to peer fifo

If Local is specified, a "server" object is created.

If Peer is specified, a "client" object is created.



Stores FILEHANDLE and returns the associated id. An exception is thrown if an error occurs.

Note: when put is called from a "client" object, FILEHANDLE will be closed once it has been sent to the "server". This seems to be necesasry in order to be able to get and use that handle later in that process.

get ( ID )

Retrieves filehandle ID and returns it. Returns undef if filehandle ID is not presentily stored. An exception is thrown if an error occurs.

del ( ID )

Removes and closes filehandle ID. Returns undef if filehandle ID is not presently stored. An exception is thrown if an error occurs.

cnt ( )

Returns the number of filehandles currently in the "server". An exception is thrown if an error occurs.

run ( [LIFELINE] )

Note: This method is available only on the "server" objects.

Starts listening for connections on the fifo in order to store filehandles. Normally, this method does not return. However, if LIFELINE is a valid filehandle, run will return when any data (or EOF) is received on LIFELINE. If used, LIFELINE is normally a pipe used as such:

  use IO::Pipe ;

  my $pipe = new IO::Pipe() ;
  if (fork()){
    $pipe->reader() ;
    require File::FDkeeper ;
    my $fdk = new File::FDkeeper(Local => "/tmp/fdkeeper.sock") ;       
    $fdk->run($pipe) ;
    exit() ;

  $pipe->writer() ;
  # do stuff...
  # When this process dies, the File::FDkeeper server process will 
  # die as well.


File::FDpasser may write directly to STDERR on error. It doesn't seem that this can be suppressed.


File::FDpasser, IO::Socket::UNIX


Patrick LeBoutillier, <>


Copyright 2005 by Patrick LeBoutillier

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: