sockets: non-blocking accept on BSDOS 
Author Message
 sockets: non-blocking accept on BSDOS

The following perl5 snippet works on Solaris, but on BSDOS
accept always returns EAGAIN, even when it should detect a

#!/usr/local/bin/perl5 -Tw
require 5.002;
use strict;
BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
use Socket;
use Carp;
use Fcntl;

my $port = shift || 2345;
my $proto = getprotobyname('tcp');
socket(Server, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n";
setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) or die "setsockopt: $!\n";
fcntl(Server, F_SETFL, O_NONBLOCK) || die "fcntl: $!";
bind(Server, sockaddr_in($port, INADDR_ANY)) or die "bind: $!\n";
listen(Server, SOMAXCONN) or die "listen: $!\n";

logmsg "server started on port $port";

my $paddr;


while ( 1 ) {
    $paddr = accept(Client, Server);

    ($! =~ /temporarily unavailable/) && next;

    my($port, $iaddr) = sockaddr_in($paddr);
    my $name = gethostbyaddr($iaddr, AF_INET);

    logmsg "connection from $name at port $port";

    print Client "Hello there, $name, it's now ", scalar localtime, "\n";


Wed, 25 Aug 1999 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. How to do a non-blocking accept() in Perl 5

2. How to do a non-blocking accept() in Perl 5

3. winNT non-blocking Sockets how-to?

4. winNT Sockets non-blocking?

5. Non-blocking sockets

6. Query about non-blocking IO::Socket usage

7. ActivePerl, Win2K, non-blocking, IO::Socket, IO::Select

8. Non-blocking sockets

9. Non-Blocking Socket in NT

10. Non-blocking Perl socket calls?

11. non-blocking I/O on a socket

12. Problem with buffering on non-blocking socket under win32


Powered by phpBB® Forum Software