Skip to content

Commit 4289263

Browse files
committed
windows: Adjust FD_SETSIZE via commandline define
When using precompiled headers, we cannot pre-define macros for the system headers from within .c files, as headers are already processed before the #define in the C file is reached. But we can pre-define using -DFD_SETSIZE, as long as that's also used when building the precompiled header. A few files #define FD_SETSIZE 1024 on windows, as the default is only 64. I am hesitant to change FD_SETSIZE globally on windows, due to src/backend/port/win32/socket.c using it to size on-stack arrays. Instead add -DFD_SETSIZE=1024 when building the specific targets needing it. We likely should move away from using select() in those places, but that's a larger change. Reviewed-by: Thomas Munro <thomas.munro@gmail.com> Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Reviewed-by: Justin Pryzby <pryzby@telsasoft.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/20221005190829.lda7ttalh4mzrvf4@awork3.anarazel.de Discussion: https://postgr.es/m/CA+hUKG+50eOUbN++ocDc0Qnp9Pvmou23DSXu=ZA6fepOcftKqA@mail.gmail.com Discussion: https://postgr.es/m/20190826054000.GE7005%40paquier.xyz
1 parent 0fa4164 commit 4289263

File tree

7 files changed

+31
-12
lines changed

7 files changed

+31
-12
lines changed

src/bin/pgbench/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ LDFLAGS_INTERNAL += -L$(top_builddir)/src/fe_utils -lpgfeutils $(libpq_pgport)
1818

1919
ifneq ($(PORTNAME), win32)
2020
override CFLAGS += $(PTHREAD_CFLAGS)
21+
else
22+
override CPPFLAGS += -DFD_SETSIZE=1024
2123
endif
2224
LIBS += $(PTHREAD_LIBS)
2325

src/bin/pgbench/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pgbench = executable('pgbench',
2727
pgbench_sources,
2828
dependencies: [frontend_code, libpq, thread_dep],
2929
include_directories: include_directories('.'),
30+
c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [],
3031
kwargs: default_bin_args,
3132
)
3233
bin_targets += pgbench

src/bin/pgbench/pgbench.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
*
2828
*/
2929

30-
#ifdef WIN32
31-
#define FD_SETSIZE 1024 /* must set before winsock2.h is included */
30+
#if defined(WIN32) && FD_SETSIZE < 1024
31+
#error FD_SETSIZE needs to have been increased
3232
#endif
3333

3434
#include "postgres_fe.h"

src/fe_utils/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ OBJS = \
3434
simple_list.o \
3535
string_utils.o
3636

37+
ifeq ($(PORTNAME), win32)
38+
override CPPFLAGS += -DFD_SETSIZE=1024
39+
endif
40+
3741
all: libpgfeutils.a
3842

3943
libpgfeutils.a: $(OBJS)

src/fe_utils/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fe_utils_sources += psqlscan
2424
fe_utils = static_library('libpgfeutils',
2525
fe_utils_sources + generated_headers,
2626
include_directories: [postgres_inc, libpq_inc],
27+
c_args: host_system == 'windows' ? ['-DFD_SETSIZE=1024'] : [],
2728
dependencies: frontend_common_code,
2829
kwargs: default_lib_args,
2930
)

src/fe_utils/parallel_slot.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
*-------------------------------------------------------------------------
1313
*/
1414

15-
#ifdef WIN32
16-
#define FD_SETSIZE 1024 /* must set before winsock2.h is included */
15+
#if defined(WIN32) && FD_SETSIZE < 1024
16+
#error FD_SETSIZE needs to have been increased
1717
#endif
1818

1919
#include "postgres_fe.h"

src/tools/msvc/Mkvcbuild.pm

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ my $libpq;
3535
my @unlink_on_exit;
3636

3737
# Set of variables for modules in contrib/ and src/test/modules/
38+
my $contrib_defines = {};
3839
my @contrib_uselibpq = ();
3940
my @contrib_uselibpgport = ();
4041
my @contrib_uselibpgcommon = ();
@@ -52,6 +53,7 @@ my @contrib_excludes = (
5253
'unsafe_tests');
5354

5455
# Set of variables for frontend modules
56+
my $frontend_defines = { 'pgbench' => 'FD_SETSIZE=1024' };
5557
my @frontend_uselibpq =
5658
('pg_amcheck', 'pg_ctl', 'pg_upgrade', 'pgbench', 'psql', 'initdb');
5759
my @frontend_uselibpgport = (
@@ -175,6 +177,7 @@ sub mkvcbuild
175177

176178
$libpgfeutils = $solution->AddProject('libpgfeutils', 'lib', 'misc');
177179
$libpgfeutils->AddDefine('FRONTEND');
180+
$libpgfeutils->AddDefine('FD_SETSIZE=1024');
178181
$libpgfeutils->AddIncludeDir('src/interfaces/libpq');
179182
$libpgfeutils->AddFiles('src/fe_utils', @pgfeutilsfiles);
180183

@@ -1120,27 +1123,28 @@ sub AdjustContribProj
11201123
{
11211124
my $proj = shift;
11221125
AdjustModule(
1123-
$proj, \@contrib_uselibpq,
1124-
\@contrib_uselibpgport, \@contrib_uselibpgcommon,
1125-
$contrib_extralibs, $contrib_extrasource,
1126-
$contrib_extraincludes);
1126+
$proj, $contrib_defines,
1127+
\@contrib_uselibpq, \@contrib_uselibpgport,
1128+
\@contrib_uselibpgcommon, $contrib_extralibs,
1129+
$contrib_extrasource, $contrib_extraincludes);
11271130
return;
11281131
}
11291132

11301133
sub AdjustFrontendProj
11311134
{
11321135
my $proj = shift;
11331136
AdjustModule(
1134-
$proj, \@frontend_uselibpq,
1135-
\@frontend_uselibpgport, \@frontend_uselibpgcommon,
1136-
$frontend_extralibs, $frontend_extrasource,
1137-
$frontend_extraincludes);
1137+
$proj, $frontend_defines,
1138+
\@frontend_uselibpq, \@frontend_uselibpgport,
1139+
\@frontend_uselibpgcommon, $frontend_extralibs,
1140+
$frontend_extrasource, $frontend_extraincludes);
11381141
return;
11391142
}
11401143

11411144
sub AdjustModule
11421145
{
11431146
my $proj = shift;
1147+
my $module_defines = shift;
11441148
my $module_uselibpq = shift;
11451149
my $module_uselibpgport = shift;
11461150
my $module_uselibpgcommon = shift;
@@ -1149,6 +1153,13 @@ sub AdjustModule
11491153
my $module_extraincludes = shift;
11501154
my $n = $proj->{name};
11511155

1156+
if ($module_defines->{$n})
1157+
{
1158+
foreach my $d ($module_defines->{$n})
1159+
{
1160+
$proj->AddDefine($d);
1161+
}
1162+
}
11521163
if (grep { /^$n$/ } @{$module_uselibpq})
11531164
{
11541165
$proj->AddIncludeDir('src\interfaces\libpq');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy