Skip to content

Commit

Permalink
Merge 52229f6 into facfab6
Browse files Browse the repository at this point in the history
  • Loading branch information
t-a-k committed May 15, 2021
2 parents facfab6 + 52229f6 commit 39d4587
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pp_sys.c
Expand Up @@ -2707,7 +2707,7 @@ PP(pp_ssockopt)
case OP_SSOCKOPT: {
const char *buf;
int aint;
if (SvPOKp(sv)) {
if (SvPOKp(sv) && !SvNIOK(sv)) {
STRLEN l;
buf = SvPV_const(sv, l);
len = l;
Expand Down
26 changes: 26 additions & 0 deletions t/io/socket.t
Expand Up @@ -281,6 +281,32 @@ SKIP: {
), "0\n", {}, "fresh socket not inherited across exec");
}

# GH #18642 - test whether setsockopt works with a numeric OPTVAL which also
# has a cached stringified value
SKIP: {
defined(my $IPPROTO_IP = eval { Socket::IPPROTO_IP() })
or skip 'no IPPROTO_IP', 4;
defined(my $IP_TTL = eval { Socket::IP_TTL() })
or skip 'no IP_TTL', 4;

my $sock;
socket($sock, PF_INET, SOCK_STREAM, $tcp) or BAIL_OUT "socket: $!";

my $ttl = 7;
my $integer_only_ttl = 0 + $ttl;
ok(setsockopt($sock, $IPPROTO_IP, $IP_TTL, $integer_only_ttl),
'setsockopt with an integer-only OPTVAL');
my $set_ttl = getsockopt($sock, $IPPROTO_IP, $IP_TTL);
is(unpack('i', $set_ttl // ''), $ttl, 'TTL set to desired value');

my $also_string_ttl = $ttl;
my $string = "$also_string_ttl";
ok(setsockopt($sock, $IPPROTO_IP, $IP_TTL, $also_string_ttl),
'setsockopt with an integer OPTVAL with stringified value');
$set_ttl = getsockopt($sock, $IPPROTO_IP, $IP_TTL);
is(unpack('i', $set_ttl // ''), $ttl, 'TTL set to desired value');
}

done_testing();

my @child_tests;
Expand Down

0 comments on commit 39d4587

Please sign in to comment.