conga/ricci/modules/cluster/clumon/src/daemon ...
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-10-14 18:00:02
Modified files:
ricci/modules/cluster/clumon/src/daemon: Communicator.cpp
Monitor.cpp Peer.cpp main.cpp
Log message:
modclusterd: exit as soon as possible, after exit signal is caught:
- make all sockets non-blocking
- make long waits interruptible
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/clumon/src/daemon/Communicator.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/clumon/src/daemon/Monitor.cpp.diff?cvsroot=cluster&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/clumon/src/daemon/Peer.cpp.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/cluster/clumon/src/daemon/main.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
ricci/modules/cluster/clumon/src/daemon/Communicator.cpp +3 -1
@@ -55,6 +55,7 @@ _serv_sock(_port), _delivery_point(delivery_point) { + _serv_sock.nonblocking(true); _connect_time = time_sec(); _rand_state = time_mil(); log(String("Communicator created, port ") + _port, LogCommunicator);
@@ -186,7 +187,7 @@ } // process events - for (unsigned int i=0; i<socks_num; i++) { + for (unsigned int i=0; i<socks_num && !shouldStop(); i++) { poll_fd& poll_info = poll_data[i]; // server socket
@@ -194,6 +195,7 @@ if (poll_info.revents & POLLIN) { try { ClientSocket sock = _serv_sock.accept(); + sock.nonblocking(true); String hostname; for (vector<String>::iterator iter = names.begin(); iter != names.end();
ricci/modules/cluster/clumon/src/daemon/Monitor.cpp +6 -2
@@ -132,8 +132,12 @@ log(msg, LogTime); // wait some time - struct pollfd nothing; - poll(¬hing, 0, 5000); + for (int i=0; i<10; i++) { + if (shouldStop()) + break; + struct pollfd nothing; + poll(¬hing, 0, 500); + } } log("Stopping communicator", LogCommunicator); _comm.stop();
ricci/modules/cluster/clumon/src/daemon/Peer.cpp +6 -2
@@ -40,14 +40,18 @@ _hostname(hostname), _in(new String()), _out(new String()) -{} +{ + _sock->nonblocking(true); +} Peer::Peer(const String& hostname, unsigned short port) : _sock(new ClientSocket(hostname, port)), _hostname(hostname), _in(new String()), _out(new String()) -{} +{ + _sock->nonblocking(true); +} Peer::~Peer() {}
ricci/modules/cluster/clumon/src/daemon/main.cpp +6 -2
@@ -102,6 +102,7 @@ log("started"); try { ServerSocket server(MONITORING_CLIENT_SOCKET); + server.nonblocking(true); Monitor monitor(COMMUNICATION_PORT); if (!foreground && (geteuid() == 0))
@@ -169,7 +170,7 @@ } // process events - for (unsigned int i=0; i<socks_num; i++) { + for (unsigned int i=0; i<socks_num && !shutdown_pending; i++) { poll_fd& poll_info = poll_data[i]; // server socket
@@ -177,6 +178,7 @@ if (poll_info.revents & POLLIN) { try { ClientSocket sock = server.accept(); + sock.nonblocking(true); clients[sock.get_sock()] = ClientInfo(sock); } catch ( ... ) {} }
@@ -187,7 +189,9 @@ if (poll_info.revents & POLLIN) { ClientInfo& info = clients[poll_info.fd]; try { - info.str = monitor.request(info.sock.recv()); + String msg = info.sock.recv(); + if (msg.size()) + info.str = monitor.request(msg); } catch ( ... ) { clients.erase(poll_info.fd); }