1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

- fixed some memory leaks in the messages code

- added a MSG_PING message for performance testing.
This commit is contained in:
Andrew Tridgell 0001-01-01 00:00:00 +00:00
parent f1c49ca7ce
commit e779f834db
3 changed files with 50 additions and 4 deletions

View File

@ -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

View File

@ -65,6 +65,14 @@ static void sig_usr1(void)
sys_select_signal();
}
/****************************************************************************
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.
****************************************************************************/
@ -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);
}
}
}

View File

@ -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_send_pid(pid, MSG_FORCE_ELECTION, NULL, 0);
message_register(MSG_PONG, pong_message);
for (i=0;i<n;i++) {
message_send_pid(pid, MSG_PING, NULL, 0);
}
while (pong_count < n) {
message_dispatch();
msleep(1);
}
return (0);
}