2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 02:27:40 -04:00

CWE Directory Reorganization

Rearrange directory structure of CWE to be loosely equivalent to
the H'uru Plasma repository.

Part 1: Movement of directories and files.
This commit is contained in:
rarified
2021-05-15 12:49:46 -06:00
parent c3f4a640a3
commit 96903e8dca
4002 changed files with 159 additions and 644 deletions

View File

@ -0,0 +1,91 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9x.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
#include "pnAceW9xInt.h"
/****************************************************************************
*
* Exported functions
*
***/
//===========================================================================
void W9xGetApi (AsyncApi * api) {
using namespace W9x;
api->initialize = W9xThreadInitialize;
api->destroy = W9xThreadDestroy;
api->signalShutdown = W9xThreadSignalShutdown;
api->waitForShutdown = W9xThreadWaitForShutdown;
api->sleep = W9xThreadSleep;
api->fileOpen = W9xFileOpen;
api->fileClose = W9xFileClose;
api->fileRead = W9xFileRead;
api->fileWrite = W9xFileWrite;
api->fileFlushBuffers = W9xFileFlushBuffers;
api->fileSetLastWriteTime = W9xFileSetLastWriteTime;
api->fileGetLastWriteTime = W9xFileGetLastWriteTime;
api->fileCreateSequence = W9xFileCreateSequence;
api->fileSeek = W9xFileSeek;
api->socketConnect = W9xSocketConnect;
api->socketConnectCancel = W9xSocketConnectCancel;
api->socketDisconnect = W9xSocketDisconnect;
api->socketDelete = W9xSocketDelete;
api->socketSend = W9xSocketSend;
api->socketWrite = W9xSocketWrite;
api->socketSetNotifyProc = W9xSocketSetNotifyProc;
api->socketSetBacklogAlloc = W9xSocketSetBacklogAlloc;
api->socketStartListening = W9xSocketStartListening;
api->socketStopListening = W9xSocketStopListening;
api->socketEnableNagling = W9xSocketEnableNagling;
}

View File

@ -0,0 +1,64 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9x.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_W9X_PNACEW9X_H
#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9x.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_W9X_PNACEW9X_H
#ifdef HS_BUILD_FOR_WIN32
/****************************************************************************
*
* Win9x API functions
*
***/
void W9xGetApi (AsyncApi * api);
#endif // HS_BUILD_FOR_WIN32

View File

