fix(linux): more shit

This commit is contained in:
Mohamed Ashraf authored and Anaël committed 2026-11-28 01:58:00 +01:00
1 parent 20278c2856
commit a0a35f3c0b
18 files changed
+267 -80

No files matched your search

+28 -13
View File
@@ -19,14 +19,20 @@ int Connection::writeThreads = 0;
int Connection::readSizes[256];
int Connection::writeSizes[256];
#if defined(__linux__)
#define INFINITE 999999999
#define WAIT_TIMEOUT 258
#include <unistd.h>
#endif //__linux__
void Connection::_init()
{
// printf("Con:0x%x init\n",this);
#if !defined(__linux__)
InitializeCriticalSection(&writeLock);
InitializeCriticalSection(&threadCounterLock);
InitializeCriticalSection(&incoming_cs);
#endif
running = true;
quitting = false;
@@ -54,11 +60,11 @@ Connection::~Connection()
// may get stuck whilst blocking waiting on a read
readThread->WaitForCompletion(INFINITE);
writeThread->WaitForCompletion(INFINITE);
#if defined(__linux__)
DeleteCriticalSection(&writeLock);
DeleteCriticalSection(&threadCounterLock);
DeleteCriticalSection(&incoming_cs);
#endif // __linux__
delete m_hWakeReadThread;
delete m_hWakeWriteThread;
@@ -99,7 +105,7 @@ Connection::Connection(Socket *socket, const wstring& id, PacketListener *packet
}*/
dis = new DataInputStream(socket->getInputStream(packetListener->isServerPacketListener()));
sos = socket->getOutputStream(packetListener->isServerPacketListener());
bufferedDos = new DataOutputStream(new BufferedOutputStream(sos, SEND_BUFFER_SIZE));
baos = new ByteArrayOutputStream( SEND_BUFFER_SIZE );
@@ -127,7 +133,7 @@ Connection::Connection(Socket *socket, const wstring& id, PacketListener *packet
writeThread->Run();
/* 4J JEV, java:
/* 4J JEV, java:
new Thread(wstring(id).append(L" read thread")) {
};
@@ -183,7 +189,7 @@ void Connection::send(shared_ptr<Packet> packet)
message.createTime = packet->createTime;
message.isRaw = false;
message.isSlow = packet->shouldDelay;
if (packet->shouldDelay)
if (packet->shouldDelay)
{
// 4J We have delayed it enough by putting it in the slow queue, so don't delay when we actually send it
packet->shouldDelay = false;
@@ -326,7 +332,7 @@ bool Connection::readTick()
}
LeaveCriticalSection(&incoming_cs);
didSomething = true;
}
}
else
{
// printf("Con:0x%x readTick close EOS\n",this);
@@ -386,7 +392,7 @@ void Connection::close(DisconnectPacket::eDisconnectReason reason, ...)
// int count = 0, sum = 0, i = first;
// va_list marker;
//
//
// va_start( marker, first );
// while( i != -1 )
// {
@@ -629,13 +635,13 @@ int Connection::runWrite(void* lpParam)
// Otherwise there is a race between the calling thread setting the running flag and this loop checking the condition
DWORD waitResult = WAIT_TIMEOUT;
while ((con->running || waitResult == WAIT_OBJECT_0 ) && ShutdownManager::ShouldRun(ShutdownManager::eConnectionWriteThreads))
while ((con->running || waitResult == 0 ) && ShutdownManager::ShouldRun(ShutdownManager::eConnectionWriteThreads))
{
while (con->writeTick())
;
//Sleep(100L);
// TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure whether we should do that as well
//Sleep(100L);
// TODO - 4J Stu - 1.8.2 changes these sleeps to 2L, but not sure whether we should do that as well
waitResult = con->m_hWakeWriteThread->WaitForSignal(100L);
if (con->bufferedDos != nullptr) con->bufferedDos->flush();
@@ -660,7 +666,12 @@ int Connection::runClose(void* lpParam)
//try {
Sleep(2000);
#ifdef _WIN32
Sleep(2000);
#else
sleep(2000);
#endif
if (con->running)
{
// 4J TODO writeThread.interrupt();
@@ -683,8 +694,12 @@ int Connection::runSendAndQuit(void* lpParam)
if (con == nullptr) return 0;
//try {
#ifdef _WIN32
Sleep(2000);
#else
sleep(2000);
#endif
if (con->running)
{
// 4J TODO writeThread.interrupt();