Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: IO::Socket::UNIX close() discards data when called "too soon"?

by pfaut (Priest)
on Jan 20, 2004 at 14:58 UTC ( #322596=note: print w/replies, xml ) Need Help??


in reply to IO::Socket::UNIX close() discards data when called "too soon"?

Your server is only reading one line from the client. If your client sends multiple lines, it's possible that the server has closed the socket before the client finishes sending all of his information. In this case, the attempt to print to the socket is probably getting a SIGPIPE aborting your client before it even gets a chance to read the socket. By adding the sleep() call, you have given the client more time to finish writing all of the extra data to the socket and it can complete successfully.

Try adding $SIG{PIPE} = sub { print "SIGPIPE\n"; }; to your client code somewhere near the top. If 'SIGPIPE' ever gets printed at the client end, then what I described above is happening.

90% of every Perl application is already written.
dragonchild
  • Comment on Re: IO::Socket::UNIX close() discards data when called "too soon"?
  • Download Code

Replies are listed 'Best First'.
Re: Re: IO::Socket::UNIX close() discards data when called "too soon"?
by Anonymous Monk on Jan 20, 2004 at 15:05 UTC
    It should read all the lines, as the readline brackets are in a list assignment - it only returns the first line though. The program works fine here, perl 5.8.2 on linux 2.4.21

      The server reads from the client with the following line in do_something():

      my ($l) = <$fh>;

      That is not a list assignment. If you want to read all of the data from the client, try adding local $/ = undef; before the above line.

      90% of every Perl application is already written.
      dragonchild

        It was the uncaught SIGPIPE. Adding undef $/; to client solved the problem. Thanks!

        perl -MO=Concise,-exec -e 'my ($l) = <$fh>' 1 <0> enter 2 <;> nextstate(main 1 -e:1) v 3 <0> pushmark s 4 <#> gvsv[*fh] s 5 <1> readline[t3] lK*/1 6 <0> pushmark s 7 <0> padsv[$l:1,2] lPRM*/LVINTRO 8 <2> aassign[t4] vKS 9 <@> leave[1 ref] vKP/REFC perl -MOpcode -le 'print Opcode::opdesc("aassign")' list assignment

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://322596]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2020-10-30 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (279 votes). Check out past polls.

    Notices?