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

Commitf4b54e1

Browse files
Introduce macros for protocol characters.
This commit introduces descriptively-named macros for theidentifiers used in wire protocol messages. These new macros areplaced in a new header file so that they can be easily used bythird-party code.Author: Dave CramerReviewed-by: Alvaro Herrera, Tatsuo Ishii, Peter Smith, Robert Haas, Tom Lane, Peter Eisentraut, Michael PaquierDiscussion:https://postgr.es/m/CADK3HHKbBmK-PKf1bPNFoMC%2BoBt%2BpD9PH8h5nvmBQskEHm-Ehw%40mail.gmail.com
1 parent7114791 commitf4b54e1

File tree

25 files changed

+305
-204
lines changed

25 files changed

+305
-204
lines changed

‎src/backend/access/common/printsimple.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include"access/printsimple.h"
2222
#include"catalog/pg_type.h"
23+
#include"libpq/protocol.h"
2324
#include"libpq/pqformat.h"
2425
#include"utils/builtins.h"
2526

@@ -32,7 +33,7 @@ printsimple_startup(DestReceiver *self, int operation, TupleDesc tupdesc)
3233
StringInfoDatabuf;
3334
inti;
3435

35-
pq_beginmessage(&buf,'T');/* RowDescription */
36+
pq_beginmessage(&buf,PqMsg_RowDescription);
3637
pq_sendint16(&buf,tupdesc->natts);
3738

3839
for (i=0;i<tupdesc->natts;++i)
@@ -65,7 +66,7 @@ printsimple(TupleTableSlot *slot, DestReceiver *self)
6566
slot_getallattrs(slot);
6667

6768
/* Prepare and send message */
68-
pq_beginmessage(&buf,'D');
69+
pq_beginmessage(&buf,PqMsg_DataRow);
6970
pq_sendint16(&buf,tupdesc->natts);
7071

7172
for (i=0;i<tupdesc->natts;++i)

‎src/backend/access/transam/parallel.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
11271127

