FTPServerTools
05-20-2003, 02:46 AM
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.
iPos=0;
.....
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);
Users++;
}
// Unlock data
((BOOL (WINAPI *)(LPVOID))Unlock)((LPVOID *)Static);
iPos = nPos;
}
...
iPos=0;
.....
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);
Users++;
}
// Unlock data
((BOOL (WINAPI *)(LPVOID))Unlock)((LPVOID *)Static);
iPos = nPos;
}
...