46 #ifdef HAVE_SYS_SELECT_H 47 #include <sys/select.h> 53 #include "pg_config_paths.h" 68 return PG_VERSION_NUM;
123 int inEnd = conn->
inEnd;
126 while (inCursor < inEnd && inBuffer[inCursor])
129 if (inCursor >= inEnd)
193 fprintf(conn->
Pfdebug,
"From backend (%lu)> ", (
unsigned long) len);
194 fwrite(s, 1, len, conn->
Pfdebug);
217 fprintf(conn->
Pfdebug,
"From backend (%lu)> ", (
unsigned long) len);
240 fwrite(s, 1, len, conn->
Pfdebug);
276 "integer of size %lu not supported by pqGetInt",
277 (
unsigned long) bytes);
282 fprintf(conn->
Pfdebug,
"From backend (#%lu)> %d\n", (
unsigned long) bytes, *result);
312 "integer of size %lu not supported by pqPutInt",
313 (
unsigned long) bytes);
318 fprintf(conn->
Pfdebug,
"To backend (%lu#)> %d\n", (
unsigned long) bytes, value);
336 if (bytes_needed <= (
size_t) newsize)
349 }
while (newsize > 0 && bytes_needed > (
size_t) newsize);
351 if (newsize > 0 && bytes_needed <= (
size_t) newsize)
367 }
while (newsize > 0 && bytes_needed > (
size_t) newsize);
369 if (newsize > 0 && bytes_needed <= (
size_t) newsize)
383 "cannot allocate memory for output buffer\n");
400 if (bytes_needed <= (
size_t) newsize)
430 if (bytes_needed <= (
size_t) newsize)
443 }
while (newsize > 0 && bytes_needed > (
size_t) newsize);
445 if (newsize > 0 && bytes_needed <= (
size_t) newsize)
461 }
while (newsize > 0 && bytes_needed > (
size_t) newsize);
463 if (newsize > 0 && bytes_needed <= (
size_t) newsize)
477 "cannot allocate memory for input buffer\n");
539 msg_type ? msg_type :
' ');
681 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN)) 688 goto definitelyFailed;
697 conn->
inEnd += nread;
711 if (conn->
inEnd > 32768 &&
776 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN)) 783 goto definitelyFailed;
792 conn->
inEnd += nread;
803 "\tThis probably means the server terminated abnormally\n" 804 "\tbefore or while processing the request.\n"));
901 #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN)) 987 if (
pqWait(
true,
true, conn))
997 memmove(conn->
outBuffer, ptr, remaining);
1037 return pqWaitTimed(forRead, forWrite, conn, (time_t) -1);
1052 result =
pqSocketCheck(conn, forRead, forWrite, finish_time);
1150 struct pollfd input_fd;
1153 if (!forRead && !forWrite)
1157 input_fd.events = POLLERR;
1158 input_fd.revents = 0;
1161 input_fd.events |= POLLIN;
1163 input_fd.events |= POLLOUT;
1166 if (end_time == ((time_t) -1))
1170 time_t
now = time(NULL);
1173 timeout_ms = (end_time -
now) * 1000;
1178 return poll(&input_fd, 1, timeout_ms);
1184 struct timeval timeout;
1185 struct timeval *ptr_timeout;
1187 if (!forRead && !forWrite)
1190 FD_ZERO(&input_mask);
1191 FD_ZERO(&output_mask);
1192 FD_ZERO(&except_mask);
1194 FD_SET(sock, &input_mask);
1197 FD_SET(sock, &output_mask);
1198 FD_SET(sock, &except_mask);
1201 if (end_time == ((time_t) -1))
1205 time_t
now = time(NULL);
1208 timeout.tv_sec = end_time -
now;
1211 timeout.tv_usec = 0;
1212 ptr_timeout = &timeout;
1215 return select(sock + 1, &input_mask, &output_mask,
1216 &except_mask, ptr_timeout);
1255 str = getenv(
"PGCLIENTENCODING");
1256 if (str && *str !=
'\0')
1269 libpq_binddomain(
void)
1271 static bool already_bound =
false;
1277 int save_errno = GetLastError();
1279 int save_errno = errno;
1283 already_bound =
true;
1285 ldir = getenv(
"PGLOCALEDIR");
1290 SetLastError(save_errno);
1305 libpq_ngettext(
const char *msgid,
const char *msgid_plural,
unsigned long n)
int pqFlush(PGconn *conn)
int pg_char_to_encoding(const char *name)
int pqReadReady(PGconn *conn)
int pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn)
int pqGets(PQExpBuffer buf, PGconn *conn)
#define pqIsnonblocking(conn)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
def bytes(source, encoding='ascii', errors='strict')
int pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn)
int PQdsplen(const char *s, int encoding)
#define PG_STRERROR_R_BUFLEN
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
int pqPutMsgStart(char msg_type, bool force_len, PGconn *conn)
ssize_t pqsecure_read(PGconn *conn, void *ptr, size_t len)
int pqGetInt(int *result, size_t bytes, PGconn *conn)
void pqDropConnection(PGconn *conn, bool flushInput)
int pqGetnchar(char *s, size_t len, PGconn *conn)
#define PG_PROTOCOL_MAJOR(v)
static int pqSocketPoll(int sock, int forRead, int forWrite, time_t end_time)
static int pqGets_internal(PQExpBuffer buf, PGconn *conn, bool resetbuffer)
int pqPutInt(int value, size_t bytes, PGconn *conn)
ssize_t pqsecure_write(PGconn *conn, const void *ptr, size_t len)
int pqWaitTimed(int forRead, int forWrite, PGconn *conn, time_t finish_time)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
PGNoticeHooks noticeHooks
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn)
int pqReadData(PGconn *conn)
#define libpq_ngettext(s, p, n)
int pqWait(int forRead, int forWrite, PGconn *conn)
bool pgtls_read_pending(PGconn *conn)
int pg_encoding_mblen(int encoding, const char *mbstr)
void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...)
#define select(n, r, w, e, timeout)
int pg_encoding_dsplen(int encoding, const char *mbstr)
int pqPutc(char c, PGconn *conn)
int pqPuts(const char *s, PGconn *conn)
int pqWriteReady(PGconn *conn)
int pqGetc(char *result, PGconn *conn)
#define PG_TEXTDOMAIN(domain)
PQExpBufferData errorMessage
#define dngettext(d, s, p, n)
int pqPutnchar(const char *s, size_t len, PGconn *conn)
#define PQExpBufferBroken(str)
int pqPutMsgEnd(PGconn *conn)
#define ALL_CONNECTION_FAILURE_ERRNOS
static int pqSendSome(PGconn *conn, int len)
int pqSkipnchar(size_t len, PGconn *conn)
void resetPQExpBuffer(PQExpBuffer str)
int PQmblen(const char *s, int encoding)
int pqGets_append(PQExpBuffer buf, PGconn *conn)
Datum now(PG_FUNCTION_ARGS)
void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen)