Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit812a6c2

Browse files
committed
- Move most of the I/O in both libpq and the backend to a set
of common routines in pqcomprim.c (pq communication primitives). Not all adapted to it yet, but it's a start. - Rewritten some of those routines, to write/read bigger chunks of data, precomputing stuff in buffers instead of sending out byte by byte. - As a consequence, I need to know the endianness of the machine. Currently I rely on getting it from machine/endian.h, but this may not be available everywhere? (Who the hell thought it was a good idea to pass integers to the backend the other way around than the normal network byte order? *argl*) - Libpq looks in the environment for magic variables, and upon establishing a connection to the backend, sends it queries of the form "SET var_name TO 'var_value'". This needs a change in the backend parser (Mr. Parser, are you there? :) - Currently it looks for two Env-Vars, namely PG_DATEFORMAT and PG_FLOATFORMAT. What else makes sense? PG_TIMEFORMAT? PG_TIMEZONE?From: "Martin J. Laubach" <mjl@wwx.vip.at>
1 parentd146305 commit812a6c2

File tree

6 files changed

+275
-68
lines changed

6 files changed

+275
-68
lines changed

‎src/backend/libpq/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for libpq subsystem (backend half of libpq interface)
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/libpq/Makefile,v 1.5 1997/03/12 21:17:45 scrappy Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/libpq/Makefile,v 1.6 1997/03/18 20:14:32 scrappy Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -23,7 +23,7 @@ CFLAGS+= $(KRBFLAGS)
2323
LDADD+=$(KRBLIBS)
2424
endif
2525

26-
OBJS = be-dumpdata.o be-fsstubs.o be-pqexec.o\
26+
OBJS = be-dumpdata.o be-fsstubs.o be-pqexec.opqcomprim.o\
2727
auth.o hba.o pqcomm.o portal.o util.o portalbuf.o pqpacket.o pqsignal.o\
2828
password.o
2929

‎src/backend/libpq/pqcomm.c

