1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-17 01:12:23 +02:00

Update IoClient/IoSession to use StringIds.

Using StringId for the client/session type removes String constants and some awkward referencing/dereferencing needed to use a String constant in the interface.

Converting IoSessionRole to StringId removes a conditional in ioSessionToLog() and improves debug logging by outputting client/server instead of 0/1.
This commit is contained in:
David Steele
2021-04-28 12:37:22 -04:00
parent 0ec91f61c6
commit bd0081fec8
12 changed files with 21 additions and 32 deletions

View File

@ -97,6 +97,7 @@
<commit subject="Convert ProtocolStorageType enum to StringId."/> <commit subject="Convert ProtocolStorageType enum to StringId."/>
<commit subject="Convert ArchiveMode enum to StringId."/> <commit subject="Convert ArchiveMode enum to StringId."/>
<commit subject="Convert ArchivePushFileIoType enum to StringId."/> <commit subject="Convert ArchivePushFileIoType enum to StringId."/>
<commit subject="Update IoClient/IoSession to use StringIds."/>
<release-item-contributor-list> <release-item-contributor-list>
<release-item-reviewer id="cynthia.shang"/> <release-item-reviewer id="cynthia.shang"/>

View File

@ -27,7 +27,7 @@ ioClientNew(void *driver, const IoClientInterface *interface)
ASSERT(driver != NULL); ASSERT(driver != NULL);
ASSERT(interface != NULL); ASSERT(interface != NULL);
ASSERT(interface->type != NULL); ASSERT(interface->type != 0);
ASSERT(interface->name != NULL); ASSERT(interface->name != NULL);
ASSERT(interface->open != NULL); ASSERT(interface->open != NULL);
ASSERT(interface->toLog != NULL); ASSERT(interface->toLog != NULL);
@ -52,5 +52,5 @@ String *
ioClientToLog(const IoClient *this) ioClientToLog(const IoClient *this)
{ {
return strNewFmt( return strNewFmt(
"{type: %s, driver: %s}", strZ(*this->pub.interface->type), strZ(this->pub.interface->toLog(this->pub.driver))); "{type: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(this->pub.interface->toLog(this->pub.driver)));
} }

View File

@ -13,9 +13,8 @@ Interface
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct IoClientInterface typedef struct IoClientInterface
{ {
// Type used to identify the client. This is stored as a pointer to a String pointer so it can be used with an existing String // Type used to identify the client
// constant (e.g. created with STRING_EXTERN()) without needing to be copied. StringId type;
const String *const *type;
// Client name, usually host:port or some other unique indentifier // Client name, usually host:port or some other unique indentifier
const String *(*name)(void *driver); const String *(*name)(void *driver);

View File

@ -27,7 +27,7 @@ ioSessionNew(void *driver, const IoSessionInterface *interface)
ASSERT(driver != NULL); ASSERT(driver != NULL);
ASSERT(interface != NULL); ASSERT(interface != NULL);
ASSERT(interface->type != NULL); ASSERT(interface->type != 0);
ASSERT(interface->close != NULL); ASSERT(interface->close != NULL);
ASSERT(interface->ioRead != NULL); ASSERT(interface->ioRead != NULL);
ASSERT(interface->ioWrite != NULL); ASSERT(interface->ioWrite != NULL);
@ -67,6 +67,6 @@ String *
ioSessionToLog(const IoSession *this) ioSessionToLog(const IoSession *this)
{ {
return strNewFmt( return strNewFmt(
"{type: %s, role: %s, driver: %s}", strZ(*this->pub.interface->type), "{type: %s, role: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(strIdToStr(ioSessionRole(this))),
ioSessionRole(this) == ioSessionRoleClient ? "client" : "server", strZ(this->pub.interface->toLog(this->pub.driver))); strZ(this->pub.interface->toLog(this->pub.driver)));
} }

View File

@ -7,6 +7,8 @@ be closed when work with them is done but they also contain destructors to do cl
#ifndef COMMON_IO_SESSION_H #ifndef COMMON_IO_SESSION_H
#define COMMON_IO_SESSION_H #define COMMON_IO_SESSION_H
#include "common/type/stringId.h"
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Object type Object type
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@ -17,8 +19,8 @@ Session roles
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef enum typedef enum
{ {
ioSessionRoleClient, // Client session ioSessionRoleClient = STRID5("client", 0x28e2a5830), // Client session
ioSessionRoleServer, // Server session ioSessionRoleServer = STRID5("server", 0x245b48b30), // Server session
} IoSessionRole; } IoSessionRole;
#include "common/io/read.h" #include "common/io/read.h"

View File

@ -12,9 +12,8 @@ Interface
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
typedef struct IoSessionInterface typedef struct IoSessionInterface
{ {
// Type used to identify the session. This is stored as a pointer to a String pointer so it can be used with an existing String // Type used to identify the session
// constant (e.g. created with STRING_EXTERN()) without needing to be copied. StringId type;
const String *const *type;
// Close the session // Close the session
void (*close)(void *driver); void (*close)(void *driver);

View File

@ -19,11 +19,6 @@ Socket Client
#include "common/type/object.h" #include "common/type/object.h"
#include "common/wait.h" #include "common/wait.h"
/***********************************************************************************************************************************
Io client type
***********************************************************************************************************************************/
STRING_EXTERN(IO_CLIENT_SOCKET_TYPE_STR, IO_CLIENT_SOCKET_TYPE);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Statistics constants Statistics constants
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@ -176,7 +171,7 @@ sckClientName(THIS_VOID)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
static const IoClientInterface sckClientInterface = static const IoClientInterface sckClientInterface =
{ {
.type = &IO_CLIENT_SOCKET_TYPE_STR, .type = IO_CLIENT_SOCKET_TYPE,
.name = sckClientName, .name = sckClientName,
.open = sckClientOpen, .open = sckClientOpen,
.toLog = sckClientToLog, .toLog = sckClientToLog,

View File

@ -12,8 +12,7 @@ A simple socket client intended to allow access to services that are exposed via
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Io client type Io client type
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#define IO_CLIENT_SOCKET_TYPE "socket" #define IO_CLIENT_SOCKET_TYPE STRID5("socket", 0x28558df30)
STRING_DECLARE(IO_CLIENT_SOCKET_TYPE_STR);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Statistics constants Statistics constants

View File

@ -154,7 +154,7 @@ sckSessionRole(const THIS_VOID)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
static const IoSessionInterface sckSessionInterface = static const IoSessionInterface sckSessionInterface =
{ {
.type = &IO_CLIENT_SOCKET_TYPE_STR, .type = IO_CLIENT_SOCKET_TYPE,
.close = sckSessionClose, .close = sckSessionClose,
.fd = sckSessionFd, .fd = sckSessionFd,
.ioRead = sckSessionIoRead, .ioRead = sckSessionIoRead,
@ -167,7 +167,7 @@ IoSession *
sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port, TimeMSec timeout) sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port, TimeMSec timeout)
{ {
FUNCTION_LOG_BEGIN(logLevelDebug) FUNCTION_LOG_BEGIN(logLevelDebug)
FUNCTION_LOG_PARAM(ENUM, role); FUNCTION_LOG_PARAM(STRING_ID, role);
FUNCTION_LOG_PARAM(INT, fd); FUNCTION_LOG_PARAM(INT, fd);
FUNCTION_LOG_PARAM(STRING, host); FUNCTION_LOG_PARAM(STRING, host);
FUNCTION_LOG_PARAM(UINT, port); FUNCTION_LOG_PARAM(UINT, port);

View File

@ -20,11 +20,6 @@ TLS Client
#include "common/type/object.h" #include "common/type/object.h"
#include "common/wait.h" #include "common/wait.h"
/***********************************************************************************************************************************
Io client type
***********************************************************************************************************************************/
STRING_EXTERN(IO_CLIENT_TLS_TYPE_STR, IO_CLIENT_TLS_TYPE);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Statistics constants Statistics constants
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
@ -336,7 +331,7 @@ tlsClientName(THIS_VOID)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
static const IoClientInterface tlsClientInterface = static const IoClientInterface tlsClientInterface =
{ {
.type = &IO_CLIENT_TLS_TYPE_STR, .type = IO_CLIENT_TLS_TYPE,
.name = tlsClientName, .name = tlsClientName,
.open = tlsClientOpen, .open = tlsClientOpen,
.toLog = tlsClientToLog, .toLog = tlsClientToLog,

View File

@ -14,8 +14,7 @@ This object is intended to be used for multiple TLS sessions so ioClientOpen() c
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Io client type Io client type
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
#define IO_CLIENT_TLS_TYPE "tls" #define IO_CLIENT_TLS_TYPE STRID5("tls", 0x4d940)
STRING_DECLARE(IO_CLIENT_TLS_TYPE_STR);
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Statistics constants Statistics constants

View File

@ -341,7 +341,7 @@ tlsSessionRole(const THIS_VOID)
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
static const IoSessionInterface tlsSessionInterface = static const IoSessionInterface tlsSessionInterface =
{ {
.type = &IO_CLIENT_TLS_TYPE_STR, .type = IO_CLIENT_TLS_TYPE,
.close = tlsSessionClose, .close = tlsSessionClose,
.ioRead = tlsSessionIoRead, .ioRead = tlsSessionIoRead,
.ioWrite = tlsSessionIoWrite, .ioWrite = tlsSessionIoWrite,