From: Ronnie sahlberg Date: Wed, 11 Apr 2007 10:32:24 +0000 (+1000) Subject: add an example on how to send a message to the daemon X-Git-Tag: tevent-0.9.20~348^2~2937^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6e2463e5c79de8bda810cee09107ee53b989f9f8;p=thirdparty%2Fsamba.git add an example on how to send a message to the daemon (send a message to ourself) this unfortunately terminates the ctdb daemon when running but im too tired right now to debug it. checkin so that nothing gets lost overnight. (This used to be ctdb commit 9d8821bfd1456591fb5c31f0c6c3fd63e99dc4fb) --- diff --git a/ctdb/direct/ctdbd_test.c b/ctdb/direct/ctdbd_test.c index 5cf8b002aef..17c8d8f9721 100644 --- a/ctdb/direct/ctdbd_test.c +++ b/ctdb/direct/ctdbd_test.c @@ -110,9 +110,34 @@ int wait_for_cluster(int fd) } +int send_a_message(int fd, int ourvnn, int vnn, int pid, TDB_DATA data) +{ + struct ctdb_req_message r; + int len, cnt; + + len = offsetof(struct ctdb_req_message, data) + data.dsize; + r.hdr.length = len; + r.hdr.ctdb_magic = CTDB_MAGIC; + r.hdr.ctdb_version = CTDB_VERSION; + r.hdr.operation = CTDB_REQ_MESSAGE; + r.hdr.destnode = vnn; + r.hdr.srcnode = ourvnn; + r.hdr.reqid = 0; + r.srvid = pid; + r.datalen = data.dsize; + + /* write header */ + cnt=write(fd, &r, offsetof(struct ctdb_req_message, data)); + /* write data */ + if(data.dsize){ + cnt=write(fd, data.dptr, data.dsize); + } +} + int main(int argc, const char *argv[]) { - int fd, pid, vnn; + int fd, pid, vnn, dstvnn, dstpid; + TDB_DATA message; /* open the socket to talk to the local ctdb daemon */ fd=ux_socket_connect(CTDB_SOCKET); @@ -138,5 +163,17 @@ int main(int argc, const char *argv[]) vnn=wait_for_cluster(fd); printf("our address is vnn:%d pid:%d if someone wants to send us a message!\n",vnn,pid); + + /* send a message to ourself */ + dstvnn=vnn; + dstpid=pid; + message.dptr="Test message"; + message.dsize=strlen(message.dptr)+1; + send_a_message(fd, vnn, dstvnn, dstpid, message); + + + /* wait for the message to come back */ + + return 0; }