I am familiar enough with XS to be able to do most basic things, but I have a problem and don't know the best approach. Essentially it is quite simple. I have some stream based C widgets that take input on STDIN and spew output on STDOUT. Typically these are compiled into little command line widgets so you might do:
widget1 --flag < input_file | widget2 | widget3 > output_file
As you might expect these are pluggable components of a larger system and I was too lazy to write buffering IO. Now I want to access these widgets via perl. Emulating the pipe linking is of course easily handled in C, but what I want to do is be able to pass two open filehandles to my XS code which will take the place of the input_file and output_file streams.
#!/usr/bin/perl open $in_fh, "<$in" or die $!; open $out_fh, ">$out" or die $!; XS_widget( $in_fh, $out_fh ); # reads stuff from $in_fh and writes s +tuff to $out_fh
I presume/hope that there must be some sort of macro that lets me exract the file descriptor out of an SV. I have done some searching and found stuff like SVt_PVGV Glob (possible a file handle) but my attempts to make anything work have failed. 'file' is not a good search term. It seems like it sould be as easy as extract the file pointer, cast it to FILE and away you go but.....
I have tried the R&D method with XS modules I know that take Perl filehandles like HTML::Parser but have found they do the read in perl and pass buffered chunks to the C. Any pointers would be appreciated.
While it would appear simple to just pass the filenames to the XS and let the open happen in C I do actually want to use Perl streams.
cheers
tachyon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |