How do I get my IO::Socket::UNIX sockets to be non-blocking?
kwopublic
created: 2006-02-01 13:44:02
I am trying to get my socket writes to be non-blocking. So far I have been unsuccessful. I am using an IO::Socket::UNIX type socket for interprocess communication. After opening it, I set the blocking flag to 0 but this does not seem to make my syswrite call non-blocking. Below are some snippets of my perl code and a print out from my logging. The logging clearly shows that the sywrite is blocking. Anyone have any idea how I can resolve this problem? Are UNIX sockets able to work in a non-blocking mode? Any help greatly appreciated, kwo
           my $s = IO::Socket::UNIX->new(
                Type      => SOCK_STREAM,
                Local     => $sockname,
                Listen    => 10,
                ReuseAddr => 1,
            );
            if ( not $s ) {
                logerr("Can't create socket $sockname : $!");
                exit $PACE::Constants::DAEMON_EXIT;
            }
            
            # Vantive ? : Set the Socket to non-blocking.
            $s->blocking(0);
            my $tmp_val = $s->blocking();
            logdbg( 15, "Blocking flag = $tmp_val\n");
 
...

    logdbg(14, "writeSocket : File # $fn has $size bytes to send.\n");

    # if no data to write just return
    return if ($size == 0);
    
    $sent = syswrite $wh, $buf, $size;

    logdbg(14, "writeSocket : $size bytes attempted, $sent bytes written.\n");

...

06/01/31 15:49:56 Agent: writeSocket : File # 35 has 100098 bytes to send.

06/01/31 15:50:26 Agent: writeSocket : 100098 bytes attempted, 100098 bytes written.

Re: How do I get my IO::Socket::UNIX sockets to be non-blocking?
created: 2006-02-01 13:50:51

Out of curiosity, what happens if you address blocking like this?

$s->blocking(0) or die $!;

I suppose it's possible that setting blocking off is failing, and this will let you know. It might not solve the issue, but at least you may discover where to dig.


Dave

Re^2: How do I get my IO::Socket::UNIX sockets to be non-blocking?
created: 2006-02-01 15:47:21
The blocking interface returns the current value so the or die would not be appropriate.
Re^3: How do I get my IO::Socket::UNIX sockets to be non-blocking?
created: 2006-02-01 20:14:50

Are you sure? You may be right, but that's not what the documents say. The blocking() method is inherited from IO::Handle, from what I can tell, and the documentation for IO::Handle says the following:

$io->blocking ( [ BOOL ] )
If called with an argument blocking will turn on non-blocking IO if BOOL is false, and turn it off if BOOL is true.

blocking will return the value of the previous setting, or the current setting if BOOL is not given.

If an error occurs blocking will return undef and $! will be set.

...which should make it a good candidate for "or die $!;" syntax.


Dave

Re^4: How do I get my IO::Socket::UNIX sockets to be non-blocking?
created: 2006-02-01 23:03:59

That's really confused. How do you determine the difference between success and failure with

$rv = $io->block(); ## Find out the current setting
if( !$rv ) {
   ## Is non-blocking enabled or did the call fail?
}

$rv = $io->blocking( 1 ); ## Turn on blocking (turn off non-blocking)
if( !$rv ) { 
    ## Was non-blocking previously enabled or did the call fail?
}

$rv = $io->blocking( 0 ); ## Turn off blocking 
if( !$rv ) {
    ## Did we succeed or did the call fail?
}

What would or die $! be telling you?

A candidate for "Bad Interface Award of 1995, 1996, 1997, ... " :)


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

perlmonks.org content © perlmonks.org and BrowserUk, davido, kwopublic

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03