mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Add ioFdReadNewOpen() and ioFdWriteNewOpen().
These functions construct and open in one call, which allows them to be used as function parameters.
This commit is contained in:
parent
f70ddc16d7
commit
d6797009f8
@ -38,12 +38,9 @@ cmdLocal(int fdRead, int fdWrite)
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
String *name = strNewFmt(PROTOCOL_SERVICE_LOCAL "-%s", strZ(cfgOptionDisplay(cfgOptProcess)));
|
||||
IoRead *read = ioFdReadNew(name, fdRead, cfgOptionUInt64(cfgOptProtocolTimeout));
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(name, fdWrite, cfgOptionUInt64(cfgOptProtocolTimeout));
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_LOCAL_STR, read, write);
|
||||
ProtocolServer *server = protocolServerNew(
|
||||
name, PROTOCOL_SERVICE_LOCAL_STR, ioFdReadNewOpen(name, fdRead, cfgOptionUInt64(cfgOptProtocolTimeout)),
|
||||
ioFdWriteNewOpen(name, fdWrite, cfgOptionUInt64(cfgOptProtocolTimeout)));
|
||||
protocolServerProcess(
|
||||
server, cfgCommandJobRetry(), commandLocalHandlerList, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandLocalHandlerList));
|
||||
}
|
||||
|
@ -36,12 +36,9 @@ cmdRemote(int fdRead, int fdWrite)
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
String *name = strNewFmt(PROTOCOL_SERVICE_REMOTE "-%s", strZ(cfgOptionDisplay(cfgOptProcess)));
|
||||
IoRead *read = ioFdReadNew(name, fdRead, cfgOptionUInt64(cfgOptProtocolTimeout));
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(name, fdWrite, cfgOptionUInt64(cfgOptProtocolTimeout));
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_REMOTE_STR, read, write);
|
||||
ProtocolServer *server = protocolServerNew(
|
||||
name, PROTOCOL_SERVICE_REMOTE_STR, ioFdReadNewOpen(name, fdRead, cfgOptionUInt64(cfgOptProtocolTimeout)),
|
||||
ioFdWriteNewOpen(name, fdWrite, cfgOptionUInt64(cfgOptProtocolTimeout)));
|
||||
|
||||
// Acquire a lock if this command needs one. We'll use the noop that is always sent from the client right after the
|
||||
// handshake to return an error. We can't take a lock earlier than this because we want the error to go back through the
|
||||
|
@ -183,9 +183,8 @@ execCheck(Exec *this)
|
||||
if (WIFEXITED(processStatus))
|
||||
{
|
||||
// Get data from stderr to help diagnose the problem
|
||||
IoRead *ioReadError = ioFdReadNew(strNewFmt("%s error", strZ(this->name)), this->fdError, 0);
|
||||
ioReadOpen(ioReadError);
|
||||
String *errorStr = strTrim(strNewBuf(ioReadBuf(ioReadError)));
|
||||
String *errorStr = strTrim(
|
||||
strNewBuf(ioReadBuf(ioFdReadNewOpen(strNewFmt("%s error", strZ(this->name)), this->fdError, 0))));
|
||||
|
||||
// Throw the error with as much information as is available
|
||||
THROWP_FMT(
|
||||
@ -361,8 +360,7 @@ execOpen(Exec *this)
|
||||
|
||||
// Assign file descriptors to io interfaces
|
||||
this->ioReadFd = ioFdReadNew(strNewFmt("%s read", strZ(this->name)), this->fdRead, this->timeout);
|
||||
this->ioWriteFd = ioFdWriteNew(strNewFmt("%s write", strZ(this->name)), this->fdWrite, this->timeout);
|
||||
ioWriteOpen(this->ioWriteFd);
|
||||
this->ioWriteFd = ioFdWriteNewOpen(strNewFmt("%s write", strZ(this->name)), this->fdWrite, this->timeout);
|
||||
|
||||
// Create wrapper interfaces that check process state
|
||||
this->pub.ioReadExec = ioReadNewP(this, .block = true, .read = execRead, .eof = execEof, .fd = execFdRead);
|
||||
|
@ -14,4 +14,13 @@ Constructors
|
||||
***********************************************************************************************************************************/
|
||||
IoRead *ioFdReadNew(const String *name, int fd, TimeMSec timeout);
|
||||
|
||||
// Construct and open read fd
|
||||
__attribute__((always_inline)) static inline IoRead *
|
||||
ioFdReadNewOpen(const String *const name, const int fd, const TimeMSec timeout)
|
||||
{
|
||||
IoRead *const result = ioFdReadNew(name, fd, timeout);
|
||||
ioReadOpen(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -14,6 +14,15 @@ Constructors
|
||||
***********************************************************************************************************************************/
|
||||
IoWrite *ioFdWriteNew(const String *name, int fd, TimeMSec timeout);
|
||||
|
||||
// Construct and open write fd
|
||||
__attribute__((always_inline)) static inline IoWrite *
|
||||
ioFdWriteNewOpen(const String *const name, const int fd, const TimeMSec timeout)
|
||||
{
|
||||
IoWrite *const result = ioFdWriteNew(name, fd, timeout);
|
||||
ioWriteOpen(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Helper functions
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -193,16 +193,12 @@ sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port,
|
||||
.host = strDup(host),
|
||||
.port = port,
|
||||
.timeout = timeout,
|
||||
.read = ioFdReadNew(name, fd, timeout),
|
||||
.write = ioFdWriteNew(name, fd, timeout),
|
||||
.read = ioFdReadNewOpen(name, fd, timeout),
|
||||
.write = ioFdWriteNewOpen(name, fd, timeout),
|
||||
};
|
||||
|
||||
strFree(name);
|
||||
|
||||
// Open read/write io
|
||||
ioReadOpen(driver->read);
|
||||
ioWriteOpen(driver->write);
|
||||
|
||||
// Ensure file descriptor is closed
|
||||
memContextCallbackSet(driver->memContext, sckSessionFreeResource, driver);
|
||||
|
||||
|
@ -73,12 +73,9 @@ protocolLocalExec(
|
||||
|
||||
// Run server with provided handlers
|
||||
String *name = strNewFmt(PROTOCOL_SERVICE_LOCAL "-shim-%u", processId);
|
||||
IoRead *read = ioFdReadNew(name, pipeWrite[0], 5000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(name, pipeRead[1], 5000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_LOCAL_STR, read, write);
|
||||
ProtocolServer *server = protocolServerNew(
|
||||
name, PROTOCOL_SERVICE_LOCAL_STR, ioFdReadNewOpen(name, pipeWrite[0], 5000),
|
||||
ioFdWriteNewOpen(name, pipeRead[1], 5000));
|
||||
protocolServerProcess(server, NULL, hrnProtocolStatic.localHandlerList, hrnProtocolStatic.localHandlerListSize);
|
||||
|
||||
// Exit when done
|
||||
@ -90,13 +87,10 @@ protocolLocalExec(
|
||||
close(pipeWrite[0]);
|
||||
|
||||
// Create protocol object
|
||||
IoRead *read = ioFdReadNew(strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol read", processId), pipeRead[0], 5000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol write", processId), pipeWrite[1], 5000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
helper->client = protocolClientNew(
|
||||
strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol", processId), PROTOCOL_SERVICE_LOCAL_STR, read, write);
|
||||
strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol", processId), PROTOCOL_SERVICE_LOCAL_STR,
|
||||
ioFdReadNewOpen(strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol read", processId), pipeRead[0], 5000),
|
||||
ioFdWriteNewOpen(strNewFmt(PROTOCOL_SERVICE_LOCAL "-%u shim protocol write", processId), pipeWrite[1], 5000));
|
||||
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
@ -169,12 +163,9 @@ protocolRemoteExec(
|
||||
|
||||
// Run server with provided handlers
|
||||
String *name = strNewFmt(PROTOCOL_SERVICE_REMOTE "-shim-%u", processId);
|
||||
IoRead *read = ioFdReadNew(name, pipeWrite[0], 5000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(name, pipeRead[1], 5000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(name, PROTOCOL_SERVICE_REMOTE_STR, read, write);
|
||||
ProtocolServer *server = protocolServerNew(
|
||||
name, PROTOCOL_SERVICE_REMOTE_STR, ioFdReadNewOpen(name, pipeWrite[0], 5000),
|
||||
ioFdWriteNewOpen(name, pipeRead[1], 5000));
|
||||
protocolServerProcess(server, NULL, hrnProtocolStatic.remoteHandlerList, hrnProtocolStatic.remoteHandlerListSize);
|
||||
|
||||
// Put an end message here to sync with the client to ensure that coverage data is written before exiting
|
||||
@ -189,13 +180,10 @@ protocolRemoteExec(
|
||||
close(pipeWrite[0]);
|
||||
|
||||
// Create protocol object
|
||||
IoRead *read = ioFdReadNew(strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol read", processId), pipeRead[0], 5000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol write", processId), pipeWrite[1], 5000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
helper->client = protocolClientNew(
|
||||
strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol", processId), PROTOCOL_SERVICE_REMOTE_STR, read, write);
|
||||
strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol", processId), PROTOCOL_SERVICE_REMOTE_STR,
|
||||
ioFdReadNewOpen(strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol read", processId), pipeRead[0], 5000),
|
||||
ioFdWriteNewOpen(strNewFmt(PROTOCOL_SERVICE_REMOTE "-%u shim protocol write", processId), pipeWrite[1], 5000));
|
||||
|
||||
FUNCTION_LOG_RETURN_VOID();
|
||||
}
|
||||
|
@ -735,10 +735,8 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
|
||||
TEST_RESULT_VOID(
|
||||
lockAcquire(
|
||||
@ -757,10 +755,8 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
|
||||
// Wait for the child to acquire the lock
|
||||
ioReadLine(read);
|
||||
|
@ -713,10 +713,8 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
|
||||
lockAcquire(
|
||||
cfgOptionStr(cfgOptLockPath), cfgOptionStr(cfgOptStanza), STRDEF("555-fefefefe"), cfgLockType(), 30000, true);
|
||||
@ -732,10 +730,8 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
|
||||
// Wait for the child to acquire the lock
|
||||
ioReadLine(read);
|
||||
|
@ -164,10 +164,8 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
|
||||
int lockFd = open(HRN_PATH "/lock/empty" LOCK_FILE_EXT, O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired");
|
||||
@ -187,10 +185,8 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
|
||||
// Wait for the child to acquire the lock
|
||||
ioReadLine(read);
|
||||
@ -218,10 +214,8 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
|
||||
int lockFd = open(HRN_PATH "/lock/empty" LOCK_FILE_EXT, O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired");
|
||||
@ -241,10 +235,8 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
|
||||
// Wait for the child to acquire the lock
|
||||
ioReadLine(read);
|
||||
@ -270,10 +262,8 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
lockAcquire(STRDEF(HRN_PATH "/lock"), cfgOptionStr(cfgOptStanza), cfgOptionStr(cfgOptExecId), 0, 30000, true),
|
||||
@ -290,10 +280,7 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
|
||||
// Wait for the child to acquire the lock
|
||||
ioReadLine(read);
|
||||
@ -317,10 +304,8 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("child read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("child write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
|
||||
int lockFd = open(HRN_PATH "/lock/badpid" LOCK_FILE_EXT, O_RDONLY, 0);
|
||||
TEST_RESULT_BOOL(lockFd != -1, true, "file descriptor acquired");
|
||||
@ -341,10 +326,8 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("parent read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("parent write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
|
||||
// Wait for the child to acquire the lock
|
||||
ioReadLine(read);
|
||||
|
@ -43,12 +43,10 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolClient *client = protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_LOCAL_STR, read, write);
|
||||
ProtocolClient *client = protocolClientNew(
|
||||
STRDEF("test"), PROTOCOL_SERVICE_LOCAL_STR,
|
||||
ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
|
||||
protocolClientNoOp(client);
|
||||
protocolClientFree(client);
|
||||
}
|
||||
|
@ -43,12 +43,10 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolClient *client = protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write);
|
||||
ProtocolClient *client = protocolClientNew(
|
||||
STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR,
|
||||
ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
|
||||
protocolClientNoOp(client);
|
||||
protocolClientFree(client);
|
||||
}
|
||||
@ -77,13 +75,13 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolClient *client = NULL;
|
||||
TEST_ASSIGN(client, protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), "create client");
|
||||
TEST_ASSIGN(
|
||||
client,
|
||||
protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR,
|
||||
ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)),
|
||||
"create client");
|
||||
protocolClientNoOp(client);
|
||||
protocolClientFree(client);
|
||||
}
|
||||
@ -111,14 +109,12 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
TEST_ERROR(
|
||||
protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), PathCreateError,
|
||||
"raised from test: unable to create path '/bogus': [13] Permission denied");
|
||||
protocolClientNew(
|
||||
STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR,
|
||||
ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)),
|
||||
PathCreateError, "raised from test: unable to create path '/bogus': [13] Permission denied");
|
||||
}
|
||||
HARNESS_FORK_PARENT_END();
|
||||
}
|
||||
@ -144,13 +140,14 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolClient *client = NULL;
|
||||
TEST_ASSIGN(client, protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), "create client");
|
||||
TEST_ASSIGN(
|
||||
client,
|
||||
protocolClientNew(
|
||||
STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR,
|
||||
ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)),
|
||||
"create client");
|
||||
protocolClientNoOp(client);
|
||||
|
||||
TEST_RESULT_BOOL(
|
||||
@ -182,16 +179,14 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
storagePutP(storageNewWriteP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT)), NULL);
|
||||
|
||||
TEST_ERROR(
|
||||
protocolClientNew(STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR, read, write), StopError,
|
||||
"raised from test: stop file exists for all stanzas");
|
||||
protocolClientNew(
|
||||
STRDEF("test"), PROTOCOL_SERVICE_REMOTE_STR,
|
||||
ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)),
|
||||
StopError, "raised from test: stop file exists for all stanzas");
|
||||
|
||||
storageRemoveP(hrnStorage, STRDEF("lock/all" STOP_FILE_EXT));
|
||||
}
|
||||
|
@ -543,8 +543,7 @@ testRun(void)
|
||||
{
|
||||
IoWrite *write = NULL;
|
||||
|
||||
TEST_ASSIGN(write, ioFdWriteNew(STRDEF("write test"), HARNESS_FORK_CHILD_WRITE(), 1000), "move write");
|
||||
ioWriteOpen(write);
|
||||
TEST_ASSIGN(write, ioFdWriteNewOpen(STRDEF("write test"), HARNESS_FORK_CHILD_WRITE(), 1000), "move write");
|
||||
TEST_RESULT_BOOL(ioWriteReadyP(write), true, "write is ready");
|
||||
TEST_RESULT_INT(ioWriteFd(write), ((IoFdWrite *)write->driver)->fd, "check write fd");
|
||||
|
||||
@ -568,9 +567,8 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("read test"), HARNESS_FORK_PARENT_READ_PROCESS(0), 1000);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("read test"), HARNESS_FORK_PARENT_READ_PROCESS(0), 1000);
|
||||
|
||||
ioReadOpen(read);
|
||||
TEST_RESULT_INT(ioReadFd(read), ((IoFdRead *)ioReadDriver(read))->fd, "check fd");
|
||||
TEST_RESULT_PTR(ioReadInterface(read), &read->pub.interface, "check interface");
|
||||
TEST_RESULT_PTR(ioReadDriver(read), read->pub.driver, "check driver");
|
||||
|
@ -24,11 +24,6 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("client read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("client write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
StringList *argList = strLstNew();
|
||||
strLstAddZ(argList, "--stanza=test1");
|
||||
hrnCfgArgRawZ(argList, cfgOptPgPath, "/path/to/pg");
|
||||
@ -36,7 +31,9 @@ testRun(void)
|
||||
strLstAddZ(argList, "--repo1-host-user=repo-host-user");
|
||||
HRN_CFG_LOAD(cfgCmdArchiveGet, argList);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(STRDEF("test"), STRDEF("config"), read, write);
|
||||
ProtocolServer *server = protocolServerNew(
|
||||
STRDEF("test"), STRDEF("config"), ioFdReadNewOpen(STRDEF("client read"), HARNESS_FORK_CHILD_READ(), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("client write"), HARNESS_FORK_CHILD_WRITE(), 2000));
|
||||
|
||||
static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_OPTION_LIST};
|
||||
protocolServerProcess(server, NULL, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler));
|
||||
@ -45,12 +42,10 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolClient *client = protocolClientNew(STRDEF("test"), STRDEF("config"), read, write);
|
||||
ProtocolClient *client = protocolClientNew(
|
||||
STRDEF("test"), STRDEF("config"),
|
||||
ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000));
|
||||
|
||||
VariantList *list = varLstNew();
|
||||
varLstAdd(list, varNewStr(STRDEF("repo1-host")));
|
||||
|
@ -63,11 +63,6 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("client read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("client write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
// Set options
|
||||
StringList *argList = strLstNew();
|
||||
strLstAddZ(argList, "--stanza=test1");
|
||||
@ -99,7 +94,13 @@ testRun(void)
|
||||
// Create server
|
||||
ProtocolServer *server = NULL;
|
||||
|
||||
TEST_ASSIGN(server, protocolServerNew(STRDEF("db test server"), STRDEF("test"), read, write), "create server");
|
||||
TEST_ASSIGN(
|
||||
server,
|
||||
protocolServerNew(
|
||||
STRDEF("db test server"), STRDEF("test"),
|
||||
ioFdReadNewOpen(STRDEF("client read"), HARNESS_FORK_CHILD_READ(), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("client write"), HARNESS_FORK_CHILD_WRITE(), 2000)),
|
||||
"create server");
|
||||
|
||||
static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_DB_LIST};
|
||||
|
||||
@ -112,16 +113,17 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
// Create client
|
||||
ProtocolClient *client = NULL;
|
||||
Db *db = NULL;
|
||||
|
||||
TEST_ASSIGN(client, protocolClientNew(STRDEF("db test client"), STRDEF("test"), read, write), "create client");
|
||||
TEST_ASSIGN(
|
||||
client,
|
||||
protocolClientNew(
|
||||
STRDEF("db test client"), STRDEF("test"),
|
||||
ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000),
|
||||
ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000)),
|
||||
"create client");
|
||||
|
||||
TRY_BEGIN()
|
||||
{
|
||||
|
@ -172,12 +172,10 @@ testRun(void)
|
||||
strIdFromZ(stringIdBit6, "test"), STRDEF("/"), 0, 0, false, NULL, &driver, driver.interface);
|
||||
|
||||
// Setup handler for remote storage protocol
|
||||
IoRead *read = ioFdReadNew(STRDEF("storage server read"), HARNESS_FORK_CHILD_READ(), 60000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("storage server write"), HARNESS_FORK_CHILD_WRITE(), 1000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = protocolServerNew(STRDEF("storage test server"), STRDEF("test"), read, write);
|
||||
ProtocolServer *server = protocolServerNew(
|
||||
STRDEF("storage test server"), STRDEF("test"),
|
||||
ioFdReadNewOpen(STRDEF("storage server read"), HARNESS_FORK_CHILD_READ(), 60000),
|
||||
ioFdWriteNewOpen(STRDEF("storage server write"), HARNESS_FORK_CHILD_WRITE(), 1000));
|
||||
|
||||
static const ProtocolServerHandler commandHandler[] = {PROTOCOL_SERVER_HANDLER_STORAGE_REMOTE_LIST};
|
||||
protocolServerProcess(server, NULL, commandHandler, PROTOCOL_SERVER_HANDLER_LIST_SIZE(commandHandler));
|
||||
@ -188,12 +186,10 @@ testRun(void)
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
// Create client
|
||||
IoRead *read = ioFdReadNew(STRDEF("storage client read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 60000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("storage client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 1000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolClient *client = protocolClientNew(STRDEF("storage test client"), STRDEF("test"), read, write);
|
||||
ProtocolClient *client = protocolClientNew(
|
||||
STRDEF("storage test client"), STRDEF("test"),
|
||||
ioFdReadNewOpen(STRDEF("storage client read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 60000),
|
||||
ioFdWriteNewOpen(STRDEF("storage client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 1000));
|
||||
|
||||
// Create remote storage
|
||||
Storage *storageRemote = storageRemoteNew(
|
||||
|
@ -437,10 +437,8 @@ testRun(void)
|
||||
{
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("server read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("server write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("server read"), HARNESS_FORK_CHILD_READ(), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("server write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
|
||||
// Various bogus greetings
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
@ -494,10 +492,8 @@ testRun(void)
|
||||
|
||||
HARNESS_FORK_PARENT_BEGIN()
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("client read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
ioWriteOpen(write);
|
||||
IoRead *read = ioFdReadNewOpen(STRDEF("client read"), HARNESS_FORK_PARENT_READ_PROCESS(0), 2000);
|
||||
IoWrite *write = ioFdWriteNewOpen(STRDEF("client write"), HARNESS_FORK_PARENT_WRITE_PROCESS(0), 2000);
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("bogus greetings");
|
||||
@ -665,13 +661,14 @@ testRun(void)
|
||||
// Local 1
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("local server 1 read"), HARNESS_FORK_CHILD_READ(), 10000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("local server 1 write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = NULL;
|
||||
TEST_ASSIGN(server, protocolServerNew(STRDEF("local server 1"), STRDEF("test"), read, write), "local server 1");
|
||||
TEST_ASSIGN(
|
||||
server,
|
||||
protocolServerNew(
|
||||
STRDEF("local server 1"), STRDEF("test"),
|
||||
ioFdReadNewOpen(STRDEF("local server 1 read"), HARNESS_FORK_CHILD_READ(), 10000),
|
||||
ioFdWriteNewOpen(STRDEF("local server 1 write"), HARNESS_FORK_CHILD_WRITE(), 2000)),
|
||||
"local server 1");
|
||||
|
||||
TEST_RESULT_UINT(protocolServerCommandGet(server).id, PROTOCOL_COMMAND_NOOP, "noop command get");
|
||||
TEST_RESULT_VOID(protocolServerDataEndPut(server), "data end put");
|
||||
@ -692,13 +689,14 @@ testRun(void)
|
||||
// Local 2
|
||||
HARNESS_FORK_CHILD_BEGIN(0, true)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(STRDEF("local server 2 read"), HARNESS_FORK_CHILD_READ(), 10000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(STRDEF("local server 2 write"), HARNESS_FORK_CHILD_WRITE(), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
ProtocolServer *server = NULL;
|
||||
TEST_ASSIGN(server, protocolServerNew(STRDEF("local server 2"), STRDEF("test"), read, write), "local server 2");
|
||||
TEST_ASSIGN(
|
||||
server,
|
||||
protocolServerNew(
|
||||
STRDEF("local server 2"), STRDEF("test"),
|
||||
ioFdReadNewOpen(STRDEF("local server 2 read"), HARNESS_FORK_CHILD_READ(), 10000),
|
||||
ioFdWriteNewOpen(STRDEF("local server 2 write"), HARNESS_FORK_CHILD_WRITE(), 2000)),
|
||||
"local server 2");
|
||||
|
||||
TEST_RESULT_UINT(protocolServerCommandGet(server).id, PROTOCOL_COMMAND_NOOP, "noop command get");
|
||||
TEST_RESULT_VOID(protocolServerDataEndPut(server), "data end put");
|
||||
@ -733,16 +731,14 @@ testRun(void)
|
||||
|
||||
for (unsigned int clientIdx = 0; clientIdx < clientTotal; clientIdx++)
|
||||
{
|
||||
IoRead *read = ioFdReadNew(
|
||||
strNewFmt("local client %u read", clientIdx), HARNESS_FORK_PARENT_READ_PROCESS(clientIdx), 2000);
|
||||
ioReadOpen(read);
|
||||
IoWrite *write = ioFdWriteNew(
|
||||
strNewFmt("local client %u write", clientIdx), HARNESS_FORK_PARENT_WRITE_PROCESS(clientIdx), 2000);
|
||||
ioWriteOpen(write);
|
||||
|
||||
TEST_ASSIGN(
|
||||
client[clientIdx],
|
||||
protocolClientNew(strNewFmt("local client %u", clientIdx), STRDEF("test"), read, write),
|
||||
protocolClientNew(
|
||||
strNewFmt("local client %u", clientIdx), STRDEF("test"),
|
||||
ioFdReadNewOpen(
|
||||
strNewFmt("local client %u read", clientIdx), HARNESS_FORK_PARENT_READ_PROCESS(clientIdx), 2000),
|
||||
ioFdWriteNewOpen(
|
||||
strNewFmt("local client %u write", clientIdx), HARNESS_FORK_PARENT_WRITE_PROCESS(clientIdx), 2000)),
|
||||
strZ(strNewFmt("local client %u new", clientIdx)));
|
||||
TEST_RESULT_VOID(
|
||||
protocolParallelClientAdd(parallel, client[clientIdx]), strZ(strNewFmt("local client %u add", clientIdx)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user