Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ->bind and ->connect with named arguments [rt.cpan.org #57671] #17451

Open
toddr opened this issue Apr 19, 2018 · 0 comments
Open

Allow ->bind and ->connect with named arguments [rt.cpan.org #57671] #17451

toddr opened this issue Apr 19, 2018 · 0 comments
Labels
dist-IO issues in the dual-life blead-first IO distribution Feature Request

Comments

@toddr
Copy link
Member

toddr commented Apr 19, 2018

Migrated from rt.cpan.org#57671 (status was 'new')

Requestors:

From [email protected] on 2010-05-20 17:02:06:

There's a disparity in convenience between

 use IO::Socket::Packet;
 my $sock = IO::Socket::Packet->new( IfIndex => 5 );

and

 use IO::Socket::Packet;
 use Socket::Packet qw( pack_sockaddr_ll ETH_P_ANY );
 my $sock = IO::Socket::Packet->new;
 $sock->bind( pack_sockaddr_ll( ETH_P_ANY, 5, 0, 0, '' ) );

It would be nice if IO::Socket->bind (and ditto ->connect) could take a
collection of named arguments instead of a single packed address.

 use IO::Socket::Packet;
 my $sock = IO::Socket::Packet->new;
 $sock->bind( IfIndex => 5 );

I observe that right now it's always an error to pass more than one
argument to ->bind:

sub bind {
    @_ == 2 or croak 'usage: $sock->bind(NAME)';
    ...

This surely gives way to a really neat implementation:

sub bind {
    my $sock = shift;
    my $addr = @_ > 1 ? $sock->pack_bindaddr( @_ ) : shift;

    return bind($sock, $addr) ? $sock
			      : undef;
}

Then any subclass that wishes to provide a neater implementation of bind
args, can provide such a method; e.g.

sub pack_bindaddr
{
   shift;
   my %args = @_;
   pack_sockaddr_ll( $args{Protocol} || ETH_P_ANY, $args{IfIndex} || 0,
0, 0, '' );
}

(with analogous implementation for ->connect)

Such code could probably be largely lifted from each subclass's
->configure method anyway.

This should be easy to implement, as it only adds new behavior which
right now would be an error; so there ought not be any risk of
clobbering existing code. Subclasses can implement these packing methods
piecemeal; we don't have to update every subclass all at once.

If you'd be happy with such an idea, I'd be quite happy to go about
actually writing code, tests, updating docs, etc...

-- 

Paul Evans
@toddr toddr transferred this issue from Dual-Life/IO Jan 20, 2020
@toddr toddr added Needs Triage dist-IO issues in the dual-life blead-first IO distribution labels Jan 20, 2020
@xenu xenu removed the Severity Low label Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dist-IO issues in the dual-life blead-first IO distribution Feature Request
Projects
None yet
Development

No branches or pull requests

3 participants