summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorTony Cook <tony@develop-help.com>2023-03-08 15:39:53 +1100
committerTony Cook <tony@develop-help.com>2023-03-23 14:43:38 +1100
commit516755179513dbb6a9fea3194452792e837d64b9 (patch)
tree335c6a468b42ba0378db786dd20ccb0662e6f156 /pp_sys.c
parent0d292c706462f0a0e7cd64ef002bd8d21513295d (diff)
downloadperl-516755179513dbb6a9fea3194452792e837d64b9.tar.gz
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
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/pp_sys.c b/pp_sys.c
index 348c43a261..4cffe6e7bd 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2685,6 +2685,9 @@ PP(pp_shutdown)
RETPUSHUNDEF;
}
+#ifndef PERL_GETSOCKOPT_SIZE
+#define PERL_GETSOCKOPT_SIZE 1024
+#endif
/* also used for: pp_gsockopt() */
@@ -2692,7 +2695,7 @@ PP(pp_ssockopt)
{
dSP;
const int optype = PL_op->op_type;
- SV * const sv = (optype == OP_GSOCKOPT) ? sv_2mortal(newSV(257)) : POPs;
+ SV * const sv = (optype == OP_GSOCKOPT) ? sv_2mortal(newSV(PERL_GETSOCKOPT_SIZE+1)) : POPs;
const unsigned int optname = (unsigned int) POPi;
const unsigned int lvl = (unsigned int) POPi;
GV * const gv = MUTABLE_GV(POPs);
@@ -2711,14 +2714,14 @@ PP(pp_ssockopt)
/* Note: there used to be an explicit SvGROW(sv,257) here, but
* this is redundant given the sv initialization ternary above */
(void)SvPOK_only(sv);
- SvCUR_set(sv,256);
+ SvCUR_set(sv, PERL_GETSOCKOPT_SIZE);
*SvEND(sv) ='\0';
len = SvCUR(sv);
if (PerlSock_getsockopt(fd, lvl, optname, SvPVX(sv), &len) < 0)
goto nuts2;
#if defined(_AIX)
/* XXX Configure test: does getsockopt set the length properly? */
- if (len == 256)
+ if (len == PERL_GETSOCKOPT_SIZE)
len = sizeof(int);
#endif
SvCUR_set(sv, len);