diff options
author | Volker Lendecke <vl@samba.org> | 2014-01-08 16:13:11 +0100 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-01-09 14:20:34 -0800 |
commit | 0c2f85a66ca0d971c6008a62c4fa732112638934 (patch) | |
tree | 23587f5059b1e4daf4c48a0bc8344962ea6868c8 /source3/lib/messages.c | |
parent | 46afd9b28df46301703ed4166dd8ba0e41767f5b (diff) | |
download | samba-0c2f85a66ca0d971c6008a62c4fa732112638934.tar.gz samba-0c2f85a66ca0d971c6008a62c4fa732112638934.tar.xz samba-0c2f85a66ca0d971c6008a62c4fa732112638934.zip |
messaging: Move the self-send logic out of messaging_tdb
This is not specific to tdb
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3/lib/messages.c')
-rw-r--r-- | source3/lib/messages.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/source3/lib/messages.c b/source3/lib/messages.c index f4d62279d93..fa3855cae58 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -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) |