You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-06-16 23:47:38 +02:00
Expose handle (file descriptor) from IoRead when applicable.
Some IO objects have file descriptors which can be useful for monitoring with select(). It might also be useful to expose handles for write objects but there is currently no use case.
This commit is contained in:
@ -71,6 +71,10 @@
|
|||||||
<p>Resolve storage path expressions before passing to remote.</p>
|
<p>Resolve storage path expressions before passing to remote.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
|
||||||
|
<release-item>
|
||||||
|
<p>Expose handle (file descriptor) from <code>IoRead</code> when applicable.</p>
|
||||||
|
</release-item>
|
||||||
|
|
||||||
<release-item>
|
<release-item>
|
||||||
<p>Add <code>storageHelperFree()</code> to storage helper.</p>
|
<p>Add <code>storageHelperFree()</code> to storage helper.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
@ -153,7 +153,9 @@ execOpen(Exec *this)
|
|||||||
ioWriteOpen(this->ioWriteHandle);
|
ioWriteOpen(this->ioWriteHandle);
|
||||||
|
|
||||||
// Create wrapper interfaces that check process state
|
// Create wrapper interfaces that check process state
|
||||||
this->ioReadExec = ioReadNewP(this, .read = (IoReadInterfaceRead)execRead, .eof = (IoReadInterfaceEof)execEof);
|
this->ioReadExec = ioReadNewP(
|
||||||
|
this, .read = (IoReadInterfaceRead)execRead, .eof = (IoReadInterfaceEof)execEof,
|
||||||
|
.handle = (IoReadInterfaceHandle)execHandleRead);
|
||||||
ioReadOpen(this->ioReadExec);
|
ioReadOpen(this->ioReadExec);
|
||||||
this->ioWriteExec = ioWriteNewP(this, .write = (IoWriteInterfaceWrite)execWrite);
|
this->ioWriteExec = ioWriteNewP(this, .write = (IoWriteInterfaceWrite)execWrite);
|
||||||
ioWriteOpen(this->ioWriteExec);
|
ioWriteOpen(this->ioWriteExec);
|
||||||
@ -335,6 +337,21 @@ execMemContext(const Exec *this)
|
|||||||
FUNCTION_TEST_RETURN(this->memContext);
|
FUNCTION_TEST_RETURN(this->memContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Get the read handle
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
int
|
||||||
|
execHandleRead(Exec *this)
|
||||||
|
{
|
||||||
|
FUNCTION_TEST_BEGIN();
|
||||||
|
FUNCTION_TEST_PARAM(EXEC, this);
|
||||||
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
|
ASSERT(this != NULL);
|
||||||
|
|
||||||
|
FUNCTION_TEST_RETURN(this->handleRead);
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Free the object
|
Free the object
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
|
@ -38,6 +38,7 @@ bool execEof(Exec *this);
|
|||||||
IoRead *execIoRead(const Exec *this);
|
IoRead *execIoRead(const Exec *this);
|
||||||
IoWrite *execIoWrite(const Exec *this);
|
IoWrite *execIoWrite(const Exec *this);
|
||||||
MemContext *execMemContext(const Exec *this);
|
MemContext *execMemContext(const Exec *this);
|
||||||
|
int execHandleRead(Exec *this);
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Destructor
|
Destructor
|
||||||
|
@ -41,7 +41,9 @@ ioHandleReadNew(const String *name, int handle, TimeMSec timeout)
|
|||||||
{
|
{
|
||||||
this = memNew(sizeof(IoHandleRead));
|
this = memNew(sizeof(IoHandleRead));
|
||||||
this->memContext = memContextCurrent();
|
this->memContext = memContextCurrent();
|
||||||
this->io = ioReadNewP(this, .eof = (IoReadInterfaceEof)ioHandleReadEof, .read = (IoReadInterfaceRead)ioHandleRead);
|
this->io = ioReadNewP(
|
||||||
|
this, .eof = (IoReadInterfaceEof)ioHandleReadEof, .handle = (IoReadInterfaceHandle)ioHandleReadHandle,
|
||||||
|
.read = (IoReadInterfaceRead)ioHandleRead);
|
||||||
this->name = strDup(name);
|
this->name = strDup(name);
|
||||||
this->handle = handle;
|
this->handle = handle;
|
||||||
this->timeout = timeout;
|
this->timeout = timeout;
|
||||||
@ -146,6 +148,21 @@ ioHandleReadEof(const IoHandleRead *this)
|
|||||||
FUNCTION_LOG_RETURN(BOOL, this->eof);
|
FUNCTION_LOG_RETURN(BOOL, this->eof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Get handle (file descriptor)
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
int
|
||||||
|
ioHandleReadHandle(const IoHandleRead *this)
|
||||||
|
{
|
||||||
|
FUNCTION_TEST_BEGIN();
|
||||||
|
FUNCTION_TEST_PARAM(IO_HANDLE_READ, this);
|
||||||
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
|
ASSERT(this != NULL);
|
||||||
|
|
||||||
|
FUNCTION_TEST_RETURN(this->handle);
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Get io interface
|
Get io interface
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
|
@ -29,6 +29,7 @@ IoHandleRead *ioHandleReadMove(IoHandleRead *this, MemContext *parentNew);
|
|||||||
Getters
|
Getters
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
bool ioHandleReadEof(const IoHandleRead *this);
|
bool ioHandleReadEof(const IoHandleRead *this);
|
||||||
|
int ioHandleReadHandle(const IoHandleRead *this);
|
||||||
IoRead *ioHandleReadIo(const IoHandleRead *this);
|
IoRead *ioHandleReadIo(const IoHandleRead *this);
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -357,6 +357,23 @@ ioReadFilterGroupSet(IoRead *this, IoFilterGroup *filterGroup)
|
|||||||
FUNCTION_LOG_RETURN_VOID();
|
FUNCTION_LOG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Handle (file descriptor) for the read object
|
||||||
|
|
||||||
|
No all read objects have a handle and -1 will be returned in that case.
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
int
|
||||||
|
ioReadHandle(const IoRead *this)
|
||||||
|
{
|
||||||
|
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||||
|
FUNCTION_LOG_PARAM(IO_READ, this);
|
||||||
|
FUNCTION_LOG_END();
|
||||||
|
|
||||||
|
ASSERT(this != NULL);
|
||||||
|
|
||||||
|
FUNCTION_LOG_RETURN(INT, this->interface.handle == NULL ? -1 : this->interface.handle(this->driver));
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Free the object
|
Free the object
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
|
@ -31,6 +31,7 @@ Getters/Setters
|
|||||||
bool ioReadEof(const IoRead *this);
|
bool ioReadEof(const IoRead *this);
|
||||||
const IoFilterGroup *ioReadFilterGroup(const IoRead *this);
|
const IoFilterGroup *ioReadFilterGroup(const IoRead *this);
|
||||||
void ioReadFilterGroupSet(IoRead *this, IoFilterGroup *filterGroup);
|
void ioReadFilterGroupSet(IoRead *this, IoFilterGroup *filterGroup);
|
||||||
|
int ioReadHandle(const IoRead *this);
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Destructor
|
Destructor
|
||||||
|
@ -12,12 +12,14 @@ Constructor
|
|||||||
typedef bool (*IoReadInterfaceEof)(void *driver);
|
typedef bool (*IoReadInterfaceEof)(void *driver);
|
||||||
typedef void (*IoReadInterfaceClose)(void *driver);
|
typedef void (*IoReadInterfaceClose)(void *driver);
|
||||||
typedef bool (*IoReadInterfaceOpen)(void *driver);
|
typedef bool (*IoReadInterfaceOpen)(void *driver);
|
||||||
|
typedef int (*IoReadInterfaceHandle)(void *driver);
|
||||||
typedef size_t (*IoReadInterfaceRead)(void *driver, Buffer *buffer, bool block);
|
typedef size_t (*IoReadInterfaceRead)(void *driver, Buffer *buffer, bool block);
|
||||||
|
|
||||||
typedef struct IoReadInterface
|
typedef struct IoReadInterface
|
||||||
{
|
{
|
||||||
IoReadInterfaceEof eof;
|
IoReadInterfaceEof eof;
|
||||||
IoReadInterfaceClose close;
|
IoReadInterfaceClose close;
|
||||||
|
IoReadInterfaceHandle handle;
|
||||||
IoReadInterfaceOpen open;
|
IoReadInterfaceOpen open;
|
||||||
IoReadInterfaceRead read;
|
IoReadInterfaceRead read;
|
||||||
} IoReadInterface;
|
} IoReadInterface;
|
||||||
|
@ -27,6 +27,7 @@ testRun(void)
|
|||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
TEST_ASSIGN(exec, execNew(strNew("cat"), NULL, strNew("cat"), 1000), "new cat exec");
|
TEST_ASSIGN(exec, execNew(strNew("cat"), NULL, strNew("cat"), 1000), "new cat exec");
|
||||||
TEST_RESULT_PTR(execMemContext(exec), exec->memContext, "get mem context");
|
TEST_RESULT_PTR(execMemContext(exec), exec->memContext, "get mem context");
|
||||||
|
TEST_RESULT_INT(execHandleRead(exec), exec->handleRead, "check read handle");
|
||||||
TEST_RESULT_VOID(execOpen(exec), "open cat exec");
|
TEST_RESULT_VOID(execOpen(exec), "open cat exec");
|
||||||
|
|
||||||
String *message = strNew("ACKBYACK");
|
String *message = strNew("ACKBYACK");
|
||||||
|
@ -519,6 +519,7 @@ testRun(void)
|
|||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
|
|
||||||
ioReadOpen(ioHandleReadIo(read));
|
ioReadOpen(ioHandleReadIo(read));
|
||||||
|
TEST_RESULT_INT(ioReadHandle(ioHandleReadIo(read)), read->handle, "check handle");
|
||||||
|
|
||||||
// Read a string
|
// Read a string
|
||||||
TEST_RESULT_STR(strPtr(ioReadLine(ioHandleReadIo(read))), "test string 1", "read test string");
|
TEST_RESULT_STR(strPtr(ioReadLine(ioHandleReadIo(read))), "test string 1", "read test string");
|
||||||
|
Reference in New Issue
Block a user