@ -0,0 +1,518 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xFile.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
#include "pnAceW9xInt.h"
namespace W9x {
/****************************************************************************
*
* FileOp
*
***/
struct FileOp {
EAsyncNotifyFile code;
bool notify;
union {
AsyncNotifyFileFlush flush;
AsyncNotifyFileRead read;
AsyncNotifyFileSequence sequence;
AsyncNotifyFileWrite write;
} data;
};
/****************************************************************************
*
* CFile
*
***/
class CFile : public CThreadDispObject {
private:
CCritSect m_critSect;
HANDLE m_handle;
FAsyncNotifyFileProc m_notifyProc;
void * m_userState;
protected:
void Complete (void * op, CCritSect * critSect, AsyncId asyncId);
void Delete (void * op);
public:
CFile (
HANDLE handle,
FAsyncNotifyFileProc notifyProc,
void * userState
);
~CFile ();
void Read (
qword offset,
void * buffer,
unsigned bytes
);
void SetLastWriteTime (qword lastWriteTime);
void Truncate (qword size);
void Write (
qword offset,
const void * buffer,
unsigned bytes
);
bool Seek (qword offset, EFileSeekFrom from);
};
//===========================================================================
CFile::CFile (
HANDLE handle,
FAsyncNotifyFileProc notifyProc,
void * userState
) :
m_handle(handle),
m_notifyProc(notifyProc),
m_userState(userState)
{
}
//===========================================================================
CFile::~CFile () {
CloseHandle(m_handle);
m_handle = INVALID_HANDLE_VALUE;
}
//===========================================================================
void CFile::Complete (void * op, CCritSect * critSect, AsyncId asyncId) {
FileOp * fileOp = (FileOp *)op;
// Enter our local critical section and leave the global one
m_critSect.Enter();
critSect->Leave();
// Complete the operation
switch (fileOp->code) {
case kNotifyFileFlush: {
if (fileOp->data.flush.truncateSize != kAsyncFileDontTruncate)
Truncate(fileOp->data.flush.truncateSize);
BOOL result = FlushFileBuffers(m_handle);
fileOp->data.flush.error = result ? kFileSuccess : AsyncGetLastFileError();
}
break;
case kNotifyFileRead:
Read(
fileOp->data.read.offset,
fileOp->data.read.buffer,
fileOp->data.read.bytes
);
break;
case kNotifyFileWrite:
Write(
fileOp->data.write.offset,
fileOp->data.write.buffer,
fileOp->data.write.bytes
);
break;
}
// Leave our local critical section
m_critSect.Leave();
// Dispatch a completion notification
if (fileOp->notify) {
fileOp->data.flush.asyncId = asyncId;
m_notifyProc(
(AsyncFile)this,
fileOp->code,
&fileOp->data.flush,
&m_userState
);
}
}
//===========================================================================
void CFile::Delete (void * op) {
FileOp * fileOp = (FileOp *)op;
DEL(fileOp);
}
//===========================================================================
void CFile::Read (
qword offset,
void * buffer,
unsigned bytes
) {
// Seek to the start of the read
Seek(offset, kFileSeekFromBegin);
// Perform the read
DWORD bytesRead;
BOOL result = ReadFile(
m_handle,
buffer,
bytes,
&bytesRead,
nil // overlapped
);
// Handle errors
if (bytesRead != bytes)
MemZero((byte *)buffer + bytesRead, bytes - bytesRead);
if ( (!result && (GetLastError() != ERROR_IO_PENDING)) ||
(bytesRead != bytes) )
LogMsg(kLogFatal, "failed: ReadFile");
}
//===========================================================================
bool CFile::Seek (qword offset, EFileSeekFrom from) {
COMPILER_ASSERT(kFileSeekFromBegin == FILE_BEGIN);
COMPILER_ASSERT(kFileSeekFromCurrent == FILE_CURRENT);
COMPILER_ASSERT(kFileSeekFromEnd == FILE_END);
LONG low = (LONG)(offset % 0x100000000ul);
LONG high = (LONG)(offset / 0x100000000ul);
dword result = SetFilePointer(m_handle, low, &high, from);
if ((result == (dword)-1) && (GetLastError() != NO_ERROR)) {
LogMsg(kLogFatal, "failed: SetFilePointer");
return false;
}
else
return true;
}
//===========================================================================
void CFile::SetLastWriteTime (qword lastWriteTime) {
COMPILER_ASSERT(sizeof(lastWriteTime) == sizeof(FILETIME));
SetFileTime(m_handle, nil, nil, (const FILETIME *)&lastWriteTime);
}
//===========================================================================
void CFile::Truncate (qword size) {
ASSERT(size != kAsyncFileDontTruncate);
if (Seek(size, kFileSeekFromBegin) && !SetEndOfFile(m_handle))
LogMsg(kLogFatal, "failed: SetEndOfFile");
}
//===========================================================================
void CFile::Write (
qword offset,
const void * buffer,
unsigned bytes
) {
// Seek to the start of the write
Seek(offset, kFileSeekFromBegin);
// Perform the write
DWORD bytesWritten;
BOOL result = WriteFile(
m_handle,
buffer,
bytes,
&bytesWritten,
nil // overlapped
);
// Handle errors
if ( (!result && (GetLastError() != ERROR_IO_PENDING)) ||
(bytesWritten != bytes) ) {
LogMsg(kLogFatal, "failed: WriteFile");
if (!result && (GetLastError() == ERROR_DISK_FULL)) {
MessageBox(nil, "Disk full!", "Error", MB_ICONSTOP | MB_SYSTEMMODAL);
// DebugDisableLeakChecking();
ExitProcess(1);
}
}
}
/****************************************************************************
*
* Exported functions
*
***/
//===========================================================================
void W9xFileClose (
AsyncFile file,
qword truncateSize
) {
// Dereference the object
CFile * object = (CFile *)file;
// If requested, truncate the file
if (truncateSize != kAsyncFileDontTruncate)
object->Truncate(truncateSize);
// Close the file object
object->Close();
}
//===========================================================================
AsyncId W9xFileCreateSequence (
AsyncFile file,
bool notify,
void * param
) {
// Dereference the object
CFile * object = (CFile *)file;
// Queue an operation
FileOp * op = NEW(FileOp);
op->code = kNotifyFileSequence;
op->notify = notify;
op->data.flush.param = param;
return object->Queue(op);
}
//===========================================================================
AsyncId W9xFileFlushBuffers (
AsyncFile file,
qword truncateSize,
bool notify,
void * param
) {
// Dereference the object
CFile * object = (CFile *)file;
// Queue an operation
FileOp * op = NEW(FileOp);
op->code = kNotifyFileFlush;
op->notify = notify;
op->data.flush.param = param;
op->data.flush.truncateSize = truncateSize;
// op->data.flush.error filled in upon completion
return object->Queue(op);
}
//===========================================================================
AsyncFile W9xFileOpen (
const wchar fullPath[],
FAsyncNotifyFileProc notifyProc,
EFileError * error,
unsigned desiredAccess,
unsigned openMode,
unsigned shareModeFlags,
void * userState,
qword * fileSize,
qword * fileLastWriteTime
) {
HANDLE fileHandle = CreateFileW(
fullPath,
desiredAccess,
shareModeFlags,
nil, // plSecurityAttributes
openMode,
0, // attributeFlags
nil // hTemplateFile
);
*error = AsyncGetLastFileError();
if (INVALID_HANDLE_VALUE == fileHandle)
return nil;
// don't allow users to open devices like "LPT1", etc.
if (GetFileType(fileHandle) != FILE_TYPE_DISK) {
LogMsg(kLogFatal, "failed: !FILE_TYPE_DISK");
*error = kFileErrorFileNotFound;
CloseHandle(fileHandle);
return nil;
}
// Get the file size
DWORD sizeHi, sizeLo = GetFileSize(fileHandle, &sizeHi);
if ((sizeLo == (DWORD) -1) && (NO_ERROR != GetLastError())) {
*error = AsyncGetLastFileError();
LogMsg(kLogFatal, "failed: GetFileSize");
CloseHandle(fileHandle);
return nil;
}
const qword size = ((qword) sizeHi << (qword) 32) | (qword) sizeLo;
qword lastWriteTime;
ASSERT(sizeof(lastWriteTime) >= sizeof(FILETIME));
GetFileTime(fileHandle, nil, nil, (FILETIME *) &lastWriteTime);
// Create a file object
CFile * object = NEW(CFile)(
fileHandle,
notifyProc,
userState
);
// return out parameters
if (fileSize)
*fileSize = size;
if (fileLastWriteTime)
*fileLastWriteTime = lastWriteTime;
return (AsyncFile)object;
}
//===========================================================================
AsyncId W9xFileRead (
AsyncFile file,
qword offset,
void * buffer,
unsigned bytes,
unsigned flags,
void * param
) {
// Dereference the object
CFile * object = (CFile *)file;
// Perform synchronous operations immediately
if (flags & kAsyncFileRwSync) {
object->Read(offset, buffer, bytes);
return 0;
}
// Queue asynchronous operations
else {
FileOp * op = NEW(FileOp);
op->code = kNotifyFileRead;
op->notify = (flags & kAsyncFileRwNotify) != 0;
op->data.read.param = param;
op->data.read.offset = offset;
op->data.read.buffer = (byte *)buffer;
op->data.read.bytes = bytes;
return object->Queue(op);
}
}
//===========================================================================
void W9xFileSetLastWriteTime (
AsyncFile file,
qword lastWriteTime
) {
// Dereference the object
CFile * object = (CFile *)file;
// Set the file time
object->SetLastWriteTime(lastWriteTime);
}
//===========================================================================
qword W9xFileGetLastWriteTime (
const wchar fileName[]
) {
WIN32_FILE_ATTRIBUTE_DATA info;
bool f = GetFileAttributesExW(fileName, GetFileExInfoStandard, &info);
return f ? *((qword *) &info.ftLastWriteTime) : 0;
}
//===========================================================================
AsyncId W9xFileWrite (
AsyncFile file,
qword offset,
const void * buffer,
unsigned bytes,
unsigned flags,
void * param
) {
// Dereference the object
CFile * object = (CFile *)file;
// Perform synchronous operations immediately
if (flags & kAsyncFileRwSync) {
object->Write(offset, buffer, bytes);
return 0;
}
// Queue asynchronous operations
else {
FileOp * op = NEW(FileOp);
op->code = kNotifyFileWrite;
op->notify = (flags & kAsyncFileRwNotify) != 0;
op->data.write.param = param;
op->data.write.offset = offset;
op->data.write.buffer = (byte *)buffer;
op->data.write.bytes = bytes;
return object->Queue(op);
}
}
//============================================================================
bool W9xFileSeek (
AsyncFile file,
qword distance,
EFileSeekFrom from
) {
CFile * object = (CFile *)file;
return object->Seek(distance, from);
}
} // namespace W9x

