Skip to content

Commit

Permalink
Merge 511f1d6 into aa467bd
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed May 21, 2021
2 parents aa467bd + 511f1d6 commit ad1d635
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pp_sys.c
Expand Up @@ -2707,13 +2707,14 @@ PP(pp_ssockopt)
case OP_SSOCKOPT: {
const char *buf;
int aint;
SvGETMAGIC(sv);
if (SvPOKp(sv)) {
STRLEN l;
buf = SvPV_const(sv, l);
buf = SvPVbyte_nomg(sv, l);
len = l;
}
else {
aint = (int)SvIV(sv);
aint = (int)SvIV_nomg(sv);
buf = (const char *) &aint;
len = sizeof(int);
}
Expand Down
28 changes: 28 additions & 0 deletions t/io/socket.t
Expand Up @@ -281,6 +281,34 @@ SKIP: {
), "0\n", {}, "fresh socket not inherited across exec");
}

SKIP:
{
my $val;
{
package SetsockoptMagic;
sub TIESCALAR { bless {}, shift }
sub FETCH { $val }
}
# setsockopt() magic
socket(my $sock, PF_INET, SOCK_STREAM, $tcp);
$val = 0;
# set a known value
ok(setsockopt($sock, SOL_SOCKET, SO_REUSEADDR, 1),
"set known SO_REUSEADDR");
isnt(getsockopt($sock, SOL_SOCKET, SO_REUSEADDR), pack("i", 0),
"check that worked");
tie my $m, "SetsockoptMagic";
# trigger the magic with the value 0
$val = pack("i", 0);
my $temp = $m;

$val = 1;
ok(setsockopt($sock, SOL_SOCKET, SO_REUSEADDR, $m),
"set SO_REUSEADDR from magic");
isnt(getsockopt($sock, SOL_SOCKET, SO_REUSEADDR), pack("i", 0),
"check SO_REUSEADDR set correctly");
}

done_testing();

my @child_tests;
Expand Down

0 comments on commit ad1d635

Please sign in to comment.