mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +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:
parent
b1957b07f3
commit
dee90d3e60
@ -71,6 +71,10 @@
|
||||
<p>Resolve storage path expressions before passing to remote.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Expose handle (file descriptor) from <code>IoRead</code> when applicable.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Add <code>storageHelperFree()</code> to storage helper.</p>
|
||||
</release-item>
|
||||
|
@ -153,7 +153,9 @@ execOpen(Exec *this)
|
||||
ioWriteOpen(this->ioWriteHandle);
|
||||
|
||||
// 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);
|
||||
this->ioWriteExec = ioWriteNewP(this, .write = (IoWriteInterfaceWrite)execWrite);
|
||||
ioWriteOpen(this->ioWriteExec);
|
||||
@ -335,6 +337,21 @@ execMemContext(const Exec *this)
|
||||
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
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -38,6 +38,7 @@ bool execEof(Exec *this);
|
||||
IoRead *execIoRead(const Exec *this);
|
||||
IoWrite *execIoWrite(const Exec *this);
|
||||
MemContext *execMemContext(const Exec *this);
|
||||
int execHandleRead(Exec *this);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
|
@ -41,7 +41,9 @@ ioHandleReadNew(const String *name, int handle, TimeMSec timeout)
|
||||
{
|
||||
this = memNew(sizeof(IoHandleRead));
|
||||
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->handle = handle;
|
||||
this->timeout = timeout;
|
||||
@ -146,6 +148,21 @@ ioHandleReadEof(const IoHandleRead *this)
|
||||
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
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -29,6 +29,7 @@ IoHandleRead *ioHandleReadMove(IoHandleRead *this, MemContext *parentNew);
|
||||
Getters
|
||||
***********************************************************************************************************************************/
|
||||
bool ioHandleReadEof(const IoHandleRead *this);
|
||||
int ioHandleReadHandle(const IoHandleRead *this);
|
||||
IoRead *ioHandleReadIo(const IoHandleRead *this);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
@ -357,6 +357,23 @@ ioReadFilterGroupSet(IoRead *this, IoFilterGroup *filterGroup)
|
||||
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
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -31,6 +31,7 @@ Getters/Setters
|
||||
bool ioReadEof(const IoRead *this);
|
||||
const IoFilterGroup *ioReadFilterGroup(const IoRead *this);
|
||||
void ioReadFilterGroupSet(IoRead *this, IoFilterGroup *filterGroup);
|
||||
int ioReadHandle(const IoRead *this);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Destructor
|
||||
|
@ -12,12 +12,14 @@ Constructor
|
||||
typedef bool (*IoReadInterfaceEof)(void *driver);
|
||||
typedef void (*IoReadInterfaceClose)(void *driver);
|
||||
typedef bool (*IoReadInterfaceOpen)(void *driver);
|
||||
typedef int (*IoReadInterfaceHandle)(void *driver);
|
||||
typedef size_t (*IoReadInterfaceRead)(void *driver, Buffer *buffer, bool block);
|
||||
|
||||
typedef struct IoReadInterface
|
||||
{
|
||||
IoReadInterfaceEof eof;
|
||||
IoReadInterfaceClose close;
|
||||
IoReadInterfaceHandle handle;
|
||||
IoReadInterfaceOpen open;
|
||||
IoReadInterfaceRead read;
|
||||
} IoReadInterface;
|
||||
|
@ -27,6 +27,7 @@ testRun(void)
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
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_INT(execHandleRead(exec), exec->handleRead, "check read handle");
|
||||
TEST_RESULT_VOID(execOpen(exec), "open cat exec");
|
||||
|
||||
String *message = strNew("ACKBYACK");
|
||||
|
@ -519,6 +519,7 @@ testRun(void)
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
ioReadOpen(ioHandleReadIo(read));
|
||||
TEST_RESULT_INT(ioReadHandle(ioHandleReadIo(read)), read->handle, "check handle");
|
||||
|
||||
// Read a string
|
||||
TEST_RESULT_STR(strPtr(ioReadLine(ioHandleReadIo(read))), "test string 1", "read test string");
|
||||
|
Loading…
Reference in New Issue
Block a user