I would like to get system notifications and pass them through http to client.
Now I use node.js to provide these two services in one process, but there is a problem.
The notification listener has its own main loop listening to system events, and when the service is started, it makes the server stop providing http service. I think if I could combine main loops of these two services into one, the problem may be solved. Is this possible? And how could I get start?
Thank you,
Here is the sample code:
var server = require("express").createServer(),
io = require('socket.io').listen(server);
server.listen(8000);
server.get("/", function (req, res) {
res.sendfile("./public/main.html");
});
io.of('/images').on('connection', function (socket) {
//read images and transfer
}
io.of('/notify').on('connection', function (socket) {
//start listen system notifications
notifyLib.start_daemon();
}
“notifyLib.start_daemon()” is a native extension and its code is as follows:
DBusError error;
int rt;
dbus_error_init (&error);
connection = dbus_bus_get (DBUS_BUS_SESSION, &error);
if (dbus_bus_name_has_owner(connection, DBUS_NAME, &error))
printf("*** DBUS_NAME had owner\n");
rt = dbus_bus_request_name (connection, DBUS_NAME, 0, &error);
if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL))
printf("*** Failed to add filter\n");
if (!dbus_connection_register_object_path (connection, DBUS_PATH, &echo_vtable, (void*) 0xdeadbeef))
printf("*** Failed to register object path\n");
while (dbus_connection_read_write_dispatch (connection, -1))
;
dbus_connection_remove_filter (connection, filter_func, NULL);
dbus_connection_unref (connection);
dbus_shutdown ();
There are many images to transfer, but when listener starts, image transfer stops.
Hope I understand your problem.
The most simple solution is use Cluster
Because it fork several process to handle the request.