Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Fixed freezing on send
Browse files Browse the repository at this point in the history
  • Loading branch information
Soreepeong committed Jul 14, 2017
1 parent 632c0a5 commit 92b36b5
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 108 deletions.
59 changes: 53 additions & 6 deletions FFXIVDLL/GameDataProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ void GameDataProcess::ProcessGameMessage(SOCKET s, GAME_MESSAGE *data, uint64_t
if (msg->Combat.AbilityResponse.skill > 7 &&
msg->Combat.AbilityResponse.duration_or_skid >= 10 &&
msg->Combat.AbilityResponse.duration_or_skid <= 60000 * 8 &&
msg->actor == mSelfId &&
msg->actor == mSelfId &&
FFXIVResources::IsKnownSkill(msg->Combat.AbilityResponse.skill) &&
IsInCombat()
) {
Expand Down Expand Up @@ -1535,22 +1535,69 @@ void GameDataProcess::TryParsePacket(Tools::ByteQueue &in, Tools::ByteQueue &out
}

void GameDataProcess::UpdateInfoThread() {
int mapClearer = 0;
while (WaitForSingleObject(hUnloadEvent, 0) == WAIT_TIMEOUT) {
WaitForSingleObject(hUpdateInfoThreadLock, 50);
ResolveUsers();
std::map<SOCKET, int> availSocks;
{
std::lock_guard<std::recursive_mutex> guard(mSocketMapLock);
for (auto i = mRecv.cbegin(); i != mRecv.cend(); ++i)
if (!i->second->isEmpty())
availSocks[i->first] |= 1;
for (auto i = mSent.cbegin(); i != mSent.cend(); ++i)
if (!i->second->isEmpty())
availSocks[i->first] |= 2;
}
for (auto s = availSocks.cbegin(); s != availSocks.cend(); ++s) {
Tools::ByteQueue *need_process;
if ((s->second & 1) && !(need_process = mRecv[s->first])->isEmpty()) {
Tools::ByteQueue *torecv;
{
std::lock_guard<std::recursive_mutex> guard(mSocketMapLock);
torecv = mToRecv[s->first] ? mToRecv[s->first] : (mToRecv[s->first] = new Tools::ByteQueue());
}
TryParsePacket(*need_process, *(torecv), s->first, true);
}
if ((s->second & 2) && !(need_process = mSent[s->first])->isEmpty()) {
Tools::ByteQueue *tosend;
{
std::lock_guard<std::recursive_mutex> guard(mSocketMapLock);
tosend = mToSend[s->first] ? mToSend[s->first] : (mToSend[s->first] = new Tools::ByteQueue());
}
TryParsePacket(*need_process, *(tosend), s->first, false);
}
}
if (++mapClearer > 100) {
std::lock_guard<std::recursive_mutex> guard(mSocketMapLock);
mapClearer = 0;
for (auto i = mRecv.begin(); i != mRecv.end(); ) {
TryParsePacket(i->second, mToRecv[i->first], i->first, true);
if (i->second.isStall())
if (i->second->isStall()) {
delete i->second;
i = mRecv.erase(i);
else
} else
++i;
}
for (auto i = mToRecv.begin(); i != mToRecv.end(); ) {
if (i->second.isStall())
if (i->second->isStall()) {
delete i->second;
i = mToRecv.erase(i);
else
} else
++i;
}
for (auto i = mSent.begin(); i != mSent.end(); ) {
if (i->second->isStall()) {
delete i->second;
i = mSent.erase(i);
} else
++i;
}

for (auto i = mToSend.begin(); i != mToSend.end(); ) {
if (i->second->isStall()) {
delete i->second;
i = mToSend.erase(i);
} else
++i;
}
}
Expand Down
30 changes: 26 additions & 4 deletions FFXIVDLL/GameDataProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ class GameDataProcess {
std::map<std::wstring, DWORD> mClassColors;

std::recursive_mutex mSocketMapLock;
std::map<SOCKET, Tools::ByteQueue> mSent, mRecv;
std::map<SOCKET, Tools::ByteQueue> mToSend, mToRecv;
std::map<SOCKET, Tools::ByteQueue*> mSent, mRecv;
std::map<SOCKET, Tools::ByteQueue*> mToSend, mToRecv;
std::map<SOCKET, Tools::bqueue<GAME_MESSAGE>> mRecvAdd;
GAME_PACKET mInboundPacketTemplate;
int mInboundSequenceId;
Expand Down Expand Up @@ -434,8 +434,30 @@ class GameDataProcess {
int GetVersion();

void OnRecv(SOCKET s, char* buf, int len) {
mRecv[s].write(buf, len);
if (mRecv[s].getUsed() >= 28)
Tools::ByteQueue *bq;
{
std::lock_guard<std::recursive_mutex> guard(mSocketMapLock);
if (mRecv[s] == nullptr)
bq = mRecv[s] = new Tools::ByteQueue();
else
bq = mRecv[s];
}
bq->write(buf, len);
if (bq->getUsed() >= 28)
SetEvent(hUpdateInfoThreadLock);
}

void OnSend(SOCKET s, const char* buf, int len) {
Tools::ByteQueue *bq;
{
std::lock_guard<std::recursive_mutex> guard(mSocketMapLock);
if (mSent[s] == nullptr)
bq = mSent[s] = new Tools::ByteQueue();
else
bq = mSent[s];
}
bq->write(buf, len);
if (bq->getUsed() >= 28)
SetEvent(hUpdateInfoThreadLock);
}
};
Loading

0 comments on commit 92b36b5

Please sign in to comment.