Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Error message in log file is different from "die" message in code.

by Mask (Pilgrim)
on May 07, 2003 at 12:26 UTC ( #256173=perlquestion: print w/ replies, xml ) Need Help??
Mask has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
my daemon died with this messages in log file:
Server socket ready, accepting... at qd.pl line 530 Can't use an undefined value as a symbol reference at qd.pl line 533
But in line 533 i have next code:
529>if( $ready_socket==$server ) { # Incomming connection 530> warn "Server socket ready, accepting..."; 531> my $new_connection=$server->accept(); 532> # make the socket non-blocking 533> my $flags = fcntl($new_connection, F_GETFL, 0) 534> or die "cannot get flags for socket: $!\n"; .....
How can it be that error message in log file(Can't use an undefined value as a symbol reference) is different from "die" message in the code(cannot get flags for socket: $!)?

Comment on Error message in log file is different from "die" message in code.
Select or Download Code
Re: Error message in log file is different from "die" message in code.
by Skeeve (Vicar) on May 07, 2003 at 12:38 UTC
    It's not your error message but a warning that $new_connection (or F_GETFL?) is undefined.
      How can i see my error message then?
        Correct your code so that it works.
Re: Error message in log file is different from "die" message in code.
by Aristotle (Chancellor) on May 07, 2003 at 12:57 UTC
    Your code is dying because $new_connection is undefined, which means $server->accept returned an undefined value. The cause seems to be this:
    if( $ready_socket == $server )
    This looks like nonsense to me. You don't want a numerical comparison there (considering $server is an object reference). Where do you assign $ready_socket and what kind of thing does it contain?

    Makeshifts last the longest.

      This is how $ready_socket created.
      527>($r_ready, $w_ready, $e_ready) = IO::Select->select($read_set, $wr +ite_set, undef, 10); 528> foreach my $ready_socket (@$r_ready) { 529> if( $ready_socket==$server ) { # Incomming connection 530> warn "Server socket ready, accepting..."; 531> my $new_connection=$server->accept(); 532> # make the socket non-blocking 533> my $flags = fcntl($new_connection, F_GETFL, 0) 534> or die "cannot get flags for socket: $!\n"; 535> $flags = fcntl($new_connection, F_SETFL, $flags | O_NONBLO +CK) 536> or die "cannot set flags for socket: $!\n";
      $server is created like this earlier.
      my $server = IO::Socket::INET->new(LocalPort => $cfg->server_port, Type => SOCK_STREAM, Reuse => 1, Listen => 10, ) or die "could not become a tcp server on port ", $cfg->server_port, +" : $@\n";
        That seems to be correct after some study of those modules' POD. The fact remains that $server->accept() is returning undef for failure - whatever the reason may be. Is there actually an external connection request at that point?

        Makeshifts last the longest.

      if ($socket == $server), see perlref:
        Using a reference as a number produces an integer representing its storage location in memory. The only useful thing to be done with this is to compare two references numerically to see whether they refer to the same location.

      It's faster than using $socket eq $server because the arguments don't need to be converted to the "blessing=type" string format first.

      --
      [ e d @ h a l l e y . c c ]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (17)
As of 2014-08-01 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (17 votes), past polls