/* On failure, the handler should return NULL after freeing the result */ if (!slot->handler(result, slot->connection, slot->handler_context)) returnfalse;
/* Ok, we have to free it ourself */
PQclear(result); returntrue;
}
if (WSAGetLastError() == WSAEINTR)
errno = EINTR;
} #endif
if (i < 0 && errno == EINTR) continue; /* ignore this */ if (i < 0 || CancelRequested) return -1; /* but not this */ if (i == 0) continue; /* timeout (Win32 only) */ break;
}
/* We must reconstruct the fd_set for each call to select_loop */
FD_ZERO(&slotset);
for (i = 0; i < sa->numslots; i++)
{ int sock;
/* We shouldn't get here if we still have slots without connections */
Assert(sa->slots[i].connection != NULL);
sock = PQsocket(sa->slots[i].connection);
/* *Wedon'treallyexpectanyconnectionstolosetheirsocketsafter *startup,butjustincase,copebyignoringthem.
*/ if (sock < 0) continue;
/* Keep track of the first valid connection we see. */ if (cancelconn == NULL)
cancelconn = sa->slots[i].connection;
FD_SET(sock, &slotset); if (sock > maxFd)
maxFd = sock;
}
/* *Ifwegetthisfarwithnovalidconnections,processingcannot *continue.
*/ if (cancelconn == NULL) returnfalse;
SetCancelConn(cancelconn);
i = select_loop(maxFd, &slotset);
ResetCancelConn();
/* failure? */ if (i < 0) returnfalse;
for (i = 0; i < sa->numslots; i++)
{ int sock;
sock = PQsocket(sa->slots[i].connection);
if (sock >= 0 && FD_ISSET(sock, &slotset))
{ /* select() says input is available, so consume it */
PQconsumeInput(sa->slots[i].connection);
}
/* Collect result(s) as long as any are available */ while (!PQisBusy(sa->slots[i].connection))
{
PGresult *result = PQgetResult(sa->slots[i].connection);
if (result != NULL)
{ /* Handle and discard the command result */ if (!processQueryResult(&sa->slots[i], result)) returnfalse;
} else
{ /* This connection has become idle */
sa->slots[i].inUse = false;
ParallelSlotClearHandler(&sa->slots[i]); break;
}
}
} returntrue;
}
/* *POSIXdefinesFD_SETSIZEasthehighestfiledescriptoracceptableto *FD_SET()andalliedmacros.Windowsdefinesitasaceilingonthe *countoffiledescriptorsintheset,notaceilingonthevalueof *eachfiledescriptor;see *https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select *and *https://learn.microsoft.com/en-us/windows/win32/api/winsock/ns-winsock-fd_set. *Wecan'tignorethat,becauseWindowsstartsfiledescriptorsata *highervalue,delaysreuse,andskipsvalues.Withlessthanten *concurrentfiledescriptors,openedandclosedrapidly,onecanreach *filedescriptor1024. * *Doingahardexithereisabitgrotty,butitdoesn'tseemworth *complicatingtheAPItomakeitlessgrotty.
*/ #ifdef WIN32 if (slotno >= FD_SETSIZE)
{
pg_log_error("too many jobs for this platform: %d", slotno); exit(1);
} #else
{ int fd = PQsocket(slot->connection);
if (fd >= FD_SETSIZE)
{
pg_log_error("socket file descriptor out of range for select(): %d",
fd);
pg_log_error_hint("Try fewer jobs."); exit(1);
}
} #endif
/* Setup the connection using the supplied command, if any. */ if (sa->initcmd)
executeCommand(slot->connection, sa->initcmd, sa->echo);
}
while (1)
{ /* First choice: a slot already connected to the desired database. */
offset = find_matching_idle_slot(sa, dbname); if (offset >= 0)
{
sa->slots[offset].inUse = true; return &sa->slots[offset];
}
/* Second choice: a slot not connected to any database. */
offset = find_unconnected_slot(sa); if (offset >= 0)
{
connect_slot(sa, offset, dbname);
sa->slots[offset].inUse = true; return &sa->slots[offset];
}
/* Third choice: a slot connected to the wrong database. */
offset = find_any_idle_slot(sa); if (offset >= 0)
{
disconnectDatabase(sa->slots[offset].connection);
sa->slots[offset].connection = NULL;
connect_slot(sa, offset, dbname);
sa->slots[offset].inUse = true; return &sa->slots[offset];
}
for (i = 0; i < sa->numslots; i++)
{ if (sa->slots[i].connection == NULL) continue; if (!consumeQueryResult(&sa->slots[i])) returnfalse; /* Mark connection as idle */
sa->slots[i].inUse = false;
ParallelSlotClearHandler(&sa->slots[i]);
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.4Bemerkung:
(vorverarbeitet am 2026-08-04)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.