Add a few more null checks.

This commit is contained in:
Chris Marsh
2017-09-07 09:23:35 -07:00
parent fa39179be7
commit 19abe80449
2 changed files with 17 additions and 0 deletions

View File

@@ -71,13 +71,22 @@ bool BaseConnection::Close()
bool BaseConnection::Write(const void* data, size_t length)
{
if (length == 0) {
return true;
}
auto self = reinterpret_cast<BaseConnectionWin*>(this);
if (self->pipe == INVALID_HANDLE_VALUE) {
return false;
}
return ::WriteFile(self->pipe, data, (DWORD)length, nullptr, nullptr) == TRUE;
}
bool BaseConnection::Read(void* data, size_t length)
{
auto self = reinterpret_cast<BaseConnectionWin*>(this);
if (self->pipe == INVALID_HANDLE_VALUE) {
return false;
}
DWORD bytesAvailable = 0;
if (::PeekNamedPipe(self->pipe, nullptr, 0, nullptr, &bytesAvailable, nullptr)) {
if (bytesAvailable >= length) {