Hi,
I am accelerating the transfer of resultset
from backend to client using the zlib library.
While coding, I was surprised that
magic number 8192 (which is defined as PQ_BUFFER_SIZE in
backend/libpq/pqcomm.c) are written into the code
in interfaces/libpq/fe-misc.
I thought the magic number should be eliminated.
So I defined the magic number 8192 as PQ_BUFFER_SIZE in fe-misc.c.
The result is attached to this mail.
# it is just a slight modification
I am very happy if you accept my proposition.
Best regards,
-- Hideyuki Kawashima
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Hideyuki KAWASHIMA <[EMAIL PROTECTED]> Ph.D.
Research Associate, Keio University
/*-
*
* FILE
* fe-misc.c
*
* DESCRIPTION
* miscellaneous useful functions
*
* The communication routines here are analogous to the ones in
* backend/libpq/pqcomm.c and backend/libpq/pqcomprim.c, but operate
* in the considerably different environment of the frontend libpq.
* In particular, we work with a bare nonblock-mode socket, rather than
* a stdio stream, so that we can avoid unwanted blocking of the application.
*
* XXX: MOVE DEBUG PRINTOUT TO HIGHER LEVEL. As is, block and restart
* will cause repeat printouts.
*
* We must speak the same transmitted data representations as the backend
* routines.
*
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
*$PostgreSQL: pgsql/src/interfaces/libpq/fe-misc.c,v 1.112 2004/12/31
22:03:50 pgsql Exp $
*
*-
*/
#include "postgres_fe.h"
#include
#include
#include
#ifndef WIN32_CLIENT_ONLY
#include
#include
#endif
#ifdef WIN32
#include "win32.h"
#else
#include
#include
#endif
#ifdef HAVE_POLL_H
#include
#endif
#ifdef HAVE_SYS_POLL_H
#include
#endif
#ifdef HAVE_SYS_SELECT_H
#include
#endif
#include "libpq-fe.h"
#include "libpq-int.h"
#include "pqsignal.h"
#include "mb/pg_wchar.h"
#define PQ_BUFFER_SIZE 8192
static int pqPutMsgBytes(const void *buf, size_t len, PGconn *conn);
static int pqSendSome(PGconn *conn, int len);
static int pqSocketCheck(PGconn *conn, int forRead, int forWrite,
time_t end_time);
static int pqSocketPoll(int sock, int forRead, int forWrite, time_t
end_time);
/*
* pqGetc: get 1 character from the connection
*
* All these routines return 0 on success, EOF on error.
* Note that for the Get routines, EOF only means there is not enough
* data in the buffer, not that there is necessarily a hard error.
*/
int
pqGetc(char *result, PGconn *conn)
{
if (conn->inCursor >= conn->inEnd)
return EOF;
*result = conn->inBuffer[conn->inCursor++];
if (conn->Pfdebug)
fprintf(conn->Pfdebug, "From backend> %c\n", *result);
return 0;
}
/*
* pqPutc: write 1 char to the current message
*/
int
pqPutc(char c, PGconn *conn)
{
if (pqPutMsgBytes(&c, 1, conn))
return EOF;
if (conn->Pfdebug)
fprintf(conn->Pfdebug, "To backend> %c\n", c);
return 0;
}
/*
* pqGets:
* get a null-terminated string from the connection,
* and store it in an expansible PQExpBuffer.
* If we run out of memory, all of the string is still read,
* but the excess characters are silently discarded.
*/
int
pqGets(PQExpBuffer buf, PGconn *conn)
{
/* Copy conn data to locals for faster search loop */
char *inBuffer = conn->inBuffer;
int inCursor = conn->inCursor;
int inEnd = conn->inEnd;
int slen;
while (inCursor < inEnd && inBuffer[inCursor])
inCursor++;
if (inCursor >= inEnd)
return EOF;
slen = inCursor - conn->inCursor;
resetPQExpBuffer(buf);
appendBinaryPQExpBuffer(buf, inBuffer + conn->inCursor, slen);
conn->inCursor = ++inCursor;
if (conn->Pfdebug)
fprintf(conn->Pfdebug, "From backend> \"%s\"\n",
buf->data);
return 0;
}
/*
* pqPuts: write a null-terminated string to the current message
*/
int
pqPuts(const char *s, PGconn *conn)
{
if (pqPutMsgBytes(s, strlen(s) + 1, conn))
return EOF;
if (conn->Pfdebug)
fprintf(conn->Pfdebug, "To backend> '%s'\n", s);
return 0;
}
/*
* pqGetnchar:
* get a string of exactly len bytes in buffer s, no null termination
*/
int
p