Properly stop the pipe server when LyX is quitting

but the answer to a client is still pending.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31212 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Enrico Forestieri 2009-08-23 13:27:08 +00:00
parent ec91bd0465
commit 736d7f82a1

View File

@ -92,6 +92,14 @@ private:
namespace { namespace {
bool closing_ = false;
void closing()
{
closing_ = true;
}
char * errormsg() char * errormsg()
{ {
void * msgbuf; void * msgbuf;
@ -121,6 +129,8 @@ DWORD WINAPI pipeServerWrapper(void * arg)
LyXComm::LyXComm(string const & pip, Server * cli, ClientCallbackfct ccb) LyXComm::LyXComm(string const & pip, Server * cli, ClientCallbackfct ccb)
: pipename_(pip), client_(cli), clientcb_(ccb) : pipename_(pip), client_(cli), clientcb_(ccb)
{ {
// Ask Qt to notify us on quit.
qAddPostRoutine(closing);
ready_ = false; ready_ = false;
openConnection(); openConnection();
} }
@ -185,7 +195,7 @@ bool LyXComm::event(QEvent * e)
BOOL LyXComm::checkStopServerEvent() BOOL LyXComm::checkStopServerEvent()
{ {
return WaitForSingleObject(stopserver_, 0) == WAIT_OBJECT_0; return WaitForSingleObject(stopserver_, 0) == WAIT_OBJECT_0 || closing_;
} }
@ -260,6 +270,9 @@ void LyXComm::emergencyCleanup()
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
if (hpipe != INVALID_HANDLE_VALUE) if (hpipe != INVALID_HANDLE_VALUE)
CloseHandle(hpipe); CloseHandle(hpipe);
ResetEvent(stopserver_);
CloseHandle(stopserver_);
} }
} }
@ -350,13 +363,14 @@ void LyXComm::send(string const & msg)
} }
Sleep(100); Sleep(100);
++count; ++count;
} while (!success && count < 100); } while (!success && count < 100 && !checkStopServerEvent());
if (!success) { if (!success) {
lyxerr << "LyXComm: Error sending message: " << msg lyxerr << "LyXComm: Error sending message: " << msg
<< '\n' << errormsg() << '\n' << errormsg()
<< "\nLyXComm: Resetting connection" << endl; << "\nLyXComm: Resetting connection" << endl;
closeConnection(); closeConnection();
if (!checkStopServerEvent())
openConnection(); openConnection();
} }
} }