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

Hi. I have 2 questions about blocking:

Is there any way to accept a connection on a socket without blocking the program? I'm using accept() on an IO::Socket::UNIX, but I think that blocks the program.

Is there any way to read data from a filehandle without blocking the program? I think I saw something about select(), but the reference on perlfunc is not clear (actually, it seems it doesn't have anything to do with it).

Thanks..

Replies are listed 'Best First'.
Re: blocking?
by jeroenes (Priest) on Jun 05, 2001 at 13:54 UTC
    You need to fork your script, in both cases. Search on forking, turns op many good threads. For example. read the nodes of For all your forking needs...

    Jeroen
    "We are not alone"(FZ)

(tye)Re: blocking?
by tye (Sage) on Jun 05, 2001 at 19:07 UTC

    select in Perl has two very different meanings. If you pass 4 arguments to select, then it offers the function that you need. These two uses of select are so different that they are documented separately. Right after the section on select that you read, you'll find another section on select that describes what you need.

            - tye (but my friends call me "Tye")
(dws)Re: blocking?
by dws (Chancellor) on Jun 05, 2001 at 22:38 UTC
    Is there any way to accept a connection on a socket without blocking the program?

    A bit of advice: Everything you're liable to need to know about writing non-blocking servers is covered in Lincoln Stein's Network Programming With Perl. Spend the bucks on the book. It's well-written, and will spare you lots of grief.