terry has asked for the wisdom of the Perl Monks concerning the following question:

Using C code with XS

I'm writing a perl daemon that will send many email messages. After looking at the SMTP modules availabe at CPAN, I've decided to take advantage of qmail to do all the SMTP sending and such. In order to send out the most messages possible I'm composing the message and making a system call to invoke qmail-queue to send it. This is not the right answer.

qmail is very fast, and I'd like to take advantage of it as much as possible, but the idea of executing a system call for each message isn't right. I'm thinking os using XS to interface with qmail-queue. I don't know anything about XS, Xsub, h2xs, etc, but I do know both Perl and C to a moderate level. I can't seem to find any good or robust documentation on XS so I can't determine if this is a stupid idea or not.

Can any of you tell me where I can find good documentation on XS, or whether the idea of taking a full program into a perl module via XS is crazy?

Thanks,

Terry

Replies are listed 'Best First'.
Re: Using C code in Perl
by chromatic (Archbishop) on Apr 07, 2000 at 19:31 UTC
    (re-posting my answer to a deleted question):

    There are two good places i know of to look for XS documentation. One should already be installed on your machine.

    Try 'perldoc perlxs' (or perlman:perlxs). The other is Sriram's book "Advanced Perl Programming". (See O'Reilly for details.) The last couple of chapters get into the guts (oh, perlman:perlguts too) of Perl data structures and such, and talk in great detail about embedding interpreters in other languages, calling and defining stubs, and all those hairy things.

RE: Using C code in Perl
by Jonathan (Curate) on Apr 07, 2000 at 19:19 UTC
    Have you thought of trying SWIG, even I found it very easy to use :-) Look at http://www.swig.org/
Re: Using C code in Perl
by jbert (Priest) on Apr 10, 2000 at 19:08 UTC
    Although you sound as though you have done your research I can't help but wonder if you are optimising the right thing at the right time.

    Sending, transferring, delivering and receiving an email is a complex process generally involving lots of network traffic.

    Do you know how quickly qmail will get email out of your system? Not necessarily to boxes located on the same LAN, but boxes located distantly on the Internet?

    I would be very surprised if your Net::SMTP script or open( MAIL, "|/foo/qmail-foo" ) script was unable to get messages into the system as fast as qmail could get them out.

    You don't really need to worry about efficiency as long as you can keep up with qmail's sending.

    Have I got the wrong end of the stick? Do you have some numbers? Could you please elaborate?

    "Premature optimisation is the root of all evil"