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