Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

LWP is not SIGPIPE safe?

by OlegG (Monk)
on Nov 28, 2012 at 11:23 UTC ( #1006011=perlquestion: print w/ replies, xml ) Need Help??
OlegG has asked for the wisdom of the Perl Monks concerning the following question:

As you know sigpipe may occur when you are writing to closed socket. I know two ways to prevent it:
  • install signal handler
  • use send instead syswrite with MSG_NOSIGNAL parameter
  • But I can't find any of this in LWP code. For example here is writing to socket: https://metacpan.org/source/GAAS/libwww-perl-6.04/lib/LWP/Protocol/http.pm#L231
    Other http client module HTTP::Tiny has such check: https://metacpan.org/source/DAGOLDEN/HTTP-Tiny-0.024/lib/HTTP/Tiny.pm#L487

    Comment on LWP is not SIGPIPE safe?
    Re: LWP is not SIGPIPE safe?
    by MidLifeXis (Prior) on Nov 28, 2012 at 13:16 UTC

      I am failing to see a question in your comments. I will assume that your question is along the lines of "why, if HTTP::Tiny has this protection, does not LWP?"

      Perhaps you can make a case for it on the mailing list (as found on the LWP documentation page), or create a patch and submit it on the github repository.

      --MidLifeXis

        Question is in subject of this topic
          Answer to this question is in the body of the question ;) As you can see from the code it is not handling SIGPIPE itself. On the other hand nothing prevents you from setting handler in your script from which you're using LWP.
    Re: LWP is not SIGPIPE safe?
    by Khen1950fx (Canon) on Nov 28, 2012 at 16:24 UTC
      One thing to remember is that SIGPIPE is global for that program. So, after looking at your examples, my guess is that the authors each had different requirements. GAAS may not have wanted to use SIGPIPE because of its global implications and requirements, and his usage of syswrite doesn't suggest that LWP isn't SIGPIPE safe.
        In HTTP::Tiny example "local $SIG{PIPE}" used, so it handles only sigpipe emitted from the block where it was installed.
        May be lwp's syswrite is safe. But I want to know reason why it is safe. For example: syswrite() can't fail if it was called immediately after socket opening and data length for write is small enough.

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Node Status?
    node history
    Node Type: perlquestion [id://1006011]
    Approved by marto
    Front-paged by ColonelPanic
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (9)
    As of 2014-07-11 04:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (218 votes), past polls