posting disconnect events if connection broken/closed

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1911 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 16 years ago
parent f12b2c145b
commit 41807f1ea7

@ -78,6 +78,8 @@ int JsonRPCServerModule::load() {
void JsonRPCServerModule::invoke(const string& method,
const AmArg& args, AmArg& ret) {
if (method == "execRpc"){
// todo: add connection id
args.assertArrayFmt("sssisis"); // evq_link, notificationReceiver, requestReceiver,
// flags(i), host, port (i), method, [params]
if (args.size() > 7) {

@ -92,4 +92,19 @@ struct JsonRpcRequestEvent
bool isNotification() { return id.empty(); }
};
struct JsonRpcConnectionEvent
: public JsonRpcEvent {
// todo: add connection id
enum {
DISCONNECT = 0
};
int what;
JsonRpcConnectionEvent(int what)
: what(what) { }
~JsonRpcConnectionEvent() { }
};
#endif // _JsonRPCEvents_h_

@ -28,6 +28,9 @@
#include "RpcServerLoop.h"
#include "JsonRPCServer.h"
#include "JsonRPC.h"
#include "JsonRPCEvents.h"
#include "AmEventDispatcher.h"
#include "log.h"
@ -101,8 +104,24 @@ static void read_cb(struct ev_loop *loop, struct ev_io *w, int revents) {
switch (res) {
case JsonrpcNetstringsConnection::CONTINUE:
ev_io_start(loop,&cli->ev_read); return;
case JsonrpcNetstringsConnection::REMOVE:
ev_io_stop(EV_A_ w); delete cli; return;
case JsonrpcNetstringsConnection::REMOVE: {
ev_io_stop(EV_A_ w);
// let event receivers know about broken connection
// todo: add connection id
if (!cli->notificationReceiver.empty())
AmEventDispatcher::instance()->post(cli->notificationReceiver,
new JsonRpcConnectionEvent(JsonRpcConnectionEvent::DISCONNECT));
if (!cli->requestReceiver.empty())
AmEventDispatcher::instance()->post(cli->requestReceiver,
new JsonRpcConnectionEvent(JsonRpcConnectionEvent::DISCONNECT));
for (std::map<std::string, std::string>::iterator it=
cli->replyReceivers.begin(); it != cli->replyReceivers.end(); it++) {
AmEventDispatcher::instance()->post(it->second,
new JsonRpcConnectionEvent(JsonRpcConnectionEvent::DISCONNECT));
}
delete cli;
} return;
case JsonrpcNetstringsConnection::DISPATCH: {
ev_io_stop(EV_A_ w);
JsonRPCServerLoop::dispatchServerEvent(new JsonServerEvent(cli));

Loading…
Cancel
Save