IO-EventMux

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

t/00-use.t
t/buffered-http-get-google.t
t/buffered-http-simple-get.t
t/buffered-http-simple-post.t
t/buffered-split.t
t/cfd.t
t/connect.t
t/connection-refused-tcp.t
t/connection-refused-udp-sendto.t
t/connection-refused-udp.t
t/credentials.t
t/critic.t
t/disconnect-delayed-write.t
t/disconnect.t
t/emptypayload.t
t/errors.t
t/fairness-by-event.t
t/fh-types.t
t/max-read-size.t
t/metahandler.t
t/perlcriticrc

README  view on Meta::CPAN

        Nothing happened and timeout occurred.

    error
        An error occurred in connection with the file handle, such as
        "connection refused", etc.

    accepted
        A new client connected to a listening socket and the connection was
        accepted by EventMux. The listening socket file handle is in the
        'parent_fh' key. If the file handle is a unix domain socket the
        credentials of the user connection will be available in the keys;
        'pid', 'uid' and 'gid'.

    ready
        A file handle is ready to be written to, this can be use full when
        working with nonblocking connects so you know when the remote
        connection accepted the connection.

    accepting
        A new client is trying to connect to a listening socket, but the
        user code must call accept manually. This only happens when the

README  view on Meta::CPAN


      $mux->sendto($my_fh, pack_sockaddr_in($port, inet_aton($ip)), $data);

  push_event($event)
    Push event on queue

  nonblock($fh)
    Puts socket into nonblocking mode.

  socket_creds($fh)
    Return credentials on UNIX domain sockets.

  socket_type($fh)
    Return socket type.

  socket_listening($fh)
    Check if the socket is set to listening mode

  recroak()
    Helper function to rethrow croaks

lib/IO/EventMux.pm  view on Meta::CPAN


=item error

An error occurred in connection with the file handle, such as 
"connection refused", etc.

=item accepted

A new client connected to a listening socket and the connection was accepted by
EventMux. The listening socket file handle is in the 'parent_fh' key. If the 
file handle is a unix domain socket the credentials of the user connection will be available in the keys; 'pid', 'uid' and 'gid'. 

=item ready 

A file handle is ready to be written to, this can be use full when working with
nonblocking connects so you know when the remote connection accepted the
connection.

=item accepting

A new client is trying to connect to a listening socket, but the user code must

lib/IO/EventMux.pm  view on Meta::CPAN

    my $flags = fcntl($socket, F_GETFL, 0)
        or die "Can't get flags for socket: $!\n";
    if (not $flags & O_NONBLOCK) {
        fcntl($socket, F_SETFL, $flags | O_NONBLOCK)
            or die "Can't make socket nonblocking: $!\n";
    }
}

=head2 B<socket_creds($fh)>

Return credentials on UNIX domain sockets.

=cut

sub socket_creds {
    my ($self, $fh) = @_;
    my %creds;

    # TODO: Support localhost TCP via: /proc/net/tcp
    my $rv = getsockopt($fh, SOL_SOCKET, SO_PEERCRED);
    if(defined $rv) {

t/credentials.t  view on Meta::CPAN

    use Data::Dumper; print Dumper($event);
    
    if($event->{type} eq 'accepted') {
        is_deeply($event, {
            pid => $$,
            gid => (split(/\s/,$())[0],
            uid => $<,
            parent_fh => $listener,
            fh => $event->{fh},
            type => 'accepted',
        }, "We got back credentials");
        exit;
    
    } elsif($event->{type} eq 'error') {
        use Data::Dumper;
        print Dumper($event);
        fail "Got error";
        exit;

    } elsif($event->{type} eq 'timeout') {
        fail "Got timeout";



( run in 0.273 second using v1.01-cache-2.11-cpan-4d50c553e7e )