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
+36 -36
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
// 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.
*/
void AppServer::DispatchMessage(int32 code, BPortLink &msg)
void
AppServer::DispatchMessage(int32 code, BPortLink &msg)
{
switch(code)
{
switch (code) {
case AS_CREATE_APP:
{
// Create the ServerApp to node monitor a new BApplication
@@ -540,35 +540,40 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg)
// 4) char * - signature of the regular app
// Find the necessary data
team_id clientTeamID=-1;
port_id clientLooperPort=-1;
port_id app_port=-1;
int32 htoken=B_NULL_TOKEN;
char *app_signature=NULL;
team_id clientTeamID = -1;
port_id clientLooperPort = -1;
port_id app_port = -1;
int32 htoken = B_NULL_TOKEN;
char *app_signature = NULL;
msg.Read<port_id>(&app_port);
msg.Read<port_id>(&clientLooperPort);
msg.Read<team_id>(&clientTeamID);
msg.Read<int32>(&htoken);
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);
if(server_listen<B_OK)
{
release_sem(fAppListLock);
port_id server_listen = create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature);
if (server_listen < B_OK) {
printf("No more ports left. Time to crash. Have a nice day! :)\n");
break;
}
ServerApp *newapp=NULL;
newapp= new ServerApp(app_port,server_listen, clientLooperPort, clientTeamID,
htoken, app_signature);
// we let the application own the port, so that we get aware when it's gone
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
fAppList->AddItem(newapp);
fAppList->AddItem(app);
release_sem(fAppListLock);
BPortLink replylink(app_port);
@@ -577,34 +582,29 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg)
replylink.Flush();
// This is necessary because BPortLink::ReadString allocates memory
if(app_signature)
free(app_signature);
free(app_signature);
break;
}
case AS_DELETE_APP:
{
// Delete a ServerApp. Received only from the respective ServerApp when a
// BApplication asks it to quit.
// Attached Data:
// 1) thread_id - thread ID of the ServerApp to be deleted
int32 i=0,
appnum=fAppList->CountItems();
ServerApp *srvapp=NULL;
thread_id srvapp_id=-1;
if(msg.Read<thread_id>(&srvapp_id)<B_OK)
int32 i = 0, appnum = fAppList->CountItems();
ServerApp *srvapp = NULL;
thread_id srvapp_id = -1;
if (msg.Read<thread_id>(&srvapp_id) < B_OK)
break;
acquire_sem(fAppListLock);
// Run through the list of apps and nuke the proper one
for(i= 0; i < appnum; i++)
{
srvapp=(ServerApp *)fAppList->ItemAt(i);
for (i = 0; i < appnum; i++) {
srvapp = (ServerApp *)fAppList->ItemAt(i);
if(srvapp != NULL && srvapp->MonitorThreadID() == srvapp_id)
{
+17 -6
View File
@@ -86,7 +86,7 @@
MIME fSignature.
*/
ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort,
team_id clientTeamID, int32 handlerID, const char* signature)
team_id clientTeamID, int32 handlerID, const char* signature)
:
fClientAppPort(sendport),
fMessagePort(rcvport),
@@ -109,18 +109,18 @@ ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort
{
if (fSignature == "")
fSignature = "application/x-vnd.NULL-application-signature";
// although this isn't pretty, ATM we have only one RootLayer.
// there should be a way that this ServerApp be attached to a particular
// RootLayer to know which RootLayer's cursor to modify.
ServerCursor *defaultCursor =
desktop->ActiveRootLayer()->GetCursorManager().GetCursor(B_CURSOR_DEFAULT);
if (defaultCursor) {
fAppCursor = new ServerCursor(defaultCursor);
fAppCursor->SetOwningTeam(fClientTeamID);
}
// fLockSem = create_sem(1, "ServerApp sem");
Run();
@@ -301,15 +301,26 @@ ServerApp::MonitorApp(void *data)
int32 code;
status_t err = B_OK;
while(!app->fQuitting) {
while (!app->fQuitting) {
STRACE(("info: ServerApp::MonitorApp listening on port %ld.\n", app->fMessagePort));
err = msgqueue.GetNextMessage(&code);
if (err < B_OK) {
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;
}
switch(code) {
switch (code) {
case AS_CREATE_WINDOW:
{
// Create the ServerWindow to node monitor a new OBWindow