DF disappeared exception

develop
Petr Mrázek 2010-03-09 03:30:22 +01:00
parent 36a6f1f0a4
commit 9d7574dafe
3 changed files with 21 additions and 3 deletions

@ -208,6 +208,17 @@ namespace DFHack
return s.str().c_str();
}
};
class DFHACK_EXPORT SHMServerDisappeared : public std::exception
{
public:
SHMServerDisappeared(){}
virtual ~SHMServerDisappeared() throw(){};
virtual const char* what() const throw()
{
return "The server process has disappeared";
}
};
}
}

@ -96,10 +96,16 @@ bool Process::Private::waitWhile (uint32_t state)
{
shmctl(my_shmid, IPC_STAT, &descriptor);
if(descriptor.shm_nattch == 1)// DF crashed?
if(descriptor.shm_nattch == 1)// DF crashed or exited - no way to tell?
{
SHMCMD = CORE_RUNNING;
//detach the shared memory
shmdt(my_shm);
attached = suspended = false;
// we aren't the current process anymore
g_pProcess = NULL;
throw Error::SHMServerDisappeared();
return false;
}
else

@ -118,9 +118,10 @@ bool Process::Private::waitWhile (uint32_t state)
{
if(!isValidSV())// DF not there anymore?
{
SHMCMD = CORE_RUNNING;
attached = suspended = false;
ReleaseMutex(DFCLMutex);
UnmapViewOfFile(my_shm);
throw Error::SHMServerDisappeared();
return false;
}
else