summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/include/messages.h1
-rw-r--r--source3/lib/messages.c29
-rw-r--r--source3/utils/msgtest.c24
3 files changed, 50 insertions, 4 deletions
diff --git a/source3/include/messages.h b/source3/include/messages.h
index 6ab21e7433..8433866f9e 100644
--- a/source3/include/messages.h
+++ b/source3/include/messages.h
@@ -25,6 +25,7 @@
/* general messages */
#define MSG_DEBUG 1
#define MSG_PING 2
+#define MSG_PONG 3
/* nmbd messages */
#define MSG_FORCE_ELECTION 1001
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 927cb095dd..939bf36004 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -66,6 +66,14 @@ static void sig_usr1(void)
}
/****************************************************************************
+a useful function for testing the message system
+****************************************************************************/
+void ping_message(int msg_type, pid_t src, void *buf, size_t len)
+{
+ message_send_pid(src, MSG_PONG, buf, len);
+}
+
+/****************************************************************************
Initialise the messaging functions.
****************************************************************************/
BOOL message_init(void)
@@ -83,6 +91,8 @@ BOOL message_init(void)
CatchSignal(SIGUSR1, sig_usr1);
+ message_register(MSG_PING, ping_message);
+
return True;
}
@@ -167,11 +177,11 @@ BOOL message_send_pid(pid_t pid, int msg_type, void *buf, size_t len)
memcpy(p+dbuf.dsize, &rec, sizeof(rec));
if (len > 0) memcpy(p+dbuf.dsize+sizeof(rec), buf, len);
+ free(dbuf.dptr);
dbuf.dptr = p;
dbuf.dsize += len + sizeof(rec);
tdb_store(tdb, kbuf, dbuf, TDB_REPLACE);
free(dbuf.dptr);
- free(p);
ok:
tdb_unlockchain(tdb, kbuf);
@@ -256,6 +266,7 @@ void message_dispatch(void)
dfn->fn(msg_type, src, buf, len);
}
}
+ if (buf) free(buf);
}
}
@@ -277,3 +288,19 @@ void message_register(int msg_type,
DLIST_ADD(dispatch_fns, dfn);
}
+
+/****************************************************************************
+de-register the function for a particular message type
+****************************************************************************/
+void message_deregister(int msg_type)
+{
+ struct dispatch_fns *dfn, *next;
+
+ for (dfn = dispatch_fns; dfn; dfn = next) {
+ next = dfn->next;
+ if (dfn->msg_type == msg_type) {
+ DLIST_REMOVE(dispatch_fns, dfn);
+ free(dfn);
+ }
+ }
+}
diff --git a/source3/utils/msgtest.c b/source3/utils/msgtest.c
index 22d7a9a331..4821aef80b 100644
--- a/source3/utils/msgtest.c
+++ b/source3/utils/msgtest.c
@@ -36,12 +36,21 @@
#include "includes.h"
+static int pong_count;
+
+/****************************************************************************
+a useful function for testing the message system
+****************************************************************************/
+void pong_message(int msg_type, pid_t src, void *buf, size_t len)
+{
+ pong_count++;
+}
int main(int argc, char *argv[])
{
pid_t pid;
- int level;
+ int i, n;
static pstring servicesf = CONFIGFILE;
TimeInit();
@@ -54,9 +63,18 @@
message_init();
pid = atoi(argv[1]);
- level = atoi(argv[2]);
+ n = atoi(argv[2]);
+
+ message_register(MSG_PONG, pong_message);
+
+ for (i=0;i<n;i++) {
+ message_send_pid(pid, MSG_PING, NULL, 0);
+ }
- message_send_pid(pid, MSG_FORCE_ELECTION, NULL, 0);
+ while (pong_count < n) {
+ message_dispatch();
+ msleep(1);
+ }
return (0);
}