DC/IO/UDP/Server.pm untested

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 2 Conditioncond n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 38 CC 2 SCAR 12.0
CC
2
Cov
0%
new
6.0
_readable
2.0
BEGIN
2.0
CRAP 3.3
1 #!/usr/local/bin/perl
2 # -*- perl -*-
3  
4 # Copyright (c) 2010 by Jeff Weisberg
5 # Author: Jeff Weisberg <jaw @ tcp4me.com>
6 # Created: 2010-Nov-22 13:21 (EST)
7 # Function:
8 #
9 # $Id: Server.pm,v 1.1 2010/12/02 18:16:21 jaw Exp $
10  
11 package AC::DC::IO::UDP::Server;
12 use AC::DC::Debug 'udp';
13 use Socket;
14 use strict;
15  
16 our @ISA = 'AC::DC::IO::UDP';
17  
18 my $BUFSIZ = 65536;
19  
20 sub new {
21 my $class = shift;
22 my $port = shift;
23 my $nextc = shift;
24  
25 my $me = bless {
26 info => "server udp/$port",
27 nextclass => $nextc,
28 }, $class;
29  
30 my $fd;
31  
32 socket($fd, PF_INET, SOCK_DGRAM, 0);
33 setsockopt($fd, SOL_SOCKET, SO_REUSEADDR, 1);
34 my $i = bind($fd, sockaddr_in($port, INADDR_ANY));
35  
36 fatal( "cannot bind to udp/$port: $!" ) unless $i;
37  
38 listen( $fd, 128 );
39 $me->init($fd);
40 $me->wantread(1);
41  
42 verbose("server started on udp/$port");
43  
44 return $me;
45 }
46  
47 sub _readable {
48 my $me = shift;
49  
50 debug( "new udp connection" );
51  
52 my $next = $me->{nextclass};
53 $next->new( $me );
54 }
55  
56  
57 1;