Lines changed: 78 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*-------------------------------------------------------------------------
1+
/*-------------------------------------------------------------------------
22
*
33
* pqcomm.c--
44
* Communication functions between the Frontend and the Backend
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.12 1997/03/12 21:17:58 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.13 1997/03/18 20:14:33 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -206,26 +206,29 @@ pq_getstr(char *s, int maxlen)
206206
* the line ended within maxlen bytes.)
207207
*1 in other cases
208208
*/
209-
int
210-
PQgetline(char*s,intmaxlen)
211-
{
212-
intc='\0';
213-
209+
intPQgetline(char*s,intmaxlen)
210+
{
214211
if (!Pfin|| !s||maxlen <=1)
215212
return(EOF);
216213

217-
for (;maxlen>1&& (c=pq_getc(Pfin))!='\n'&&c!=EOF;--maxlen) {
218-
*s++=c;
219-
}
214+
if(fgets(s,maxlen-1,Pfin)==NULL)
215+
{
216+
returnfeof(Pfin) ?EOF :1;
217+
}
218+
else
219+
{
220+
for( ;*s;*s++)
221+
{
222+
if(*s=='\n')
223+
{
220224
*s='\0';
225+
break;
226+
}
227+
}
228+
}
221229

222-
if (c==EOF) {
223-
return(EOF);/* error -- reached EOF before \n */
224-
}elseif (c=='\n') {
225-
return(0);/* done with this line */
230+
return0;
226231
}
227-
return(1);/* returning a full buffer */
228-
}
229232

230233
/*
231234
* USER FUNCTION - sends a string to the backend.
@@ -252,6 +255,9 @@ PQputline(char *s)
252255
int
253256
pq_getnchar(char*s,intoff,intmaxlen)
254257
{
258+
returnpqGetNBytes(s+off,maxlen,Pfin);
259+
260+
#if0
255261
intc='\0';
256262

257263
if (Pfin== (FILE*)NULL) {
@@ -270,6 +276,7 @@ pq_getnchar(char *s, int off, int maxlen)
270276
if (c==EOF)
271277
return(EOF);
272278
return(!EOF);
279+
#endif
273280
}
274281

275282
/* --------------------------------
@@ -282,20 +289,38 @@ pq_getnchar(char *s, int off, int maxlen)
282289
int
283290
pq_getint(intb)
284291
{
285-
intn,c,p;
286-
287-
if (Pfin== (FILE*)NULL) {
288-
/*elog(DEBUG, "pq_getint: Input descriptor is null"); */
289-
return(EOF);
292+
intn,status=1;
293+
294+
if(!Pfin)
295+
returnEOF;
296+
/* mjl: Seems inconsisten w/ return value of pq_putint (void). Also,
297+
EOF is a valid return value for an int! XXX */
298+
299+
switch(b)
300+
{
301+
case1:
302+
status= ((n=fgetc(Pfin))==EOF);
303+
break;
304+
case2:
305+
pqGetShort(&n,Pfin);
306+
break;
307+
case4:
308+
pqGetLong(&n,Pfin);
309+
break;
310+
default:
311+
fprintf(stderr,"** Unsupported size %d\n",b);
290312
}
291313

292-
n=p=0;
293-
while (b--&& (c=pq_getc(Pfin))!=EOF&&p<32) {
294-
n |= (c&0xff) <<p;
295-
p+=8;
314+
if(status)
315+
{
316+
(void)sprintf(PQerrormsg,
317+
"FATAL: pq_getint failed: errno=%d\n",errno);
318+
fputs(PQerrormsg,stderr);
319+
pqdebug("%s",PQerrormsg);
320+
n=0;
296321
}
297322

298-
return(n);
323+
returnn;
299324
}
300325

301326
/* --------------------------------
@@ -305,26 +330,13 @@ pq_getint(int b)
305330
void
306331
pq_putstr(char*s)
307332
{
308-
intstatus;
309-
310-
if (Pfout) {
311-
status=fputs(s,Pfout);
312-
if (status==EOF) {
313-
(void)sprintf(PQerrormsg,
314-
"FATAL: pq_putstr: fputs() failed: errno=%d\n",
315-
errno);
316-
fputs(PQerrormsg,stderr);
317-
pqdebug("%s",PQerrormsg);
318-
}
319-
status=fputc('\0',Pfout);
320-
if (status==EOF) {
333+
if(pqPutString(s,Pfout))
334+
{
321335
(void)sprintf(PQerrormsg,
322-
"FATAL: pq_putstr: fputc() failed: errno=%d\n",
323-
errno);
336+
"FATAL: pq_putstr: fputs() failed: errno=%d\n",errno);
324337
fputs(PQerrormsg,stderr);
325338
pqdebug("%s",PQerrormsg);
326339
}
327-
}
328340
}
329341

330342
/* --------------------------------
@@ -333,22 +345,16 @@ pq_putstr(char *s)
333345
*/
334346
void
335347
pq_putnchar(char*s,intn)
336-
{
337-
intstatus;
338-
339-
if (Pfout) {
340-
while (n--) {
341-
status=fputc(*s++,Pfout);
342-
if (status==EOF) {
348+
{
349+
if(pqPutNBytes(s,n,Pfout))
350+
{
343351
(void)sprintf(PQerrormsg,
344352
"FATAL: pq_putnchar: fputc() failed: errno=%d\n",
345353
errno);
346354
fputs(PQerrormsg,stderr);
347355
pqdebug("%s",PQerrormsg);
348356
}
349357
}
350-
}
351-
}
352358

353359
/* --------------------------------
354360
*pq_putint - send an integer to connection
@@ -362,22 +368,31 @@ pq_putint(int i, int b)
362368
{
363369
intstatus;
364370

365-
if (b>4)
366-
b=4;
367-
368-
if (Pfout) {
369-
while (b--) {
370-
status=fputc(i&0xff,Pfout);
371-
i >>=8;
372-
if (status==EOF) {
371+
if(!Pfout)return;
372+
373+
status=1;
374+
switch(b)
375+
{
376+
case1:
377+
status= (fputc(i,Pfout)==EOF);
378+
break;
379+
case2:
380+
status=pqPutShort(i,Pfout);
381+
break;
382+
case4:
383+
status=pqPutLong(i,Pfout);
384+
break;
385+
default:
386+
fprintf(stderr,"** Unsupported size %d\n",b);
387+
}
388+
389+
if(status)
390+
{
373391
(void)sprintf(PQerrormsg,
374-
"FATAL: pq_putint: fputc() failed: errno=%d\n",
375-
errno);
392+
"FATAL: pq_putint failed: errno=%d\n",errno);
376393
fputs(PQerrormsg,stderr);
377394
pqdebug("%s",PQerrormsg);
378395
}
379-
}
380-
}
381396
}
382397

383398
/* ---

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp