Presumably, the C type MsgType was meant to hold the protocol message
type in the pre-version-3 era, but this was never fully developed even
then, and the name is pretty confusing nowadays. It has only one
vestigial use for cancel requests that we can get rid of. Since a
cancel request is indicated by a special protocol version number, we can
use the ProtocolVersion type, which MsgType was based on. (If this is
also found confusing, we could also use uint32 directly.)
From b74e5ff37ce648639d662600a392e12a8c9b44f4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Thu, 3 Jul 2025 14:46:17 +0200
Subject: [PATCH] Remove MsgType type
Presumably, this type was meant to hold the protocol message type in
the pre-version-3 era, but this was never even fully developed then,
and the name is pretty confusing nowadays. It has only one vestigial
use that we can get rid of. Since a cancel request is indicated by a
special protocol version number, we can use the ProtocolVersion type,
which MsgType was based on. (If this is also found confusing, we
could also use uint32 directly.)
---
src/include/libpq/pqcomm.h | 3 +--
src/interfaces/libpq/fe-cancel.c | 4 ++--
src/tools/pgindent/typedefs.list | 1 -
3 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index 625f4b43879..235f6ed7d0d 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -114,7 +114,6 @@ is_unixsock_path(const char *path)
typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
-typedef ProtocolVersion MsgType;
/*
@@ -146,7 +145,7 @@ typedef uint32 AuthRequest; /* an AUTH_REQ_* code */
typedef struct CancelRequestPacket
{
/* Note that each field is stored in network byte order! */
- MsgType cancelRequestCode; /* code to identify a cancel
request */
+ ProtocolVersion cancelRequestCode; /* code to identify a cancel
request */
uint32 backendPID; /* PID of client's backend */
uint8 cancelAuthCode[FLEXIBLE_ARRAY_MEMBER]; /* secret key to
* authorize cancel */
diff --git a/src/interfaces/libpq/fe-cancel.c b/src/interfaces/libpq/fe-cancel.c
index c872a0267f0..f23caf8349d 100644
--- a/src/interfaces/libpq/fe-cancel.c
+++ b/src/interfaces/libpq/fe-cancel.c
@@ -448,7 +448,7 @@ PQgetCancel(PGconn *conn)
}
req = (CancelRequestPacket *) &cancel->cancel_req;
- req->cancelRequestCode = (MsgType) pg_hton32(CANCEL_REQUEST_CODE);
+ req->cancelRequestCode = pg_hton32(CANCEL_REQUEST_CODE);
req->backendPID = pg_hton32(conn->be_pid);
memcpy(req->cancelAuthCode, conn->be_cancel_key,
conn->be_cancel_key_len);
/* include the length field itself in the length */
@@ -479,7 +479,7 @@ PQsendCancelRequest(PGconn *cancelConn)
/* Send the message body. */
memset(&req, 0, offsetof(CancelRequestPacket, cancelAuthCode));
- req.cancelRequestCode = (MsgType) pg_hton32(CANCEL_REQUEST_CODE);
+ req.cancelRequestCode = pg_hton32(CANCEL_REQUEST_CODE);
req.backendPID = pg_hton32(cancelConn->be_pid);
if (pqPutnchar(&req, offsetof(CancelRequestPacket, cancelAuthCode),
cancelConn))
return STATUS_ERROR;
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 9dd65b10254..792042e4961 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1722,7 +1722,6 @@ ModifyTablePath
ModifyTableState
MonotonicFunction
MorphOpaque
-MsgType
MultiAssignRef
MultiSortSupport
MultiSortSupportData
--
2.52.0