View File

@ -0,0 +1,197 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xInt.h
*
***/
#ifdef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_W9X_PNACEW9XINT_H
#error "Header $/Plasma20/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xInt.h included more than once"
#endif
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNASYNCCOREEXE_PRIVATE_W9X_PNACEW9XINT_H
namespace W9x {
/*****************************************************************************
*
* Internal types
*
***/
class CThreadDispObject : public AtomicRef {
public:
CThreadDispObject ();
virtual ~CThreadDispObject () { }
void Close ();
virtual void Complete (void * op, CCritSect * critSect, AsyncId asyncId) = 0;
virtual void Delete (void * op) = 0;
AsyncId Queue (void * op);
};
/*****************************************************************************
*
* W9x internal async API
*
***/
void W9xThreadInitialize ();
void W9xThreadDestroy (unsigned exitThreadWaitMs);
void W9xThreadSignalShutdown ();
void W9xThreadWaitForShutdown ();
void W9xThreadSleep (unsigned sleepMs);
bool W9xThreadWaitId (
AsyncFile file,
AsyncId asyncId,
unsigned timeoutMs
);
AsyncFile W9xFileOpen (
const wchar fullPath[],
FAsyncNotifyFileProc notifyProc,
EFileError * error,
unsigned desiredAccess,
unsigned openMode,
unsigned shareModeFlags,
void * userState,
qword * fileSize,
qword * fileLastWriteTime
);
void W9xFileClose (
AsyncFile file,
qword truncateSize
);
void W9xFileSetLastWriteTime (
AsyncFile file,
qword lastWriteTime
);
qword W9xFileGetLastWriteTime (
const wchar fileName[]
);
AsyncId W9xFileFlushBuffers (
AsyncFile file,
qword truncateSize,
bool notify,
void * param
);
AsyncId W9xFileRead (
AsyncFile file,
qword offset,
void * buffer,
unsigned bytes,
unsigned flags,
void * param
);
AsyncId W9xFileWrite (
AsyncFile file,
qword offset,
const void *buffer,
unsigned bytes,
unsigned flags,
void * param
);
AsyncId W9xFileCreateSequence (
AsyncFile file,
bool notify,
void * param
);
bool W9xFileSeek (
AsyncFile file,
qword distance,
EFileSeekFrom from
);
void W9xSocketConnect (
AsyncCancelId * cancelId,
const NetAddress & netAddr,
FAsyncNotifySocketProc notifyProc,
void * param,
const void * sendData,
unsigned sendBytes,
unsigned connectMs,
unsigned localPort
);
void W9xSocketConnectCancel (
FAsyncNotifySocketProc notifyProc,
AsyncCancelId cancelId
);
void W9xSocketDisconnect (
AsyncSocket sock,
bool hardClose
);
void W9xSocketDelete (AsyncSocket sock);
void W9xSocketDestroy ();
bool W9xSocketSend (
AsyncSocket sock,
const void * data,
unsigned bytes
);
bool W9xSocketWrite (
AsyncSocket sock,
const void * buffer,
unsigned bytes,
void * param
);
void W9xSocketSetNotifyProc (
AsyncSocket sock,
FAsyncNotifySocketProc notifyProc
);
void W9xSocketSetBacklogAlloc (
AsyncSocket sock,
unsigned bufferSize
);
unsigned W9xSocketStartListening (
const NetAddress & listenAddr,
FAsyncNotifySocketProc notifyProc
);
void W9xSocketStopListening (
const NetAddress & listenAddr,
FAsyncNotifySocketProc notifyProc
);
void W9xSocketEnableNagling (
AsyncSocket conn,
bool enable
);
} // namespace W9x

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,453 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xThread.cpp
*
***/
#include "../../Pch.h"
#pragma hdrstop
#include "pnAceW9xInt.h"
namespace W9x {
/*****************************************************************************
*
* Private data
*
***/
const unsigned kThreadCount = 2;
static CCritSect s_critSect;
static bool s_destroying;
static HANDLE s_destroyEvent;
static unsigned s_sequence;
static HANDLE s_shutdownEvent;
static HANDLE s_signalEvent;
static HANDLE s_thread[kThreadCount];
/****************************************************************************
*
* ThreadWaitRec
*
***/
struct ThreadWaitRec {
HANDLE event;
LINK(ThreadWaitRec) link;
};
/****************************************************************************
*
* CThreadDispRec
*
***/
class CThreadDispRec {
private:
CThreadDispObject * m_object;
void * m_op;
AsyncId m_ioId;
LISTDECL(ThreadWaitRec, link) m_waitList;
public:
LINK(CThreadDispRec) m_link;
CThreadDispRec (
CThreadDispObject * object,
void * op,
AsyncId * asyncId
);
~CThreadDispRec ();
void Complete (CCritSect * critSect);
AsyncId GetId () const { return m_ioId; }
void LinkWait (ThreadWaitRec * wait);
};
static LISTDECL(CThreadDispRec, m_link) s_dispList;
static LISTDECL(CThreadDispRec, m_link) s_dispInProcList;
//===========================================================================
CThreadDispRec::CThreadDispRec (
CThreadDispObject * object,
void * op,
AsyncId * asyncId
) :
m_object(object),
m_op(op)
{
s_critSect.Enter();
// Verify that this module is not being destroyed
ASSERT(!s_destroying);
// Increment the owning object's reference count
object->IncRef();
// Assign an id
m_ioId = (AsyncId)++s_sequence;
if (!m_ioId)
m_ioId = (AsyncId)++s_sequence;
*asyncId = m_ioId;
// Link this record to the dispatch list
s_dispList.Link(this);
s_critSect.Leave();
}
//===========================================================================
CThreadDispRec::~CThreadDispRec () {
// Delete the operation data
CThreadDispObject * object = m_object;
object->Delete(m_op);
s_critSect.Enter();
// Unlink this record
m_link.Unlink();
// Wake up all threads blocking on this operation. We must unlink each
// wait record before we signal it.
for (ThreadWaitRec * rec; (rec = m_waitList.Head()) != nil; ) {
m_waitList.Unlink(rec);
SetEvent(rec->event);
}
// Decrement the owning object's reference count
object->DecRef();
s_critSect.Leave();
}
//===========================================================================
void CThreadDispRec::Complete (CCritSect * critSect) {
m_object->Complete(m_op, critSect, m_ioId);
}
//===========================================================================
void CThreadDispRec::LinkWait (ThreadWaitRec * wait) {
// The caller should have already claimed the critical section before
// calling this function
m_waitList.Link(wait);
}
/****************************************************************************
*
* CThreadDispObject
*
***/
//===========================================================================
CThreadDispObject::CThreadDispObject () {
IncRef();
}
//===========================================================================
void CThreadDispObject::Close () {
s_critSect.Enter();
DecRef();
s_critSect.Leave();
}
//===========================================================================
AsyncId CThreadDispObject::Queue (void * op) {
AsyncId asyncId = 0;
NEW(CThreadDispRec)(this, op, &asyncId);
SetEvent(s_signalEvent);
return asyncId;
}
/****************************************************************************
*
* Thread procedure
*
***/
//===========================================================================
static unsigned CALLBACK W9xThreadProc (AsyncThread *) {
// Perform the main thread loop
for (;;) {
unsigned timeout = (unsigned)-1;
// If an operation is queued, complete it and dispatch a notification.
// The code that processes the operation is responsible for leaving
// our critical section. This ensures that operations are completed
// in order.
s_critSect.Enter();
CThreadDispRec * rec = s_dispList.Head();
if (rec) {
s_dispInProcList.Link(rec);
rec->Complete(&s_critSect);
DEL(rec);
timeout = 0;
}
else {
s_critSect.Leave();
}
// Consume events, check for destruction, and block if we have
// nothing to do.
HANDLE events[] = {s_destroyEvent, s_signalEvent};
dword result = WaitForMultipleObjects(
arrsize(events),
events,
FALSE,
INFINITE
);
if (result == WAIT_OBJECT_0)
return 0;
}
}
/****************************************************************************
*
* Exported functions
*
***/
//===========================================================================
void W9xThreadDestroy (
unsigned exitThreadWaitMs
) {
// Wait until all outstanding I/O is complete. We allow new I/O
// operations to be queued while old ones are completing.
s_critSect.Enter();
while (s_dispList.Head() || s_dispInProcList.Head()) {
s_critSect.Leave();
Sleep(10);
s_critSect.Enter();
}
// Once all I/O operations are complete, we disallow any future
// I/O operations from being queued.
s_destroying = true;
s_critSect.Leave();
// Signal thread destruction
if (s_destroyEvent)
SetEvent(s_destroyEvent);
// Wait for thread destruction
for (unsigned thread = kThreadCount; thread--; )
if (s_thread[thread]) {
// Wait for the thread to terminate
WaitForSingleObject(s_thread[thread], exitThreadWaitMs);
// Close the thread handle
CloseHandle(s_thread[thread]);
s_thread[thread] = 0;
}
// Destroy internal modules
W9xSocketDestroy();
// Destroy events
if (s_destroyEvent) {
CloseHandle(s_destroyEvent);
s_destroyEvent = 0;
}
if (s_shutdownEvent) {
CloseHandle(s_shutdownEvent);
s_shutdownEvent = 0;
}
if (s_signalEvent) {
CloseHandle(s_signalEvent);
s_signalEvent = 0;
}
}
//===========================================================================
void W9xThreadInitialize () {
// Reset static variables
s_destroying = false;
// Create a manual reset event to use for signaling thread destruction
if (s_destroyEvent)
ResetEvent(s_destroyEvent);
else {
s_destroyEvent = CreateEvent(nil, TRUE, FALSE, nil);
ASSERT(s_destroyEvent);
}
// Create an auto-reset event to use for signaling the thread to process
// notifications
if (!s_signalEvent) {
s_signalEvent = CreateEvent(nil, FALSE, FALSE, nil);
ASSERT(s_signalEvent);
}
// Create a manual reset event to use for signaling application shutdown
if (s_shutdownEvent)
ResetEvent(s_shutdownEvent);
else {
s_shutdownEvent = CreateEvent(nil, TRUE, FALSE, nil);
ASSERT(s_shutdownEvent);
}
// Create threads
for (unsigned thread = 0; thread < kThreadCount; ++thread) {
if (!s_thread[thread]) {
s_thread[thread] = (HANDLE) AsyncThreadCreate(
W9xThreadProc,
(void *) thread,
L"W9xWorkerThread"
);
}
}
}
//===========================================================================
void W9xThreadSignalShutdown () {
SetEvent(s_shutdownEvent);
}
//===========================================================================
void W9xThreadSleep (
unsigned sleepMs
) {
Sleep(sleepMs);
}
//===========================================================================
void W9xThreadWaitForShutdown () {
// We know that the applicaton is finished initializing at this point.
// While it was still initializing, it may have returned an infinite
// sleep time from the idle procedure, which would prevent us from ever
// calling it again. Therefore, we trigger an idle callback here.
SetEvent(s_signalEvent);
// Wait for the application to signal shutdown
WaitForSingleObject(s_shutdownEvent, INFINITE);
}
//===========================================================================
bool W9xThreadWaitId (
AsyncFile file,
AsyncId asyncId,
unsigned timeoutMs
) {
REF(file);
// Find a pending I/O operation with the given id
s_critSect.Enter();
CThreadDispRec * disp;
for (disp = s_dispList.Head(); disp && (disp->GetId() != asyncId); disp = s_dispList.Next(disp))
;
if (!disp)
for (disp = s_dispInProcList.Head(); disp && (disp->GetId() != asyncId); disp = s_dispInProcList.Next(disp))
;
// If we couldn't find the given id, the operation must have already
// completed, so return true.
if (!disp) {
s_critSect.Leave();
return true;
}
// The operation has not completed. If the timeout is zero, return
// false.
if (!timeoutMs) {
s_critSect.Leave();
return false;
}
// Create a wait event
HANDLE event = CreateEvent(nil, FALSE, FALSE, nil);
// Create a wait record and link it to the I/O operation
ThreadWaitRec wait;
wait.event = event;
disp->LinkWait(&wait);
s_critSect.Leave();
// Wait for the operation to complete
DWORD result = WaitForSingleObject(event, timeoutMs);
// If the operation completed then the dispatcher unlinked our wait
// record before signaling it. We can simply free the event and return.
if (result == WAIT_OBJECT_0) {
CloseHandle(event);
return true;
}
// Unlink our wait record from the I/O operation
s_critSect.Enter();
wait.link.Unlink();
s_critSect.Leave();
// Free the event
CloseHandle(event);
// Return false, because the operation did not complete during the
// timeout period
return false;
}
} // namespace W9x