Make the server a BApplication for a smoother shutdown (I've never
experienced this problem, but others have). Original changes by Axel, though edited quite a bit by myself. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10337 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <Application.h>
|
||||
#include <Autolock.h>
|
||||
#include <Message.h>
|
||||
#include <NodeMonitor.h>
|
||||
@@ -543,6 +544,7 @@ NodeMonitor::NodeMonitor()
|
||||
// destructor
|
||||
NodeMonitor::~NodeMonitor()
|
||||
{
|
||||
delete_sem(fMessageCountSem);
|
||||
}
|
||||
|
||||
// Init
|
||||
@@ -779,9 +781,10 @@ NodeManager::~NodeManager()
|
||||
fNodeMonitor->Lock();
|
||||
fNodeMonitor->Quit();
|
||||
}
|
||||
|
||||
if (fNodeMonitoringProcessor >= 0) {
|
||||
int32 result;
|
||||
wait_for_thread(fNodeMonitoringProcessor, &result);
|
||||
status_t status;
|
||||
wait_for_thread(fNodeMonitoringProcessor, &status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1350,10 +1353,12 @@ DBG(OUT(" -> entryCount: %ld, error: `%s'\n", reply->entryCount, strerror(reply
|
||||
return error;
|
||||
}
|
||||
|
||||
// main
|
||||
int
|
||||
main()
|
||||
// request_loop
|
||||
int32
|
||||
request_loop(void *data)
|
||||
{
|
||||
port_id requestPort = *(port_id*)data;
|
||||
|
||||
// init node manager
|
||||
status_t error = NodeManager::GetDefault()->Init();
|
||||
if (error != B_OK) {
|
||||
@@ -1361,15 +1366,9 @@ main()
|
||||
return 1;
|
||||
}
|
||||
|
||||
// create the request port
|
||||
port_id port = create_port(1, STAT_CACHE_SERVER_PORT_NAME);
|
||||
if (port < 0) {
|
||||
fprintf(stderr, "Failed to create request port: %s\n", strerror(port));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// handle requests until our port goes away
|
||||
stat_cache_request request;
|
||||
while (read_request(port, request) == B_OK) {
|
||||
while (read_request(requestPort, request) == B_OK) {
|
||||
BAutolock _(NodeManager::GetDefault());
|
||||
switch (request.command) {
|
||||
case STAT_CACHE_COMMAND_STAT:
|
||||
@@ -1385,6 +1384,39 @@ main()
|
||||
}
|
||||
|
||||
// delete the request port
|
||||
delete_port(port);
|
||||
if (delete_port(requestPort) == B_OK)
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// main
|
||||
int
|
||||
main()
|
||||
{
|
||||
// create the request port
|
||||
port_id requestPort = create_port(1, STAT_CACHE_SERVER_PORT_NAME);
|
||||
if (requestPort < 0) {
|
||||
fprintf(stderr, "Failed to create request port: %s\n",
|
||||
strerror(requestPort));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// start the request handling loop
|
||||
thread_id requestLoop = spawn_thread(request_loop, "request loop",
|
||||
B_NORMAL_PRIORITY, &requestPort);
|
||||
if (resume_thread(requestLoop) < B_OK)
|
||||
return -1;
|
||||
|
||||
// the BApplication is only needed for a smooth server shutdown
|
||||
BApplication app("application/x-vnd.haiku.jam-cacheserver");
|
||||
app.Run();
|
||||
|
||||
// delete the request port
|
||||
delete_port(requestPort);
|
||||
|
||||
// wait for the request handling loop to quit
|
||||
status_t result;
|
||||
wait_for_thread(requestLoop, &result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
|
||||
resource(1, "BEOS:APP_SIG") #'MIMS' "application/x-vnd.haiku.jam-cacheserver";
|
||||
|
||||
resource(1, "BEOS:FILE_TYPES") message
|
||||
{
|
||||
"types" = "application/octet-stream"
|
||||
};
|
||||
|
||||
resource app_version
|
||||
{
|
||||
major = 1,
|
||||
middle = 0,
|
||||
minor = 0,
|
||||
|
||||
/* 0 = development 1 = alpha 2 = beta
|
||||
3 = gamma 4 = golden master 5 = final */
|
||||
variety = 5,
|
||||
internal = 1,
|
||||
|
||||
short_info = "StatCacheServer",
|
||||
long_info = "StatCacheServer 1.0.0 for Jam ©2004 Haiku"
|
||||
};
|
||||
|
||||
resource(1, "BEOS:APP_FLAGS") #'APPF' $"04000000";
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <string>
|
||||
|
||||
#include <Entry.h>
|
||||
#include <Locker.h>
|
||||
#include <Looper.h>
|
||||
#include <MessageQueue.h>
|
||||
#include <Node.h>
|
||||
#include <OS.h>
|
||||
|
||||
Reference in New Issue
Block a user