Tried to make the ServerApp aware when a client dies: the main communication

port is now transferred to the client, so that it goes away automatically.
Unfortunately, this doesn't seem to work. This code is truly a big mess :-/


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12846 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-05-26 15:06:31 +00:00
parent 280d1aac5b
commit d7c08b7d2e
2 changed files with 53 additions and 42 deletions
+21 -21
View File
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copyright (c) 2001-2002, Haiku, Inc. // Copyright (c) 2001-2005, Haiku, Inc.
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
@@ -524,10 +524,10 @@ void AppServer::InitDecorators(void)
\param buffer Attachment buffer for the message. \param buffer Attachment buffer for the message.
*/ */
void AppServer::DispatchMessage(int32 code, BPortLink &msg) void
{ AppServer::DispatchMessage(int32 code, BPortLink &msg)
switch(code)
{ {
switch (code) {
case AS_CREATE_APP: case AS_CREATE_APP:
{ {
// Create the ServerApp to node monitor a new BApplication // Create the ServerApp to node monitor a new BApplication
@@ -552,22 +552,27 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg)
msg.Read<int32>(&htoken); msg.Read<int32>(&htoken);
msg.ReadString(&app_signature); msg.ReadString(&app_signature);
// Create the ServerApp subthread for this app
acquire_sem(fAppListLock);
port_id server_listen = create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature); port_id server_listen = create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature);
if(server_listen<B_OK) if (server_listen < B_OK) {
{
release_sem(fAppListLock);
printf("No more ports left. Time to crash. Have a nice day! :)\n"); printf("No more ports left. Time to crash. Have a nice day! :)\n");
break; break;
} }
ServerApp *newapp=NULL;
newapp= new ServerApp(app_port,server_listen, clientLooperPort, clientTeamID, // we let the application own the port, so that we get aware when it's gone
htoken, app_signature); if (set_port_owner(server_listen, clientTeamID) < B_OK) {
delete_port(server_listen);
printf("Could not transfer port ownership to client %ld!\n", clientTeamID);
break;
}
// Create the ServerApp subthread for this app
acquire_sem(fAppListLock);
ServerApp *app = new ServerApp(app_port,server_listen, clientLooperPort,
clientTeamID, htoken, app_signature);
// add the new ServerApp to the known list of ServerApps // add the new ServerApp to the known list of ServerApps
fAppList->AddItem(newapp); fAppList->AddItem(app);
release_sem(fAppListLock); release_sem(fAppListLock);
@@ -577,9 +582,7 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg)
replylink.Flush(); replylink.Flush();
// This is necessary because BPortLink::ReadString allocates memory // This is necessary because BPortLink::ReadString allocates memory
if(app_signature)
free(app_signature); free(app_signature);
break; break;
} }
case AS_DELETE_APP: case AS_DELETE_APP:
@@ -590,9 +593,7 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg)
// Attached Data: // Attached Data:
// 1) thread_id - thread ID of the ServerApp to be deleted // 1) thread_id - thread ID of the ServerApp to be deleted
int32 i=0, int32 i = 0, appnum = fAppList->CountItems();
appnum=fAppList->CountItems();
ServerApp *srvapp = NULL; ServerApp *srvapp = NULL;
thread_id srvapp_id = -1; thread_id srvapp_id = -1;
@@ -602,8 +603,7 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg)
acquire_sem(fAppListLock); acquire_sem(fAppListLock);
// Run through the list of apps and nuke the proper one // Run through the list of apps and nuke the proper one
for(i= 0; i < appnum; i++) for (i = 0; i < appnum; i++) {
{
srvapp = (ServerApp *)fAppList->ItemAt(i); srvapp = (ServerApp *)fAppList->ItemAt(i);
if(srvapp != NULL && srvapp->MonitorThreadID() == srvapp_id) if(srvapp != NULL && srvapp->MonitorThreadID() == srvapp_id)
+11
View File
@@ -306,6 +306,17 @@ ServerApp::MonitorApp(void *data)
err = msgqueue.GetNextMessage(&code); err = msgqueue.GetNextMessage(&code);
if (err < B_OK) { if (err < B_OK) {
STRACE(("ServerApp::MonitorApp(): GetNextMessage returned %s\n", strerror(err))); STRACE(("ServerApp::MonitorApp(): GetNextMessage returned %s\n", strerror(err)));
// ToDo: this should kill the app, but it doesn't work
port_id serverport = find_port(SERVER_PORT_NAME);
if (serverport == B_NAME_NOT_FOUND){
printf("PANIC: ServerApp %s could not find the app_server port!\n",app->fSignature.String());
break;
}
app->fMsgSender->SetPort(serverport);
app->fMsgSender->StartMessage(AS_DELETE_APP);
app->fMsgSender->Attach(&app->fMonitorThreadID, sizeof(thread_id));
app->fMsgSender->Flush();
break; break;
} }