Skip to content

Commit

Permalink
fix: its a pair now
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Jul 30, 2023
1 parent a2a5feb commit 4222c46
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
8 changes: 3 additions & 5 deletions src/singletons/NativeMessaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,21 @@ void NativeMessagingServer::start()

void NativeMessagingServer::ReceiverThread::run()
{
auto result =
auto [messageQueue, error] =
ipc::IpcQueue::tryReplaceOrCreate("chatterino_gui", 100, MESSAGE_SIZE);

if (std::holds_alternative<QString>(result))
if (!error.isEmpty())
{
auto error = std::get<QString>(result);
qCDebug(chatterinoNativeMessage)
<< "Failed to create message queue:" << error;

nmIpcError().set(error);
return;
}

auto &messageQueue = std::get<ipc::IpcQueue>(result);
while (true)
{
auto buf = messageQueue.receive();
auto buf = messageQueue->receive();
if (buf.isEmpty())
{
continue;
Expand Down
9 changes: 6 additions & 3 deletions src/util/IpcQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ IpcQueue::IpcQueue(IpcQueuePrivate *priv)
: private_(priv){};
IpcQueue::~IpcQueue() = default;

std::variant<IpcQueue, QString> IpcQueue::tryReplaceOrCreate(
std::pair<std::unique_ptr<IpcQueue>, QString> IpcQueue::tryReplaceOrCreate(
const char *name, size_t maxMessages, size_t maxMessageSize)
{
try
{
boost_ipc::message_queue::remove(name);
return IpcQueue(new IpcQueuePrivate(name, maxMessages, maxMessageSize));
return std::make_pair(
std::unique_ptr<IpcQueue>(new IpcQueue(
new IpcQueuePrivate(name, maxMessages, maxMessageSize))),
QString());
}
catch (boost_ipc::interprocess_exception &ex)
{
return QString::fromLatin1(ex.what());
return {nullptr, QString::fromLatin1(ex.what())};
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/util/IpcQueue.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <memory>
#include <variant>
#include <utility>

class QByteArray;
class QString;
Expand All @@ -16,7 +16,7 @@ class IpcQueue
public:
~IpcQueue();

static std::variant<IpcQueue, QString> tryReplaceOrCreate(
static std::pair<std::unique_ptr<IpcQueue>, QString> tryReplaceOrCreate(
const char *name, size_t maxMessages, size_t maxMessageSize);

// TODO: use std::expected
Expand Down

0 comments on commit 4222c46

Please sign in to comment.