From 806767ec21530cfb049592cc24b599e01f88ed09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 6 Jul 2005 22:39:15 +0000 Subject: [PATCH] It now deletes its message port (it was previously incorrectly deleted by the client). Now handles it gracefully if someone deletes its message port (it will try to close the client and quit). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13511 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/ServerWindow.cpp | 49 +++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 65f9f51982..fcc710cef8 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -104,8 +104,9 @@ ServerWindow::~ServerWindow() gDesktop->RemoveWinBorder(fWinBorder); delete fWinBorder; - + free(const_cast(fTitle)); + delete_port(fMessagePort); BPrivate::gDefaultTokens.RemoveToken(fServerToken); @@ -191,6 +192,9 @@ ServerWindow::Quit() } if (fThread == find_thread(NULL)) { + // make sure we're hidden + Hide(); + App()->RemoveWindow(this); delete this; @@ -236,7 +240,11 @@ ServerWindow::Show() if (fQuitting || !fWinBorder->IsHidden()) return; - fWinBorder->GetRootLayer()->ShowWinBorder(fWinBorder); + RootLayer* rootLayer = fWinBorder->GetRootLayer(); + + rootLayer->Lock(); + rootLayer->ShowWinBorder(fWinBorder); + rootLayer->Unlock(); } //! Hides the window's WinBorder @@ -249,7 +257,11 @@ ServerWindow::Hide() if (fWinBorder->IsHidden()) return; - fWinBorder->GetRootLayer()->HideWinBorder(fWinBorder); + RootLayer* rootLayer = fWinBorder->GetRootLayer(); + + rootLayer->Lock(); + rootLayer->HideWinBorder(fWinBorder); + rootLayer->Unlock(); } @@ -2137,20 +2149,21 @@ void ServerWindow::_MessageLooper() { BPrivate::LinkReceiver& receiver = fLink.Receiver(); + bool quitLoop = false; - bool quitting = false; - int32 code; - status_t err = B_OK; - - while (!quitting) { + while (!quitLoop) { STRACE(("info: ServerWindow::MonitorWin listening on port %ld.\n", fMessagePort)); - err = receiver.GetNextMessage(code); - if (err < B_OK) { + int32 code; + status_t status = receiver.GetNextMessage(code); + if (status < B_OK) { // that shouldn't happen, it's our port - // ToDo: do something about it, anyway! - return; + printf("Someone deleted our message port!\n"); + + // try to let our client die happily + NotifyQuitRequested(); + break; } Lock(); @@ -2158,11 +2171,12 @@ ServerWindow::_MessageLooper() switch (code) { case AS_DELETE_WINDOW: case kMsgWindowQuit: - { // this means the client has been killed STRACE(("ServerWindow %s received 'AS_DELETE_WINDOW' message code\n", Title())); + quitLoop = true; + // ToDo: what's this? //RootLayer *rootLayer = fWinBorder->GetRootLayer(); @@ -2180,11 +2194,8 @@ ServerWindow::_MessageLooper() // ServerWindow's destructor takes care of pulling this object off the desktop. if (!fWinBorder->IsHidden()) CRITICAL("ServerWindow: a window must be hidden before it's deleted\n"); - - Quit(); - // does not return break; - } + case B_QUIT_REQUESTED: STRACE(("ServerWindow %s received quit request\n", Title())); NotifyQuitRequested(); @@ -2197,6 +2208,10 @@ ServerWindow::_MessageLooper() Unlock(); } + + // we were asked to quit the message loop - either on request or because of an error + Quit(); + // does not return } /*