View Single Post
Old 10-17-2003, 10:51 PM  
Mouton
Posse Member
 
Join Date: Dec 2002
Posts: 1,956
Default bad ONLINEDATA usage ?

What's wrong with this code ?
It appears to work correctly, until you try to run multiple threads that does that... Then, it makes io (.14 and probably earlier) crash (probably when 2 threads do that at the exact same time).

I know it's this code that makes it crash cause if i comment the sendmessage, it doesn't crash anymore.

Code:
int iPos = 0, nPos = 0, Users = 0;
while (nPos != -1 && Users < 1000 ) {
	// Initial setup for DC_GET_ONLINEDATA
	lpMessage->dwIdentifier	= DC_GET_ONLINEDATA;
	LPDC_ONLINEDATA pOnlineData = (LPDC_ONLINEDATA)lpMessage->lpContext;
	pOnlineData->iOffset = nPos;
	pOnlineData->dwSharedMemorySize = sizeof(DC_MESSAGE) + sizeof(DC_ONLINEDATA) + (_MAX_PATH + 1) * 2;

	// Send Message
	dwReturn = SendMessage(hIoFTPD, WM_SHMEM, NULL, (LPARAM)hMemory);
	if (!dwReturn) {
		// Wait until processed (5 secs)
		if (WaitForSingleObject(hEvent, 5000) == WAIT_TIMEOUT) break;

		nPos = pOnlineData->iOffset;
		if (iPos>=nPos || nPos == 1024)
			break;

		Users++;
		iPos = nPos;
	}
}
Mouton is offline