Skip to content

Commit 5167551

Browse files
committed
getsockopt: increase the buffer size for getsockopt()
As suggested in the ticket, the buffer size is now 1024 by default, but this can be adjusted at perl build time with: -Accflags=-DPERL_GETSOCKOPT_SIZE=2048 or similarly with hints. I considered making this adjustable with a ${^...} variable, but that seemed excessive. I don't see a practical way to regression test this, TCP_INFO is non-portable. I did examine strace output for a one-liner that calls getsockopt() and the new buffer size was used. Fixes #19758
1 parent 0d292c7 commit 5167551

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pp_sys.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,14 +2685,17 @@ PP(pp_shutdown)
26852685
RETPUSHUNDEF;
26862686
}
26872687

2688+
#ifndef PERL_GETSOCKOPT_SIZE
2689+
#define PERL_GETSOCKOPT_SIZE 1024
2690+
#endif
26882691

26892692
/* also used for: pp_gsockopt() */
26902693

26912694
PP(pp_ssockopt)
26922695
{
26932696
dSP;
26942697
const int optype = PL_op->op_type;
2695-
SV * const sv = (optype == OP_GSOCKOPT) ? sv_2mortal(newSV(257)) : POPs;
2698+
SV * const sv = (optype == OP_GSOCKOPT) ? sv_2mortal(newSV(PERL_GETSOCKOPT_SIZE+1)) : POPs;
26962699
const unsigned int optname = (unsigned int) POPi;
26972700
const unsigned int lvl = (unsigned int) POPi;
26982701
GV * const gv = MUTABLE_GV(POPs);
@@ -2711,14 +2714,14 @@ PP(pp_ssockopt)
27112714
/* Note: there used to be an explicit SvGROW(sv,257) here, but
27122715
* this is redundant given the sv initialization ternary above */
27132716
(void)SvPOK_only(sv);
2714-
SvCUR_set(sv,256);
2717+
SvCUR_set(sv, PERL_GETSOCKOPT_SIZE);
27152718
*SvEND(sv) ='\0';
27162719
len = SvCUR(sv);
27172720
if (PerlSock_getsockopt(fd, lvl, optname, SvPVX(sv), &len) < 0)
27182721
goto nuts2;
27192722
#if defined(_AIX)
27202723
/* XXX Configure test: does getsockopt set the length properly? */
2721-
if (len == 256)
2724+
if (len == PERL_GETSOCKOPT_SIZE)
27222725
len = sizeof(int);
27232726
#endif
27242727
SvCUR_set(sv, len);

0 commit comments

Comments
 (0)