11281128
switch (msgtype)
11291129
{
1130-
case'K':/* BackendKeyData */
1130+
casePqMsg_BackendKeyData:
11311131
{
11321132
int32pid=pq_getmsgint(msg,4);
11331133

@@ -1137,8 +1137,8 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
11371137
break;
11381138
}
11391139

1140-
case'E':/* ErrorResponse */
1141-
case'N':/* NoticeResponse */
1140+
casePqMsg_ErrorResponse:
1141+
casePqMsg_NoticeResponse:
11421142
{
11431143
ErrorDataedata;
11441144
ErrorContextCallback*save_error_context_stack;
@@ -1183,7 +1183,7 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
11831183
break;
11841184
}
11851185

1186-
case'A':/* NotifyResponse */
1186+
casePqMsg_NotificationResponse:
11871187
{
11881188
/* Propagate NotifyResponse. */
11891189
int32pid;
@@ -1217,7 +1217,7 @@ HandleParallelMessage(ParallelContext *pcxt, int i, StringInfo msg)
12171217
break;
12181218
}
12191219

1220-
case'X':/* Terminate, indicating clean exit */
1220+
casePqMsg_Terminate:
12211221
{
12221222
shm_mq_detach(pcxt->worker[i].error_mqh);
12231223
pcxt->worker[i].error_mqh=NULL;
@@ -1372,7 +1372,7 @@ ParallelWorkerMain(Datum main_arg)
13721372
* protocol message is defined, but it won't actually be used for anything
13731373
* in this case.
13741374
*/
1375-
pq_beginmessage(&msgbuf,'K');
1375+
pq_beginmessage(&msgbuf,PqMsg_BackendKeyData);
13761376
pq_sendint32(&msgbuf, (int32)MyProcPid);
13771377
pq_sendint32(&msgbuf, (int32)MyCancelKey);
13781378
pq_endmessage(&msgbuf);
@@ -1550,7 +1550,7 @@ ParallelWorkerMain(Datum main_arg)
15501550
DetachSession();
15511551

15521552
/* Report success. */
1553-
pq_putmessage('X',NULL,0);
1553+
pq_putmessage(PqMsg_Terminate,NULL,0);
15541554
}
15551555

15561556
/*

‎src/backend/backup/basebackup_copy.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ bbsink_copystream_begin_backup(bbsink *sink)
152152
SendTablespaceList(state->tablespaces);
153153

154154
/* Send a CommandComplete message */
155-
pq_puttextmessage('C',"SELECT");
155+
pq_puttextmessage(PqMsg_CommandComplete,"SELECT");
156156

157157
/* Begin COPY stream. This will be used for all archives + manifest. */
158158
SendCopyOutResponse();
@@ -169,7 +169,7 @@ bbsink_copystream_begin_archive(bbsink *sink, const char *archive_name)
169169
StringInfoDatabuf;
170170

171171
ti=list_nth(state->tablespaces,state->tablespace_num);
172-
pq_beginmessage(&buf,'d');/* CopyData */
172+
pq_beginmessage(&buf,PqMsg_CopyData);
173173
pq_sendbyte(&buf,'n');/* New archive */
174174
pq_sendstring(&buf,archive_name);
175175
pq_sendstring(&buf,ti->path==NULL ?"" :ti->path);
@@ -220,7 +220,7 @@ bbsink_copystream_archive_contents(bbsink *sink, size_t len)
220220
{
221221
mysink->last_progress_report_time=now;
222222

223-
pq_beginmessage(&buf,'d');/* CopyData */
223+
pq_beginmessage(&buf,PqMsg_CopyData);
224224
pq_sendbyte(&buf,'p');/* Progress report */
225225
pq_sendint64(&buf,state->bytes_done);
226226
pq_endmessage(&buf);
@@ -246,7 +246,7 @@ bbsink_copystream_end_archive(bbsink *sink)
246246

247247
mysink->bytes_done_at_last_time_check=state->bytes_done;
248248
mysink->last_progress_report_time=GetCurrentTimestamp();
249-
pq_beginmessage(&buf,'d');/* CopyData */
249+
pq_beginmessage(&buf,PqMsg_CopyData);
250250
pq_sendbyte(&buf,'p');/* Progress report */
251251
pq_sendint64(&buf,state->bytes_done);
252252
pq_endmessage(&buf);
@@ -261,7 +261,7 @@ bbsink_copystream_begin_manifest(bbsink *sink)
261261
{
262262
StringInfoDatabuf;
263263

264-
pq_beginmessage(&buf,'d');/* CopyData */
264+
pq_beginmessage(&buf,PqMsg_CopyData);
265265
pq_sendbyte(&buf,'m');/* Manifest */
266266
pq_endmessage(&buf);
267267
}
@@ -318,7 +318,7 @@ SendCopyOutResponse(void)
318318
{
319319
StringInfoDatabuf;
320320

321-
pq_beginmessage(&buf,'H');
321+
pq_beginmessage(&buf,PqMsg_CopyOutResponse);
322322
pq_sendbyte(&buf,0);/* overall format */
323323
pq_sendint16(&buf,0);/* natts */
324324
pq_endmessage(&buf);
@@ -330,7 +330,7 @@ SendCopyOutResponse(void)
330330
staticvoid
331331
SendCopyDone(void)
332332
{
333-
pq_putemptymessage('c');
333+
pq_putemptymessage(PqMsg_CopyDone);
334334
}
335335

336336
/*
@@ -368,7 +368,7 @@ SendXlogRecPtrResult(XLogRecPtr ptr, TimeLineID tli)
368368
end_tup_output(tstate);
369369

370370
/* Send a CommandComplete message */
371-
pq_puttextmessage('C',"SELECT");
371+
pq_puttextmessage(PqMsg_CommandComplete,"SELECT");
372372
}
373373

374374
/*

‎src/backend/commands/async.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ NotifyMyFrontEnd(const char *channel, const char *payload, int32 srcPid)
22812281
{
22822282
StringInfoDatabuf;
22832283

2284-
pq_beginmessage(&buf,'A');
2284+
pq_beginmessage(&buf,PqMsg_NotificationResponse);
22852285
pq_sendint32(&buf,srcPid);
22862286
pq_sendstring(&buf,channel);
22872287
pq_sendstring(&buf,payload);

‎src/backend/commands/copyfromparse.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ ReceiveCopyBegin(CopyFromState cstate)
174174
int16format= (cstate->opts.binary ?1 :0);
175175
inti;
176176

177-
pq_beginmessage(&buf,'G');
177+
pq_beginmessage(&buf,PqMsg_CopyInResponse);
178178
pq_sendbyte(&buf,format);/* overall format */
179179
pq_sendint16(&buf,natts);
180180
for (i=0;i<natts;i++)
@@ -279,13 +279,13 @@ CopyGetData(CopyFromState cstate, void *databuf, int minread, int maxread)
279279
/* Validate message type and set packet size limit */
280280
switch (mtype)
281281
{
282-
case'd':/* CopyData */
282+
casePqMsg_CopyData:
283283
maxmsglen=PQ_LARGE_MESSAGE_LIMIT;
284284
break;
285-
case'c':/* CopyDone */
286-
case'f':/* CopyFail */
287-
case'H':/* Flush */
288-
case'S':/* Sync */
285+
casePqMsg_CopyDone:
286+
casePqMsg_CopyFail:
287+
casePqMsg_Flush:
288+
casePqMsg_Sync:
289289
maxmsglen=PQ_SMALL_MESSAGE_LIMIT;
290290
break;
291291
default:
@@ -305,20 +305,20 @@ CopyGetData(CopyFromState cstate, void *databuf, int minread, int maxread)
305305
/* ... and process it */
306306
switch (mtype)
307307
{
308-
case'd':/* CopyData */
308+
casePqMsg_CopyData:
309309
break;
310-
case'c':/* CopyDone */
310+
casePqMsg_CopyDone:
311311
/* COPY IN correctly terminated by frontend */
312312
cstate->raw_reached_eof= true;
313313
returnbytesread;
314-
case'f':/* CopyFail */
314+
casePqMsg_CopyFail:
315315
ereport(ERROR,
316316
(errcode(ERRCODE_QUERY_CANCELED),
317317
errmsg("COPY from stdin failed: %s",
318318
pq_getmsgstring(cstate->fe_msgbuf))));
319319
break;
320-
case'H':/* Flush */
321-
case'S':/* Sync */
320+
casePqMsg_Flush:
321+
casePqMsg_Sync:
322322

323323
/*
324324
* Ignore Flush/Sync for the convenience of client

‎src/backend/commands/copyto.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ SendCopyBegin(CopyToState cstate)
144144
int16format= (cstate->opts.binary ?1 :0);
145145
inti;
146146

147-
pq_beginmessage(&buf,'H');
147+
pq_beginmessage(&buf,PqMsg_CopyOutResponse);
148148
pq_sendbyte(&buf,format);/* overall format */
149149
pq_sendint16(&buf,natts);
150150
for (i=0;i<natts;i++)
@@ -159,7 +159,7 @@ SendCopyEnd(CopyToState cstate)
159159
/* Shouldn't have any unsent data */
160160
Assert(cstate->fe_msgbuf->len==0);
161161
/* Send Copy Done message */
162-
pq_putemptymessage('c');
162+
pq_putemptymessage(PqMsg_CopyDone);
163163
}
164164

165165
/*----------
@@ -247,7 +247,7 @@ CopySendEndOfRow(CopyToState cstate)
247247
CopySendChar(cstate,'\n');
248248

249249
/* Dump the accumulated row as one CopyData message */
250-
(void)pq_putmessage('d',fe_msgbuf->data,fe_msgbuf->len);
250+
(void)pq_putmessage(PqMsg_CopyData,fe_msgbuf->data,fe_msgbuf->len);
251251
break;
252252
caseCOPY_CALLBACK:
253253
cstate->data_dest_cb(fe_msgbuf->data,fe_msgbuf->len);

‎src/backend/libpq/auth-sasl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ CheckSASLAuth(const pg_be_sasl_mech *mech, Port *port, char *shadow_pass,
8787
{
8888
pq_startmsgread();
8989
mtype=pq_getbyte();
90-
if (mtype!='p')
90+
if (mtype!=PqMsg_SASLResponse)
9191
{
9292
/* Only log error if client didn't disconnect. */
9393
if (mtype!=EOF)

‎src/backend/libpq/auth.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ sendAuthRequest(Port *port, AuthRequest areq, const char *extradata, int extrale
665665

666666
CHECK_FOR_INTERRUPTS();
667667

668-
pq_beginmessage(&buf,'R');
668+
pq_beginmessage(&buf,PqMsg_AuthenticationRequest);
669669
pq_sendint32(&buf, (int32)areq);
670670
if (extralen>0)
671671
pq_sendbytes(&buf,extradata,extralen);
@@ -698,7 +698,7 @@ recv_password_packet(Port *port)
698698

699699
/* Expect 'p' message type */
700700
mtype=pq_getbyte();
701-
if (mtype!='p')
701+
if (mtype!=PqMsg_PasswordMessage)
702702
{
703703
/*
704704
* If the client just disconnects without offering a password, don't
@@ -961,7 +961,7 @@ pg_GSS_recvauth(Port *port)
961961
CHECK_FOR_INTERRUPTS();
962962

963963
mtype=pq_getbyte();
964-
if (mtype!='p')
964+
if (mtype!=PqMsg_GSSResponse)
965965
{
966966
/* Only log error if client didn't disconnect. */
967967
if (mtype!=EOF)
@@ -1232,7 +1232,7 @@ pg_SSPI_recvauth(Port *port)
12321232
{
12331233
pq_startmsgread();
12341234
mtype=pq_getbyte();
1235-
if (mtype!='p')
1235+
if (mtype!=PqMsg_GSSResponse)
12361236
{
12371237
if (sspictx!=NULL)
12381238
{

‎src/backend/postmaster/postmaster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ SendNegotiateProtocolVersion(List *unrecognized_protocol_options)
23572357
StringInfoDatabuf;
23582358
ListCell*lc;
23592359

2360-
pq_beginmessage(&buf,'v');/* NegotiateProtocolVersion */
2360+
pq_beginmessage(&buf,PqMsg_NegotiateProtocolVersion);
23612361
pq_sendint32(&buf,PG_PROTOCOL_LATEST);
23622362
pq_sendint32(&buf,list_length(unrecognized_protocol_options));
23632363
foreach(lc,unrecognized_protocol_options)

‎src/backend/replication/walsender.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd)
603603
dest->rStartup(dest,CMD_SELECT,tupdesc);
604604

605605
/* Send a DataRow message */
606-
pq_beginmessage(&buf,'D');
606+
pq_beginmessage(&buf,PqMsg_DataRow);
607607
pq_sendint16(&buf,2);/* # of columns */
608608
len=strlen(histfname);
609609
pq_sendint32(&buf,len);/* col1 len */
@@ -801,7 +801,7 @@ StartReplication(StartReplicationCmd *cmd)
801801
WalSndSetState(WALSNDSTATE_CATCHUP);
802802

803803
/* Send a CopyBothResponse message, and start streaming */
804-
pq_beginmessage(&buf,'W');
804+
pq_beginmessage(&buf,PqMsg_CopyBothResponse);
805805
pq_sendbyte(&buf,0);
806806
pq_sendint16(&buf,0);
807807
pq_endmessage(&buf);
@@ -1294,7 +1294,7 @@ StartLogicalReplication(StartReplicationCmd *cmd)
12941294
WalSndSetState(WALSNDSTATE_CATCHUP);
12951295

12961296
/* Send a CopyBothResponse message, and start streaming */
1297-
pq_beginmessage(&buf,'W');
1297+
pq_beginmessage(&buf,PqMsg_CopyBothResponse);
12981298
pq_sendbyte(&buf,0);
12991299
pq_sendint16(&buf,0);
13001300
pq_endmessage(&buf);
@@ -1923,11 +1923,11 @@ ProcessRepliesIfAny(void)
19231923
/* Validate message type and set packet size limit */
19241924
switch (firstchar)
19251925
{
1926-
case'd':
1926+
casePqMsg_CopyData:
19271927
maxmsglen=PQ_LARGE_MESSAGE_LIMIT;
19281928
break;
1929-
case'c':
1930-
case'X':
1929+
casePqMsg_CopyDone:
1930+
casePqMsg_Terminate:
19311931
maxmsglen=PQ_SMALL_MESSAGE_LIMIT;
19321932
break;
19331933
default:
@@ -1955,7 +1955,7 @@ ProcessRepliesIfAny(void)
19551955
/*
19561956
* 'd' means a standby reply wrapped in a CopyData packet.
19571957
*/
1958-
case'd':
1958+
casePqMsg_CopyData:
19591959
ProcessStandbyMessage();
19601960
received= true;
19611961
break;
@@ -1964,7 +1964,7 @@ ProcessRepliesIfAny(void)
19641964
* CopyDone means the standby requested to finish streaming.
19651965
* Reply with CopyDone, if we had not sent that already.
19661966
*/
1967-
case'c':
1967+
casePqMsg_CopyDone:
19681968
if (!streamingDoneSending)
19691969
{
19701970
pq_putmessage_noblock('c',NULL,0);
@@ -1978,7 +1978,7 @@ ProcessRepliesIfAny(void)
19781978
/*
19791979
* 'X' means that the standby is closing down the socket.
19801980
*/
1981-
case'X':
1981+
casePqMsg_Terminate:
19821982
proc_exit(0);
19831983

19841984
default:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp