Get pipe from base connection instance
This commit is contained in:
parent
d5a342c7bb
commit
2f52c24f6d
@ -62,9 +62,8 @@ bool BaseConnection::Open(int pipe)
|
|||||||
int optval = 1;
|
int optval = 1;
|
||||||
setsockopt(self->sock, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval));
|
setsockopt(self->sock, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval));
|
||||||
#endif
|
#endif
|
||||||
for (int pipeNum = pipe; pipeNum < 10; ++pipeNum) {
|
for (pipe; pipe < 10; ++pipe) {
|
||||||
snprintf(
|
snprintf(PipeAddr.sun_path, sizeof(PipeAddr.sun_path), "%s/discord-ipc-%d", tempPath, pipe);
|
||||||
PipeAddr.sun_path, sizeof(PipeAddr.sun_path), "%s/discord-ipc-%d", tempPath, pipeNum);
|
|
||||||
int err = connect(self->sock, (const sockaddr*)&PipeAddr, sizeof(PipeAddr));
|
int err = connect(self->sock, (const sockaddr*)&PipeAddr, sizeof(PipeAddr));
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
self->isOpen = true;
|
self->isOpen = true;
|
||||||
|
@ -67,7 +67,6 @@ static QueuedMessage QueuedPresence{};
|
|||||||
static MsgQueue<QueuedMessage, MessageQueueSize> SendQueue;
|
static MsgQueue<QueuedMessage, MessageQueueSize> SendQueue;
|
||||||
static MsgQueue<User, JoinQueueSize> JoinAskQueue;
|
static MsgQueue<User, JoinQueueSize> JoinAskQueue;
|
||||||
static User connectedUser;
|
static User connectedUser;
|
||||||
static int PipeNumber{0};
|
|
||||||
|
|
||||||
// We want to auto connect, and retry on failure, but not as fast as possible. This does expoential
|
// We want to auto connect, and retry on failure, but not as fast as possible. This does expoential
|
||||||
// backoff from 0.5 seconds to 1 minute
|
// backoff from 0.5 seconds to 1 minute
|
||||||
@ -142,7 +141,7 @@ static void Discord_UpdateConnection(void)
|
|||||||
if (!Connection->IsOpen()) {
|
if (!Connection->IsOpen()) {
|
||||||
if (std::chrono::system_clock::now() >= NextConnect) {
|
if (std::chrono::system_clock::now() >= NextConnect) {
|
||||||
UpdateReconnectTime();
|
UpdateReconnectTime();
|
||||||
Connection->Open(PipeNumber);
|
Connection->Open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -275,7 +274,7 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
|||||||
DiscordEventHandlers* handlers,
|
DiscordEventHandlers* handlers,
|
||||||
int autoRegister,
|
int autoRegister,
|
||||||
const char* optionalSteamId,
|
const char* optionalSteamId,
|
||||||
int pipe = 0)
|
int pipe)
|
||||||
{
|
{
|
||||||
IoThread = new (std::nothrow) IoThreadHolder();
|
IoThread = new (std::nothrow) IoThreadHolder();
|
||||||
if (IoThread == nullptr) {
|
if (IoThread == nullptr) {
|
||||||
@ -310,9 +309,7 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PipeNumber = pipe;
|
Connection = RpcConnection::Create(applicationId, pipe);
|
||||||
|
|
||||||
Connection = RpcConnection::Create(applicationId, PipeNumber);
|
|
||||||
Connection->onConnect = [](JsonDocument& readyMessage) {
|
Connection->onConnect = [](JsonDocument& readyMessage) {
|
||||||
Discord_UpdateHandlers(&QueuedHandlers);
|
Discord_UpdateHandlers(&QueuedHandlers);
|
||||||
if (QueuedPresence.length > 0) {
|
if (QueuedPresence.length > 0) {
|
||||||
|
@ -21,13 +21,13 @@ static RpcConnection Instance;
|
|||||||
c = nullptr;
|
c = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RpcConnection::Open(int pipe)
|
void RpcConnection::Open()
|
||||||
{
|
{
|
||||||
if (state == State::Connected) {
|
if (state == State::Connected) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == State::Disconnected && !connection->Open(pipe)) {
|
if (state == State::Disconnected && !connection->Open(Instance.pipe)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,12 +48,12 @@ struct RpcConnection {
|
|||||||
char lastErrorMessage[256]{};
|
char lastErrorMessage[256]{};
|
||||||
RpcConnection::MessageFrame sendFrame;
|
RpcConnection::MessageFrame sendFrame;
|
||||||
|
|
||||||
static RpcConnection* Create(const char* applicationId, int optionalPipeNumber);
|
static RpcConnection* Create(const char* applicationId, int pipe);
|
||||||
static void Destroy(RpcConnection*&);
|
static void Destroy(RpcConnection*&);
|
||||||
|
|
||||||
inline bool IsOpen() const { return state == State::Connected; }
|
inline bool IsOpen() const { return state == State::Connected; }
|
||||||
|
|
||||||
void Open(int pipe);
|
void Open();
|
||||||
void Close();
|
void Close();
|
||||||
bool Write(const void* data, size_t length);
|
bool Write(const void* data, size_t length);
|
||||||
bool Read(JsonDocument& message);
|
bool Read(JsonDocument& message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user