Also, make error messages consistent.
From: Michael Paquier <michael.paquier@gmail.com>
if (PQsocket(streamConn) < 0)
ereport(ERROR,
(errcode_for_socket_access(),
- errmsg("socket not open")));
+ errmsg("invalid socket: %s", PQerrorMessage(streamConn))));
/* We use poll(2) if available, otherwise select(2) */
{
struct timeval timeout;
struct timeval *timeoutptr = NULL;
+ if (PQsocket(conn) < 0)
+ {
+ fprintf(stderr,
+ _("%s: invalid socket: %s"),
+ progname, PQerrorMessage(conn));
+ goto error;
+ }
+
FD_ZERO(&input_mask);
FD_SET(PQsocket(conn), &input_mask);
if (PQsocket(conn) < 0)
{
- fprintf(stderr, _("%s: socket not open"), progname);
+ fprintf(stderr, _("%s: invalid socket: %s"), progname,
+ PQerrorMessage(conn));
return -1;
}
sock = PQsocket(st->con);
if (sock < 0)
{
- fprintf(stderr, "bad socket: %s", PQerrorMessage(st->con));
+ fprintf(stderr, "invalid socket: %s", PQerrorMessage(st->con));
goto done;
}
if (sock < 0)
{
- fprintf(stderr, "bad socket: %s", PQerrorMessage(st->con));
+ fprintf(stderr, "invalid socket: %s",
+ PQerrorMessage(st->con));
goto done;
}
if (FD_ISSET(sock, &input_mask) ||
static int select_loop(int maxFd, fd_set *workerset, bool *aborting);
-static void init_slot(ParallelSlot *slot, PGconn *conn);
+static void init_slot(ParallelSlot *slot, PGconn *conn, const char *progname);
static void help(const char *progname);
* array contains the connection.
*/
slots = (ParallelSlot *) pg_malloc(sizeof(ParallelSlot) * concurrentCons);
- init_slot(slots, conn);
+ init_slot(slots, conn, progname);
if (parallel)
{
for (i = 1; i < concurrentCons; i++)
{
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false, true);
- init_slot(slots + i, conn);
+ init_slot(slots + i, conn, progname);
}
}
}
static void
-init_slot(ParallelSlot *slot, PGconn *conn)
+init_slot(ParallelSlot *slot, PGconn *conn, const char *progname)
{
slot->connection = conn;
slot->isFree = true;
slot->sock = PQsocket(conn);
+
+ if (slot->sock < 0)
+ {
+ fprintf(stderr, _("%s: invalid socket: %s"), progname,
+ PQerrorMessage(conn));
+ exit(1);
+ }
}
static void
if (conn->sock == PGINVALID_SOCKET)
{
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("socket not open\n"));
+ libpq_gettext("invalid socket\n"));
return -1;
}
PGresult *res;
bool canceled = false;
+ if (sock < 0)
+ {
+ fprintf(stderr, "invalid socket: %s", PQerrorMessage(conn));
+ exit_nicely();
+ }
+
gettimeofday(&start_time, NULL);
FD_ZERO(&read_set);