mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-30 05:39:12 +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:
parent
0ec91f61c6
commit
bd0081fec8
@ -97,6 +97,7 @@
|
||||
<commit subject="Convert ProtocolStorageType enum to StringId."/>
|
||||
<commit subject="Convert ArchiveMode enum to StringId."/>
|
||||
<commit subject="Convert ArchivePushFileIoType enum to StringId."/>
|
||||
<commit subject="Update IoClient/IoSession to use StringIds."/>
|
||||
|
||||
<release-item-contributor-list>
|
||||
<release-item-reviewer id="cynthia.shang"/>
|
||||
|
@ -27,7 +27,7 @@ ioClientNew(void *driver, const IoClientInterface *interface)
|
||||
|
||||
ASSERT(driver != NULL);
|
||||
ASSERT(interface != NULL);
|
||||
ASSERT(interface->type != NULL);
|
||||
ASSERT(interface->type != 0);
|
||||
ASSERT(interface->name != NULL);
|
||||
ASSERT(interface->open != NULL);
|
||||
ASSERT(interface->toLog != NULL);
|
||||
@ -52,5 +52,5 @@ String *
|
||||
ioClientToLog(const IoClient *this)
|
||||
{
|
||||
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)));
|
||||
}
|
||||
|
@ -13,9 +13,8 @@ Interface
|
||||
***********************************************************************************************************************************/
|
||||
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
|
||||
// constant (e.g. created with STRING_EXTERN()) without needing to be copied.
|
||||
const String *const *type;
|
||||
// Type used to identify the client
|
||||
StringId type;
|
||||
|
||||
// Client name, usually host:port or some other unique indentifier
|
||||
const String *(*name)(void *driver);
|
||||
|
@ -27,7 +27,7 @@ ioSessionNew(void *driver, const IoSessionInterface *interface)
|
||||
|
||||
ASSERT(driver != NULL);
|
||||
ASSERT(interface != NULL);
|
||||
ASSERT(interface->type != NULL);
|
||||
ASSERT(interface->type != 0);
|
||||
ASSERT(interface->close != NULL);
|
||||
ASSERT(interface->ioRead != NULL);
|
||||
ASSERT(interface->ioWrite != NULL);
|
||||
@ -67,6 +67,6 @@ String *
|
||||
ioSessionToLog(const IoSession *this)
|
||||
{
|
||||
return strNewFmt(
|
||||
"{type: %s, role: %s, driver: %s}", strZ(*this->pub.interface->type),
|
||||
ioSessionRole(this) == ioSessionRoleClient ? "client" : "server", strZ(this->pub.interface->toLog(this->pub.driver)));
|
||||
"{type: %s, role: %s, driver: %s}", strZ(strIdToStr(this->pub.interface->type)), strZ(strIdToStr(ioSessionRole(this))),
|
||||
strZ(this->pub.interface->toLog(this->pub.driver)));
|
||||
}
|
||||
|
@ -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
|
||||
#define COMMON_IO_SESSION_H
|
||||
|
||||
#include "common/type/stringId.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Object type
|
||||
***********************************************************************************************************************************/
|
||||
@ -17,8 +19,8 @@ Session roles
|
||||
***********************************************************************************************************************************/
|
||||
typedef enum
|
||||
{
|
||||
ioSessionRoleClient, // Client session
|
||||
ioSessionRoleServer, // Server session
|
||||
ioSessionRoleClient = STRID5("client", 0x28e2a5830), // Client session
|
||||
ioSessionRoleServer = STRID5("server", 0x245b48b30), // Server session
|
||||
} IoSessionRole;
|
||||
|
||||
#include "common/io/read.h"
|
||||
|
@ -12,9 +12,8 @@ Interface
|
||||
***********************************************************************************************************************************/
|
||||
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
|
||||
// constant (e.g. created with STRING_EXTERN()) without needing to be copied.
|
||||
const String *const *type;
|
||||
// Type used to identify the session
|
||||
StringId type;
|
||||
|
||||
// Close the session
|
||||
void (*close)(void *driver);
|
||||
|
@ -19,11 +19,6 @@ Socket Client
|
||||
#include "common/type/object.h"
|
||||
#include "common/wait.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Io client type
|
||||
***********************************************************************************************************************************/
|
||||
STRING_EXTERN(IO_CLIENT_SOCKET_TYPE_STR, IO_CLIENT_SOCKET_TYPE);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Statistics constants
|
||||
***********************************************************************************************************************************/
|
||||
@ -176,7 +171,7 @@ sckClientName(THIS_VOID)
|
||||
/**********************************************************************************************************************************/
|
||||
static const IoClientInterface sckClientInterface =
|
||||
{
|
||||
.type = &IO_CLIENT_SOCKET_TYPE_STR,
|
||||
.type = IO_CLIENT_SOCKET_TYPE,
|
||||
.name = sckClientName,
|
||||
.open = sckClientOpen,
|
||||
.toLog = sckClientToLog,
|
||||
|
@ -12,8 +12,7 @@ A simple socket client intended to allow access to services that are exposed via
|
||||
/***********************************************************************************************************************************
|
||||
Io client type
|
||||
***********************************************************************************************************************************/
|
||||
#define IO_CLIENT_SOCKET_TYPE "socket"
|
||||
STRING_DECLARE(IO_CLIENT_SOCKET_TYPE_STR);
|
||||
#define IO_CLIENT_SOCKET_TYPE STRID5("socket", 0x28558df30)
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Statistics constants
|
||||
|
@ -154,7 +154,7 @@ sckSessionRole(const THIS_VOID)
|
||||
/**********************************************************************************************************************************/
|
||||
static const IoSessionInterface sckSessionInterface =
|
||||
{
|
||||
.type = &IO_CLIENT_SOCKET_TYPE_STR,
|
||||
.type = IO_CLIENT_SOCKET_TYPE,
|
||||
.close = sckSessionClose,
|
||||
.fd = sckSessionFd,
|
||||
.ioRead = sckSessionIoRead,
|
||||
@ -167,7 +167,7 @@ IoSession *
|
||||
sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port, TimeMSec timeout)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug)
|
||||
FUNCTION_LOG_PARAM(ENUM, role);
|
||||
FUNCTION_LOG_PARAM(STRING_ID, role);
|
||||
FUNCTION_LOG_PARAM(INT, fd);
|
||||
FUNCTION_LOG_PARAM(STRING, host);
|
||||
FUNCTION_LOG_PARAM(UINT, port);
|
||||
|
@ -20,11 +20,6 @@ TLS Client
|
||||
#include "common/type/object.h"
|
||||
#include "common/wait.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Io client type
|
||||
***********************************************************************************************************************************/
|
||||
STRING_EXTERN(IO_CLIENT_TLS_TYPE_STR, IO_CLIENT_TLS_TYPE);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Statistics constants
|
||||
***********************************************************************************************************************************/
|
||||
@ -336,7 +331,7 @@ tlsClientName(THIS_VOID)
|
||||
/**********************************************************************************************************************************/
|
||||
static const IoClientInterface tlsClientInterface =
|
||||
{
|
||||
.type = &IO_CLIENT_TLS_TYPE_STR,
|
||||
.type = IO_CLIENT_TLS_TYPE,
|
||||
.name = tlsClientName,
|
||||
.open = tlsClientOpen,
|
||||
.toLog = tlsClientToLog,
|
||||
|
@ -14,8 +14,7 @@ This object is intended to be used for multiple TLS sessions so ioClientOpen() c
|
||||
/***********************************************************************************************************************************
|
||||
Io client type
|
||||
***********************************************************************************************************************************/
|
||||
#define IO_CLIENT_TLS_TYPE "tls"
|
||||
STRING_DECLARE(IO_CLIENT_TLS_TYPE_STR);
|
||||
#define IO_CLIENT_TLS_TYPE STRID5("tls", 0x4d940)
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Statistics constants
|
||||
|
@ -341,7 +341,7 @@ tlsSessionRole(const THIS_VOID)
|
||||
/**********************************************************************************************************************************/
|
||||
static const IoSessionInterface tlsSessionInterface =
|
||||
{
|
||||
.type = &IO_CLIENT_TLS_TYPE_STR,
|
||||
.type = IO_CLIENT_TLS_TYPE,
|
||||
.close = tlsSessionClose,
|
||||
.ioRead = tlsSessionIoRead,
|
||||
.ioWrite = tlsSessionIoWrite,
|
||||
|
Loading…
x
Reference in New Issue
Block a user