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

Commitea58f28

Browse files
committed
om: "Martin J. Laubach" <mjl@CSlab.tuwien.ac.at>
Subject: [HACKERS] Patch for io routines I am currently trying to improve on the front-backend communicationroutines; and noticed that lots of code are duplicated for libpq andthe backend. This is a first patch that tries to share code betweenthe two, more to follow. mjl
1 parenta9049a4 commitea58f28

File tree

3 files changed

+89
-90
lines changed

3 files changed

+89
-90
lines changed

‎src/include/libpq/pqcomm.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pqcomm.h,v 1.8 1997/03/12 21:22:19 scrappy Exp $
9+
* $Id: pqcomm.h,v 1.9 1997/03/16 18:50:47 scrappy Exp $
1010
*
1111
* NOTES
1212
* Some of this should move to libpq.h
@@ -123,6 +123,11 @@ typedef struct Port {
123123
externFILE*Pfout,*Pfin;
124124
externintPQAsyncNotifyWaiting;
125125

126+
/* in pqcompriv.c */
127+
intpqGetShort(int*,FILE*);
128+
intpqGetLong(int*,FILE*);
129+
intpqPutShort(int,FILE*);
130+
intpqPutLong(int,FILE*);
126131
/*
127132
* prototypes for functions in pqpacket.c
128133
*/

‎src/interfaces/libpq/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
#
99
# IDENTIFICATION
10-
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.29 1997/03/15 19:17:03 scrappy Exp $
10+
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.30 1997/03/16 18:51:13 scrappy Exp $
1111
#
1212
#-------------------------------------------------------------------------
1313

@@ -24,7 +24,7 @@ CFLAGS+= $(KRBFLAGS)
2424
endif
2525

2626
OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-lobj.o\
27-
dllist.o pqsignal.o
27+
dllist.o pqsignal.opqcomprim.o
2828

2929
# Shared library stuff
3030
shlib :=
@@ -58,7 +58,10 @@ fe-lobj.o: ../backend/fmgr.h
5858
# We need to compile this with special options for shared libs,
5959
# so we can't use the object in ../backend
6060
dllist.c:../backend/lib/dllist.c
61-
-ln ../backend/lib/dllist.c
61+
-ln -s ../backend/lib/dllist.c
62+
63+
pqcomprim.c: ../backend/libpq/pqcomprim.c
64+
-ln -s ../backend/libpq/pqcomprim.c
6265

6366
# The following rules cause dependencies in the backend directory to
6467
# get made if they don't exist, but don't cause them to get remade if they

‎src/interfaces/libpq/fe-misc.c

Lines changed: 77 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.4 1996/12/31 07:29:17 bryanh Exp $
14+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.5 1997/03/16 18:51:29 scrappy Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -23,181 +23,172 @@
2323

2424
#include"libpq-fe.h"
2525

26+
/* --------------------------------------------------------------------- */
2627
/* pqGetc:
2728
get a character from stream f
2829
2930
if debug is set, also echo the character fetched
3031
*/
31-
int
32-
pqGetc(FILE*fin,FILE*debug)
32+
intpqGetc(FILE*fin,FILE*debug)
3333
{
3434
intc;
3535

3636
c=getc(fin);
37+
3738
if (debug&&c!=EOF)
3839
fprintf(debug,"From backend> %c\n",c);
40+
3941
returnc;
4042
}
4143

44+
/* --------------------------------------------------------------------- */
4245
/* pqPutnchar:
4346
send a string of exactly len length into stream f
4447
4548
returns 1 if there was an error, 0 otherwise.
4649
*/
47-
int
48-
pqPutnchar(constchar*s,intlen,FILE*f,FILE*debug)
50+
intpqPutnchar(constchar*s,intlen,FILE*f,FILE*debug)
4951
{
50-
intstatus;
51-
5252
if (f==NULL)
5353
return1;
5454

55-
if (debug)fputs("To backend>",debug);
56-
while (len--) {
57-
status=fputc(*s,f);
58-
if (debug)
59-
fputc(*s,debug);
60-
s++;
61-
if (status==EOF)
55+
if(debug)
56+
fprintf(debug,"To backend> %s\n",s);
57+
58+
if(fwrite(s,1,len,f)!=len)
6259
return1;
63-
}
64-
if (debug)fputc('\n',debug);
60+
6561
return0;
6662
}
6763

64+
/* --------------------------------------------------------------------- */
6865
/* pqGetnchar:
6966
get a string of exactly len length from stream f
7067
*/
71-
int
72-
pqGetnchar(char*s,intlen,FILE*f,FILE*debug)
68+
intpqGetnchar(char*s,intlen,FILE*f,FILE*debug)
7369
{
74-
intc;
70+
intcnt;
7571

7672
if (f==NULL)
7773
return1;
7874

79-
while (len--&& (c=getc(f))!=EOF)
80-
*s++=c;
81-
*s='\0';
75+
cnt=fread(s,1,len,f);
76+
s[cnt]='\0';
77+
/* mjl: actually needs up to len+1 bytes, is this okay? XXX */
78+
79+
if (debug)
80+
fprintf(debug,"From backend (%d)> %s\n",len,s);
8281

83-
if (debug) {
84-
fprintf(debug,"From backend> %s\n",s);
85-
}
8682
return0;
8783
}
8884

85+
/* --------------------------------------------------------------------- */
8986
/* pqGets:
9087
get a string of up to length len from stream f
9188
*/
92-
int
93-
pqGets(char*s,intlen,FILE*f,FILE*debug)
89+
intpqGets(char*s,intlen,FILE*f,FILE*debug)
9490
{
9591
intc;
92+
constchar*str=s;
9693

9794
if (f==NULL)
9895
return1;
9996

10097
while (len--&& (c=getc(f))!=EOF&&c)
10198
*s++=c;
10299
*s='\0';
100+
/* mjl: actually needs up to len+1 bytes, is this okay? XXX */
101+
102+
if (debug)
103+
fprintf(debug,"From backend> \"%s\"\n",str);
103104

104-
if (debug) {
105-
fprintf(debug,"From backend> %s\n",s);
106-
}
107105
return0;
108106
}
109107

110-
108+
/* --------------------------------------------------------------------- */
111109
/* pgPutInt
112-
send an integer of up to 4 bytesto the file stream
113-
do this one byte at at time.
114-
This insures that machines with different ENDIANness can talk to each other
115-
get a n-byte integer from the stream into result
110+
send an integer of 2 or 4 bytes to the file stream, compensate
111+
for host endianness.
116112
returns 0 if successful, 1 otherwise
117113
*/
118-
int
119-
pqPutInt(constintinteger,intbytes,FILE*f,FILE*debug)
114+
intpqPutInt(constintinteger,intbytes,FILE*f,FILE*debug)
120115
{
121-
inti;
122-
intstatus;
123-
124-
i=integer;
125-
126-
if (bytes>4)
127-
bytes=4;
128-
129-
while (bytes--) {
130-
status=fputc(i&0xff,f);
131-
i >>=8;
132-
if (status==EOF) {
133-
return1;
134-
}
135-
}
136-
if (debug)fprintf(debug,"To backend (#)> %d\n",integer);
137-
return0;
116+
intretval=0;
117+
118+
switch(bytes)
119+
{
120+
case2:
121+
retval=pqPutShort(integer,f);
122+
break;
123+
case4:
124+
retval=pqPutLong(integer,f);
125+
break;
126+
default:
127+
fprintf(stderr,"** int size %d not supported\n",bytes);
128+
retval=1;
129+
}
130+
131+
if (debug)fprintf(debug,"To backend (%d#)> %d\n",bytes,integer);
132+
133+
returnretval;
138134
}
139135

136+
/* --------------------------------------------------------------------- */
140137
/* pgGetInt
141-
reconstructs the integer one byte at a time.
142-
This insures that machines with different ENDIANness can talk to each other
143-
get a n-byte integer from the stream into result
138+
read a 2 or 4 byte integer from the stream and swab it around
139+
to compensate for different endianness
144140
returns 0 if successful
145141
*/
146-
int
147-
pqGetInt(int*result,intbytes,FILE*f,FILE*debug)
142+
intpqGetInt(int*result,intbytes,FILE*f,FILE*debug)
148143
{
149-
intc;
150-
intp;
151-
intn;
152-
153-
if (f==NULL)
154-
return1;
144+
intretval=0;
155145

156-
p=0;
157-
n=0;
158-
while (bytes&& (c=getc(f))!=EOF)
146+
switch(bytes)
159147
{
160-
n |= (c&0xff) <<p;
161-
p+=8;
162-
bytes--;
148+
case2:
149+
retval=pqGetShort(result,f);
150+
break;
151+
case4:
152+
retval=pqGetLong(result,f);
153+
break;
154+
default:
155+
fprintf(stderr,"** int size %d not supported\n",bytes);
156+
retval=1;
163157
}
164158

165-
if (bytes!=0)
166-
return1;
167-
168-
*result=n;
169159
if (debug)
170-
fprintf(debug,"From backend (#)> %d\n",*result);
171-
return0;
172-
}
160+
fprintf(debug,"From backend (#%d)> %d\n",bytes,*result);
173161

162+
returnretval;
163+
}
174164

175-
int
176-
pqPuts(constchar*s,FILE*f,FILE*debug)
165+
/* --------------------------------------------------------------------- */
166+
intpqPuts(constchar*s,FILE*f,FILE*debug)
177167
{
178168
if (f==NULL)
179169
return1;
180170

181-
if (fputs(s,f)==EOF)
171+
if (fputs(s,f)==EOF)
182172
return1;
183173

184-
fputc('\0',f);/* important to send an endingEOF since backend expects it */
174+
fputc('\0',f);/* important to send an ending\0 since backend expects it */
185175
fflush(f);
186176

187177
if (debug) {
188178
fprintf(debug,"To backend> %s\n",s);
189179
}
180+
190181
return0;
191182
}
192183

193-
194-
void
195-
pqFlush(FILE*f,FILE*debug)
184+
/* --------------------------------------------------------------------- */
185+
voidpqFlush(FILE*f,FILE*debug)
196186
{
197187
if (f)
198188
fflush(f);
189+
199190
if (debug)
200191
fflush(debug);
201192
}
202193

203-
194+
/* --------------------------------------------------------------------- */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp