messaging: Move the self-send logic out of messaging_tdb
authorVolker Lendecke <vl@samba.org>
Wed, 8 Jan 2014 15:13:11 +0000 (16:13 +0100)
committerJeremy Allison <jra@samba.org>
Thu, 9 Jan 2014 22:20:34 +0000 (14:20 -0800)
This is not specific to tdb

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/messages.c
source3/lib/messages_local.c

index f4d62279d935cedbb328dc7d941b685b6169d3a8..fa3855cae5818832dc51f00055a748e571509f7a 100644 (file)
@@ -344,6 +344,15 @@ void messaging_deregister(struct messaging_context *ctx, uint32_t msg_type,
        }
 }
 
+struct messaging_selfsend_state {
+       struct messaging_context *msg;
+       struct messaging_rec rec;
+};
+
+static void messaging_trigger_self(struct tevent_context *ev,
+                                  struct tevent_immediate *im,
+                                  void *private_data);
+
 /*
   Send a message to a particular server
 */
@@ -362,10 +371,53 @@ NTSTATUS messaging_send(struct messaging_context *msg_ctx,
                                                msg_ctx->remote);
        }
 #endif
+
+       if (server_id_equal(&msg_ctx->id, &server)) {
+               struct messaging_selfsend_state *state;
+               struct tevent_immediate *im;
+
+               im = tevent_create_immediate(msg_ctx);
+               if (im == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               state = talloc(im, struct messaging_selfsend_state);
+               if (state == NULL) {
+                       TALLOC_FREE(im);
+                       return NT_STATUS_NO_MEMORY;
+               }
+               state->msg = msg_ctx;
+               state->rec.msg_version = MESSAGE_VERSION;
+               state->rec.msg_type = msg_type & MSG_TYPE_MASK;
+               state->rec.dest = server;
+               state->rec.src = msg_ctx->id;
+
+               state->rec.buf = data_blob_talloc(
+                       state, data->data, data->length);
+               if ((state->rec.buf.length != 0) &&
+                   (state->rec.buf.data == NULL)) {
+                       TALLOC_FREE(im);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               tevent_schedule_immediate(im, msg_ctx->event_ctx,
+                                         messaging_trigger_self, state);
+               return NT_STATUS_OK;
+       }
+
        return msg_ctx->local->send_fn(msg_ctx, server, msg_type, data,
                                       msg_ctx->local);
 }
 
+static void messaging_trigger_self(struct tevent_context *ev,
+                                  struct tevent_immediate *im,
+                                  void *private_data)
+{
+       struct messaging_selfsend_state *state = talloc_get_type_abort(
+               private_data, struct messaging_selfsend_state);
+       messaging_dispatch_rec(state->msg, &state->rec);
+}
+
 NTSTATUS messaging_send_buf(struct messaging_context *msg_ctx,
                            struct server_id server, uint32_t msg_type,
                            const uint8_t *buf, size_t len)
index 36a267a1ba92c07e088f21da3ac694c03316bd66..c74c0aa0d0d759092b7dbfcb42dab6fe39588e83 100644 (file)
@@ -354,15 +354,6 @@ static NTSTATUS message_notify(struct server_id procid)
  Send a message to a particular pid.
 ****************************************************************************/
 
-struct messaging_tdb_self_state {
-       struct messaging_context *msg;
-       struct messaging_rec rec;
-};
-
-static void messaging_tdb_trigger_self(struct tevent_context *ev,
-                                      struct tevent_immediate *im,
-                                      void *private_data);
-
 static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
                                   struct server_id pid, int msg_type,
                                   const DATA_BLOB *data,
@@ -389,41 +380,6 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
 
        SMB_ASSERT(procid_to_pid(&pid) > 0);
 
-       if (server_id_equal(&msg_ctx->id, &pid)) {
-               struct messaging_tdb_self_state *state;
-               struct tevent_immediate *im;
-
-               TALLOC_FREE(frame);
-
-               im = tevent_create_immediate(msg_ctx);
-               if (im == NULL) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-
-               state = talloc(im, struct messaging_tdb_self_state);
-               if (state == NULL) {
-                       TALLOC_FREE(im);
-                       return NT_STATUS_NO_MEMORY;
-               }
-               state->msg = msg_ctx;
-               state->rec.msg_version = MESSAGE_VERSION;
-               state->rec.msg_type = msg_type & MSG_TYPE_MASK;
-               state->rec.dest = pid;
-               state->rec.src = msg_ctx->id;
-
-               state->rec.buf = data_blob_talloc(
-                       state, data->data, data->length);
-               if ((state->rec.buf.length != 0) &&
-                   (state->rec.buf.data == NULL)) {
-                       TALLOC_FREE(im);
-                       return NT_STATUS_NO_MEMORY;
-               }
-
-               tevent_schedule_immediate(im, msg_ctx->event_ctx,
-                                         messaging_tdb_trigger_self, state);
-               return NT_STATUS_OK;
-       }
-
        key = message_key_pid(frame, pid);
 
        if (tdb_chainlock(tdb->tdb, key) != 0) {
@@ -481,16 +437,6 @@ static NTSTATUS messaging_tdb_send(struct messaging_context *msg_ctx,
        return status;
 }
 
-static void messaging_tdb_trigger_self(struct tevent_context *ev,
-                                      struct tevent_immediate *im,
-                                      void *private_data)
-{
-       struct messaging_tdb_self_state *state = talloc_get_type_abort(
-               private_data, struct messaging_tdb_self_state);
-       messaging_dispatch_rec(state->msg, &state->rec);
-}
-
-
 /****************************************************************************
  Retrieve all messages for a process.
 ****************************************************************************/