View Single Post
Old 05-20-2003, 02:46 AM  
Senior Member
Join Date: Sep 2002
Posts: 543
Default Correction in dark0ne's sitewho.cpp

If you start with iPos=0 the following can occur. Suppose I kill connection 0, then when you want to get the WM_WHO_SHARED contents you will see that connection 0 looks to be still alive. There is no immediate possibility to see if the connection is closed or not (unless you check the socket state). The correct way to resolve is that the nPos-1 is always a correct entry that is connected. Thus you shoud use iPos=nPos-1 in your code.

while ((nPos = SendMessage(Target, WM_WHO_SHARED, iPos, Result)) != -1 && iPos + 1 <= nPos && Users < 1000 ){
iPos=nPos-1; //The correction
// Lock data
Static = (STATIC *)((LPVOID (WINAPI *)(HANDLE, DWORD))Lock)(hShared, PID);
if (Static){
printf("%i %i:%i - %s\r\n", nPos - 1, Static->UserFile.uid, Static->UserFile.gid, Static->Action);
// Unlock data
((BOOL (WINAPI *)(LPVOID))Unlock)((LPVOID *)Static);
iPos = nPos;
FTPServerTools is offline