diff options
author | Ronnie sahlberg <ronniesahlberg@gmail.com> | 2007-04-12 09:09:27 +1000 |
---|---|---|
committer | Ronnie sahlberg <ronniesahlberg@gmail.com> | 2007-04-12 09:09:27 +1000 |
commit | 51c660d1a144a5d9d4951df8ede961e493f7550e (patch) | |
tree | 7dd5439a05e3fbf0f1816780bb99408355413e43 /ctdb | |
parent | e18ed8cc846f7b31b48f182b0cc2fc32c5b1cc82 (diff) | |
download | samba-51c660d1a144a5d9d4951df8ede961e493f7550e.tar.gz samba-51c660d1a144a5d9d4951df8ede961e493f7550e.tar.xz samba-51c660d1a144a5d9d4951df8ede961e493f7550e.zip |
add an example on how to read a message from the domain socket
(This used to be ctdb commit 9723828b1562eb6a386eb26e63db3b6617ebb454)
Diffstat (limited to 'ctdb')
-rw-r--r-- | ctdb/direct/ctdbd_test.c | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/ctdb/direct/ctdbd_test.c b/ctdb/direct/ctdbd_test.c index 17c8d8f9721..18cf7d3f84c 100644 --- a/ctdb/direct/ctdbd_test.c +++ b/ctdb/direct/ctdbd_test.c @@ -130,10 +130,40 @@ int send_a_message(int fd, int ourvnn, int vnn, int pid, TDB_DATA data) 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[]) { int fd, pid, vnn, dstvnn, dstpid; @@ -172,8 +202,10 @@ int main(int argc, const char *argv[]) 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; } |