Skip to content

Always call IO::Socket->configure even with no %args [rt.cpan.org #59984] #17452

Open
@toddr

Description

@toddr

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

Requestors:

From leonerd-cpan@leonerd.org.uk on 2010-08-01 21:08:41:

Currently, IO::Socket::new tests if any named arguments are present, and
does not call ->configure if there are no arguments. It's the actual
configure method that creates a socket handle (by a call to ->socket),
so without this, no further methods will work correctly.

In particular, the following code does not work:

  my $sock = IO::Socket::UNIX->new;
  $sock->setsockopt( .... );
  $sock->bind( pack_sockaddr_un( $path ) );

Because the configure method doesn't actually check the full set of
named keys, it'll accept anything, so the following works fine

  my $sock = IO::Socket::UNIX->new( DummyToKeepIOSocketHappy => 1 );
  ...

Is there any actual implementation reason why this call has to be
conditional? I've tried simply making the call unconditional in the IO
dist, and all tests still pass. There's often times, such as when
creating PF_PACKET sockets, that I'll want to create a socket handle to
set some options (such as a packet filter), before the eventual ->bind()
call to attach it to some interface. It's useful to be able to get an
unconfigured but still opened filehandle in this case.

Rather than await a 'yes', I'll fork+patch+docs+tests on github anyway,
and submit you a pull request, and you can decide on the merits there.
This will also include a fix for

  https://rt.cpan.org/Ticket/Display.html?id=57671

which I am also working on.

Thanks,

-- 

Paul Evans

Metadata

Metadata

Assignees

No one assigned

    Labels

    dist-IOissues in the dual-life blead-first IO distribution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions