title: Perl IO::Socket::UNIX DGRAM non-blocking socket blocks in a loop
body: <p>Having an issue with socket block which I defined to be non-blocking.</p>
  
  <p>This way I make a new socket:</p>
  
  <pre><code>   unlink "/tmp/mysock";
     $socket = IO::Socket::UNIX-&gt;new(Local =&gt; "/tmp/mysock",
                                     Type      =&gt; SOCK_DGRAM,
                                     )
     or die "SOCKET CREATION FAILED: $!\n";
     $socket-&gt;blocking(0);
  
     $client = IO::Socket::UNIX-&gt;new(Peer =&gt; "/tmp/mysock",
                                     Type =&gt; SOCK_DGRAM
                                    )
     or die "CLIENT SOCKET: $!\n";
     $client-&gt;blocking(0);
  </code></pre>
  
  <p>This is how I send message from thread#1:</p>
  
  <pre><code>while ( $client-&gt;send(pack("LLLL", $_[0], $_[1], $_[2], $_[3]).join(':', @_[4..$#_]), 0) eq undef)
  {
      #Error logging here
  }
  $client-&gt;flush();
  </code></pre>
  
  <p>This is how I receive the message in thread#2</p>
  
  <pre><code>while (1)
  {
      my $fds=epoll_wait($poll, 10000, -1) or next; # next when error
  
      foreach my $fd (@{$fds})
      {
          if ($fd-&gt;[0] == fileno($socket))
          {
  
              while ($socket-&gt;recv($msg,64,0))
              {
                  #Processing the message
              }
          }
      }
  }
  </code></pre>
  
  <p>The problem is despite the fact that either <code>$socket</code> or <code>$client</code> are defined to be non-blocking the <code>$socket</code> blocks in the <code>while ($socket-&gt;recv($msg,64,0))</code> loop until the next message comes.
  Am I missing anything here?
  What can I do to avoid this blocking?</p>
  
  <p>Thanks in advance!
  :)</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This way it works:</p>
  
  <pre><code>use Socket;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>while ( !defined(send($client,pack("LLLL", $_[0], $_[1], $_[2], $_[3]).join(':', @_[4..$#_]),0)))
  {
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>while (defined(recv($server,my $msg,64,0)))
  {
  }
  </code></pre>