Rev 98: merge from ronnie in http://samba.org/~tridge/ctdb
tridge at samba.org
tridge at samba.org
Thu Apr 12 00:44:18 GMT 2007
------------------------------------------------------------
revno: 98
revision-id: tridge at samba.org-20070412004418-85381cc96b73ebe8
parent: tridge at samba.org-20070411122143-e0d0192ca901c6f9
parent: ronniesahlberg at gmail.com-20070411230927-88foctkqh1hqr8ab
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Thu 2007-04-12 10:44:18 +1000
message:
merge from ronnie
modified:
direct/ctdbd.c ctdbd.c-20070411085044-dqmhr6mfeexnyt4m-1
direct/ctdbd_test.c ctdbd_test.c-20070411085057-17kgjzfktsh28g99-1
tests/ctdb_messaging.c ctdb_messaging.c-20070411034205-6d6vne56pbih2x1p-1
------------------------------------------------------------
merged: ronniesahlberg at gmail.com-20070411230927-88foctkqh1hqr8ab
parent: ronniesahlberg at gmail.com-20070411224415-ix25hyi4thd8ydoe
committer: Ronnie sahlberg <ronniesahlberg at gmail.com>
branch nick: ctdb
timestamp: Thu 2007-04-12 09:09:27 +1000
message:
add an example on how to read a message from the domain socket
------------------------------------------------------------
merged: ronniesahlberg at gmail.com-20070411224415-ix25hyi4thd8ydoe
parent: ronniesahlberg at gmail.com-20070411222854-5k8oj8f10kqzasro
committer: Ronnie sahlberg <ronniesahlberg at gmail.com>
branch nick: ctdb
timestamp: Thu 2007-04-12 08:44:15 +1000
message:
do an infinite loop calling event_loop_once() in the ctdbd parent process instead of event_loop_wait() since the latter will return and thus take down the daemon
------------------------------------------------------------
merged: ronniesahlberg at gmail.com-20070411222854-5k8oj8f10kqzasro
parent: ronniesahlberg at gmail.com-20070411214928-pizt3e0yiw8ehql2
committer: Ronnie sahlberg <ronniesahlberg at gmail.com>
branch nick: ctdb
timestamp: Thu 2007-04-12 08:28:54 +1000
message:
add a test message to the messaging test so we can see that the message data is also passed from originator to receiver
------------------------------------------------------------
merged: ronniesahlberg at gmail.com-20070411214928-pizt3e0yiw8ehql2
parent: ronniesahlberg at gmail.com-20070411103224-hvqzewjcfhpxcgbg
parent: tridge at samba.org-20070411122143-e0d0192ca901c6f9
committer: Ronnie sahlberg <ronniesahlberg at gmail.com>
branch nick: ctdb
timestamp: Thu 2007-04-12 07:49:28 +1000
message:
merge from ridge and vl
=== modified file 'direct/ctdbd.c'
--- a/direct/ctdbd.c 2007-04-11 12:21:43 +0000
+++ b/direct/ctdbd.c 2007-04-11 22:44:15 +0000
@@ -129,8 +129,11 @@
/* start the protocol running */
ret = ctdb_start(ctdb);
- event_loop_wait(ev);
-
+/* event_loop_wait(ev);*/
+ while (1) {
+ event_loop_once(ev);
+ }
+
/* shut it down */
talloc_free(ev);
return 0;
=== modified file 'direct/ctdbd_test.c'
--- a/direct/ctdbd_test.c 2007-04-11 10:32:24 +0000
+++ b/direct/ctdbd_test.c 2007-04-11 23:09:27 +0000
@@ -130,8 +130,38 @@
cnt=write(fd, &r, offsetof(struct ctdb_req_message, data));
/* write data */
if(data.dsize){
- cnt=write(fd, data.dptr, data.dsize);
- }
+ cnt+=write(fd, data.dptr, data.dsize);
+ }
+}
+
+void wait_for_a_message(int fd)
+{
+ int cnt, tot;
+ uint32_t len;
+ struct ctdb_req_message *msg;
+
+ /* read the 4 bytes of length for the pdu */
+ cnt=0;
+ tot=4;
+ while(cnt!=tot){
+ int numread;
+ numread=read(fd, ((char *)&len)+cnt, tot-cnt);
+ if(numread>0){
+ cnt+=numread;
+ }
+ }
+ msg=malloc(len);
+ msg->hdr.length=len;
+ /* read the rest of the pdu */
+ tot=msg->hdr.length;
+ while(cnt!=tot){
+ int numread;
+ numread=read(fd, (char *)msg+cnt, tot-cnt);
+ if(numread>0){
+ cnt+=numread;
+ }
+ }
+ printf("got a message : %s\n",&msg->data[0]);
}
int main(int argc, const char *argv[])
@@ -172,8 +202,10 @@
send_a_message(fd, vnn, dstvnn, dstpid, message);
- /* wait for the message to come back */
-
+ /* wait for the message to come back.
+ i.e. the one we just sent to ourself
+ */
+ wait_for_a_message(fd);
return 0;
}
=== modified file 'tests/ctdb_messaging.c'
--- a/tests/ctdb_messaging.c 2007-04-11 05:23:50 +0000
+++ b/tests/ctdb_messaging.c 2007-04-11 22:28:54 +0000
@@ -36,7 +36,7 @@
static void message_handler(struct ctdb_context *ctdb, uint32_t srvid,
TDB_DATA data, void *private)
{
- printf("client vnn:%d received a message to srvid:%d\n",ctdb_get_vnn(ctdb),srvid);
+ printf("client vnn:%d received a message to srvid:%d [%s]\n",ctdb_get_vnn(ctdb),srvid,data.dptr);
fflush(stdout);
}
@@ -52,6 +52,7 @@
const char *myaddress = NULL;
int self_connect=0;
int daemon_mode=0;
+ char buf[256];
struct poptOption popt_options[] = {
POPT_AUTOHELP
@@ -159,18 +160,19 @@
/* wait until all nodes are connected (should not be needed
outside of test code) */
- data.dptr=NULL;
- data.dsize=0;
ctdb_set_message_handler(ctdb, srvid, message_handler, NULL);
ctdb_connect_wait(ctdb);
- sleep(1);
+ sleep(3);
printf("sending message from vnn:%d to vnn:%d/srvid:%d\n",ctdb_get_vnn(ctdb),ctdb_get_vnn(ctdb), 1-srvid);
for (i=0;i<ctdb_get_num_nodes(ctdb);i++) {
for (j=0;j<num_clients;j++) {
printf("sending message to %d:%d\n", i, j);
+ sprintf(buf,"Message from %d to vnn:%d srvid:%d",ctdb_get_vnn(ctdb),i,j);
+ data.dptr=buf;
+ data.dsize=strlen(buf)+1;
ctdb_send_message(ctdb, i, j, data);
}
}
More information about the samba-cvs
mailing list