mirror of
https://github.com/yuzu-emu/discord-rpc.git
synced 2024-11-30 17:04:14 +01:00
Add a few more null checks.
This commit is contained in:
parent
fa39179be7
commit
19abe80449
@ -71,13 +71,22 @@ bool BaseConnection::Close()
|
|||||||
|
|
||||||
bool BaseConnection::Write(const void* data, size_t length)
|
bool BaseConnection::Write(const void* data, size_t length)
|
||||||
{
|
{
|
||||||
|
if (length == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
||||||
|
if (self->pipe == INVALID_HANDLE_VALUE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return ::WriteFile(self->pipe, data, (DWORD)length, nullptr, nullptr) == TRUE;
|
return ::WriteFile(self->pipe, data, (DWORD)length, nullptr, nullptr) == TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BaseConnection::Read(void* data, size_t length)
|
bool BaseConnection::Read(void* data, size_t length)
|
||||||
{
|
{
|
||||||
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
||||||
|
if (self->pipe == INVALID_HANDLE_VALUE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
DWORD bytesAvailable = 0;
|
DWORD bytesAvailable = 0;
|
||||||
if (::PeekNamedPipe(self->pipe, nullptr, 0, nullptr, &bytesAvailable, nullptr)) {
|
if (::PeekNamedPipe(self->pipe, nullptr, 0, nullptr, &bytesAvailable, nullptr)) {
|
||||||
if (bytesAvailable >= length) {
|
if (bytesAvailable >= length) {
|
||||||
|
@ -95,6 +95,10 @@ static void SendQueueCommitMessage()
|
|||||||
|
|
||||||
extern "C" void Discord_UpdateConnection()
|
extern "C" void Discord_UpdateConnection()
|
||||||
{
|
{
|
||||||
|
if (!Connection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Connection->IsOpen()) {
|
if (!Connection->IsOpen()) {
|
||||||
if (std::chrono::system_clock::now() >= NextConnect) {
|
if (std::chrono::system_clock::now() >= NextConnect) {
|
||||||
UpdateReconnectTime();
|
UpdateReconnectTime();
|
||||||
@ -292,6 +296,10 @@ extern "C" void Discord_RunCallbacks()
|
|||||||
// of times inbetween calls here. Externally, we want the sequence to seem sane, so any other
|
// of times inbetween calls here. Externally, we want the sequence to seem sane, so any other
|
||||||
// signals are book-ended by calls to ready and disconnect.
|
// signals are book-ended by calls to ready and disconnect.
|
||||||
|
|
||||||
|
if (!Connection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool wasDisconnected = WasJustDisconnected.exchange(false);
|
bool wasDisconnected = WasJustDisconnected.exchange(false);
|
||||||
bool isConnected = Connection->IsOpen();
|
bool isConnected = Connection->IsOpen();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user