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:
@@ -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
|
||||||
@@ -540,35 +540,40 @@ void AppServer::DispatchMessage(int32 code, BPortLink &msg)
|
|||||||
// 4) char * - signature of the regular app
|
// 4) char * - signature of the regular app
|
||||||
|
|
||||||
// Find the necessary data
|
// Find the necessary data
|
||||||
team_id clientTeamID=-1;
|
team_id clientTeamID = -1;
|
||||||
port_id clientLooperPort=-1;
|
port_id clientLooperPort = -1;
|
||||||
port_id app_port=-1;
|
port_id app_port = -1;
|
||||||
int32 htoken=B_NULL_TOKEN;
|
int32 htoken = B_NULL_TOKEN;
|
||||||
char *app_signature=NULL;
|
char *app_signature = NULL;
|
||||||
|
|
||||||
msg.Read<port_id>(&app_port);
|
msg.Read<port_id>(&app_port);
|
||||||
msg.Read<port_id>(&clientLooperPort);
|
msg.Read<port_id>(&clientLooperPort);
|
||||||
msg.Read<team_id>(&clientTeamID);
|
msg.Read<team_id>(&clientTeamID);
|
||||||
msg.Read<int32>(&htoken);
|
msg.Read<int32>(&htoken);
|
||||||
msg.ReadString(&app_signature);
|
msg.ReadString(&app_signature);
|
||||||
|
|
||||||
// Create the ServerApp subthread for this app
|
port_id server_listen = create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature);
|
||||||
acquire_sem(fAppListLock);
|
if (server_listen < B_OK) {
|
||||||
|
|
||||||
port_id server_listen=create_port(DEFAULT_MONITOR_PORT_SIZE, app_signature);
|
|
||||||
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);
|
||||||
|
|
||||||
BPortLink replylink(app_port);
|
BPortLink replylink(app_port);
|
||||||
@@ -577,34 +582,29 @@ 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:
|
||||||
{
|
{
|
||||||
// Delete a ServerApp. Received only from the respective ServerApp when a
|
// Delete a ServerApp. Received only from the respective ServerApp when a
|
||||||
// BApplication asks it to quit.
|
// BApplication asks it to quit.
|
||||||
|
|
||||||
// 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,
|
|
||||||
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;
|
break;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -86,7 +86,7 @@
|
|||||||
MIME fSignature.
|
MIME fSignature.
|
||||||
*/
|
*/
|
||||||
ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort,
|
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),
|
fClientAppPort(sendport),
|
||||||
fMessagePort(rcvport),
|
fMessagePort(rcvport),
|
||||||
@@ -109,18 +109,18 @@ ServerApp::ServerApp(port_id sendport, port_id rcvport, port_id clientLooperPort
|
|||||||
{
|
{
|
||||||
if (fSignature == "")
|
if (fSignature == "")
|
||||||
fSignature = "application/x-vnd.NULL-application-signature";
|
fSignature = "application/x-vnd.NULL-application-signature";
|
||||||
|
|
||||||
// although this isn't pretty, ATM we have only one RootLayer.
|
// although this isn't pretty, ATM we have only one RootLayer.
|
||||||
// there should be a way that this ServerApp be attached to a particular
|
// there should be a way that this ServerApp be attached to a particular
|
||||||
// RootLayer to know which RootLayer's cursor to modify.
|
// RootLayer to know which RootLayer's cursor to modify.
|
||||||
ServerCursor *defaultCursor =
|
ServerCursor *defaultCursor =
|
||||||
desktop->ActiveRootLayer()->GetCursorManager().GetCursor(B_CURSOR_DEFAULT);
|
desktop->ActiveRootLayer()->GetCursorManager().GetCursor(B_CURSOR_DEFAULT);
|
||||||
|
|
||||||
if (defaultCursor) {
|
if (defaultCursor) {
|
||||||
fAppCursor = new ServerCursor(defaultCursor);
|
fAppCursor = new ServerCursor(defaultCursor);
|
||||||
fAppCursor->SetOwningTeam(fClientTeamID);
|
fAppCursor->SetOwningTeam(fClientTeamID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fLockSem = create_sem(1, "ServerApp sem");
|
// fLockSem = create_sem(1, "ServerApp sem");
|
||||||
|
|
||||||
Run();
|
Run();
|
||||||
@@ -301,15 +301,26 @@ ServerApp::MonitorApp(void *data)
|
|||||||
int32 code;
|
int32 code;
|
||||||
status_t err = B_OK;
|
status_t err = B_OK;
|
||||||
|
|
||||||
while(!app->fQuitting) {
|
while (!app->fQuitting) {
|
||||||
STRACE(("info: ServerApp::MonitorApp listening on port %ld.\n", app->fMessagePort));
|
STRACE(("info: ServerApp::MonitorApp listening on port %ld.\n", app->fMessagePort));
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(code) {
|
switch (code) {
|
||||||
case AS_CREATE_WINDOW:
|
case AS_CREATE_WINDOW:
|
||||||
{
|
{
|
||||||
// Create the ServerWindow to node monitor a new OBWindow
|
// Create the ServerWindow to node monitor a new OBWindow
|
||||||
|
|||||||
Reference in New Issue
Block a user