mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-08-09 11:39:06 +00:00
Connection: Replace usages of goto
This commit is contained in:
parent
6c9fdfcbb7
commit
ac4858b857
@ -107,7 +107,7 @@ static int Write(int fd, const void* buf, size_t size) {
|
|||||||
|
|
||||||
uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
|
uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
|
||||||
uint32_t readLen;
|
uint32_t readLen;
|
||||||
int ret = Read(m_readpipe[0], &readLen, 4);
|
int ret = Read(m_readpipe[0], &readLen, sizeof(readLen));
|
||||||
if (ret < 4) {
|
if (ret < 4) {
|
||||||
BlenderLog.report(logvisor::Error, fmt("Pipe error {} {}"), ret, strerror(errno));
|
BlenderLog.report(logvisor::Error, fmt("Pipe error {} {}"), ret, strerror(errno));
|
||||||
_blenderDied();
|
_blenderDied();
|
||||||
@ -124,8 +124,11 @@ uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
BlenderLog.report(logvisor::Fatal, fmt("{}"), strerror(errno));
|
BlenderLog.report(logvisor::Fatal, fmt("{}"), strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
} else if (readLen >= 9) {
|
}
|
||||||
if (!memcmp(buf, "EXCEPTION", std::min(readLen, uint32_t(9)))) {
|
|
||||||
|
constexpr std::string_view exception_str{"EXCEPTION"};
|
||||||
|
if (readLen >= exception_str.size()) {
|
||||||
|
if (exception_str.compare(0, exception_str.size(), buf) == 0) {
|
||||||
_blenderDied();
|
_blenderDied();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -136,54 +139,75 @@ uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Connection::_writeStr(const char* buf, uint32_t len, int wpipe) {
|
uint32_t Connection::_writeStr(const char* buf, uint32_t len, int wpipe) {
|
||||||
int ret, nlerr;
|
const auto error = [this] {
|
||||||
nlerr = Write(wpipe, &len, 4);
|
_blenderDied();
|
||||||
if (nlerr < 4)
|
return 0U;
|
||||||
goto err;
|
};
|
||||||
ret = Write(wpipe, buf, len);
|
|
||||||
if (ret < 0)
|
const int nlerr = Write(wpipe, &len, 4);
|
||||||
goto err;
|
if (nlerr < 4) {
|
||||||
return (uint32_t)ret;
|
return error();
|
||||||
err:
|
}
|
||||||
_blenderDied();
|
|
||||||
return 0;
|
const int ret = Write(wpipe, buf, len);
|
||||||
|
if (ret < 0) {
|
||||||
|
return error();
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<uint32_t>(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Connection::_readBuf(void* buf, size_t len) {
|
size_t Connection::_readBuf(void* buf, size_t len) {
|
||||||
uint8_t* cBuf = reinterpret_cast<uint8_t*>(buf);
|
const auto error = [this] {
|
||||||
|
_blenderDied();
|
||||||
|
return 0U;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto* cBuf = static_cast<uint8_t*>(buf);
|
||||||
size_t readLen = 0;
|
size_t readLen = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int ret = Read(m_readpipe[0], cBuf, len);
|
const int ret = Read(m_readpipe[0], cBuf, len);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
goto err;
|
return error();
|
||||||
if (len >= 9)
|
}
|
||||||
if (!memcmp((char*)cBuf, "EXCEPTION", std::min(len, size_t(9))))
|
|
||||||
|
constexpr std::string_view exception_str{"EXCEPTION"};
|
||||||
|
if (len >= exception_str.size()) {
|
||||||
|
if (exception_str.compare(0, exception_str.size(), static_cast<char*>(buf)) == 0) {
|
||||||
_blenderDied();
|
_blenderDied();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readLen += ret;
|
readLen += ret;
|
||||||
cBuf += ret;
|
cBuf += ret;
|
||||||
len -= ret;
|
len -= ret;
|
||||||
} while (len);
|
} while (len != 0);
|
||||||
|
|
||||||
return readLen;
|
return readLen;
|
||||||
err:
|
|
||||||
_blenderDied();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Connection::_writeBuf(const void* buf, size_t len) {
|
size_t Connection::_writeBuf(const void* buf, size_t len) {
|
||||||
const uint8_t* cBuf = reinterpret_cast<const uint8_t*>(buf);
|
const auto error = [this] {
|
||||||
|
_blenderDied();
|
||||||
|
return 0U;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto* cBuf = static_cast<const uint8_t*>(buf);
|
||||||
size_t writeLen = 0;
|
size_t writeLen = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int ret = Write(m_writepipe[1], cBuf, len);
|
const int ret = Write(m_writepipe[1], cBuf, len);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
goto err;
|
return error();
|
||||||
|
}
|
||||||
|
|
||||||
writeLen += ret;
|
writeLen += ret;
|
||||||
cBuf += ret;
|
cBuf += ret;
|
||||||
len -= ret;
|
len -= ret;
|
||||||
} while (len);
|
} while (len != 0);
|
||||||
|
|
||||||
return writeLen;
|
return writeLen;
|
||||||
err:
|
|
||||||
_blenderDied();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::_closePipe() {
|
void Connection::_closePipe() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user