show gow to use _send() _recv() in the example program
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 12 May 2010 02:11:07 +0000 (12:11 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 12 May 2010 02:11:07 +0000 (12:11 +1000)
libctdb/tst.c

index 51829b5f71582bb53fc13ed579279240f00dbe35..8f315caf51eb7bca980aafe56cb3d8b1b01fef2e 100644 (file)
@@ -5,6 +5,11 @@
 #include "lib/tdb/include/tdb.h"
 #include "include/ctdb.h"
 
+void msg_h(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data, void *private_data)
+{
+       printf("Message received on port %d : %s\n", (int)srvid, data.dptr);
+}
+
 
 void rm_cb(int32_t status, int32_t recmaster, void *private_data)
 {
@@ -14,17 +19,45 @@ void rm_cb(int32_t status, int32_t recmaster, void *private_data)
 int main(int argc, char *argv[])
 {
        struct ctdb_context *ctdb_context;
-       struct ctdb_client_control_state *state;
+       ctdb_handle *handle;
        struct pollfd pfd;
+       int ret;
+       TDB_DATA msg;
 
        ctdb_context = ctdb_connect("/tmp/ctdb.socket");
 
 
        pfd.fd = ctdb_get_fd(ctdb_context);
 
-       state = ctdb_getrecmaster_send(ctdb_context, 0, rm_cb, NULL);
+       handle = ctdb_set_message_handler_send(ctdb_context, 55, NULL, msg_h, NULL);
+       if (handle == NULL) {
+               printf("Failed to register message port\n");
+               exit(10);
+       }
+       ret = ctdb_set_message_handler_recv(ctdb_context, ctdb_handle);
+       if (ret != 0) {
+               printf("Failed to receive set_message_handler reply\n");
+               exit(10);
+       }
+
+       msg.dptr="HelloWorld";
+       msg.dsize = strlen(msg.dptr);
+
+       ret = ctdb_send_message(ctdb_context, 0, 55, msg);
+       if (ret != 0) {
+               printf("Failed to send message. Aborting\n");
+               exit(10);
+       }
+
+       handle = ctdb_getrecmaster_send(ctdb_context, 0, rm_cb, NULL);
+       if (handle == NULL) {
+               printf("Failed to send get_recmaster control\n");
+               exit(10);
+       }
+
 
        for (;;) {
+
          pfd.events = ctdb_which_events(ctdb_context);
          if (poll(&pfd, 1, -1) < 0) {
            printf("Poll failed");