summaryrefslogtreecommitdiffstats
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-04-24 09:23:48 +0000
committerVolker Lendecke <vl@samba.org>2014-05-08 09:10:12 +0200
commit8d65512e69441d4756ba49b33a235043035ba1bd (patch)
treeba5c24c0675f8fb02bd060ef5cd867a834197c06 /source3
parent7a266c575af9fa31583c2bd64f79e3b66fd30815 (diff)
downloadsamba-8d65512e69441d4756ba49b33a235043035ba1bd.tar.gz
samba-8d65512e69441d4756ba49b33a235043035ba1bd.tar.xz
samba-8d65512e69441d4756ba49b33a235043035ba1bd.zip
dbwrap: Use messaging_filtered_read
This does not really save any code lines, but IMHO the code is simpler this way. Also, in case we have lots of watchers this will be slightly cheaper, because we don't have to re-establish a tevent_req. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/dbwrap/dbwrap_watch.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/source3/lib/dbwrap/dbwrap_watch.c b/source3/lib/dbwrap/dbwrap_watch.c
index 4f3a2b3f059..a5f1ebd5bff 100644
--- a/source3/lib/dbwrap/dbwrap_watch.c
+++ b/source3/lib/dbwrap/dbwrap_watch.c
@@ -235,6 +235,8 @@ struct dbwrap_record_watch_state {
TDB_DATA w_key;
};
+static bool dbwrap_record_watch_filter(struct messaging_rec *rec,
+ void *private_data);
static void dbwrap_record_watch_done(struct tevent_req *subreq);
static int dbwrap_record_watch_state_destructor(
struct dbwrap_record_watch_state *state);
@@ -271,8 +273,8 @@ struct tevent_req *dbwrap_record_watch_send(TALLOC_CTX *mem_ctx,
return tevent_req_post(req, ev);
}
- subreq = messaging_read_send(state, ev, state->msg,
- MSG_DBWRAP_MODIFIED);
+ subreq = messaging_filtered_read_send(
+ state, ev, state->msg, dbwrap_record_watch_filter, state);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
@@ -288,6 +290,21 @@ struct tevent_req *dbwrap_record_watch_send(TALLOC_CTX *mem_ctx,
return req;
}
+static bool dbwrap_record_watch_filter(struct messaging_rec *rec,
+ void *private_data)
+{
+ struct dbwrap_record_watch_state *state = talloc_get_type_abort(
+ private_data, struct dbwrap_record_watch_state);
+
+ if (rec->msg_type != MSG_DBWRAP_MODIFIED) {
+ return false;
+ }
+ if (rec->buf.length != state->w_key.dsize) {
+ return false;
+ }
+ return memcmp(rec->buf.data, state->w_key.dptr, rec->buf.length) == 0;
+}
+
static int dbwrap_record_watch_state_destructor(
struct dbwrap_record_watch_state *s)
{
@@ -351,33 +368,16 @@ static void dbwrap_record_watch_done(struct tevent_req *subreq)
{
struct tevent_req *req = tevent_req_callback_data(
subreq, struct tevent_req);
- struct dbwrap_record_watch_state *state = tevent_req_data(
- req, struct dbwrap_record_watch_state);
struct messaging_rec *rec;
int ret;
- ret = messaging_read_recv(subreq, talloc_tos(), &rec);
+ ret = messaging_filtered_read_recv(subreq, talloc_tos(), &rec);
TALLOC_FREE(subreq);
if (ret != 0) {
tevent_req_nterror(req, map_nt_error_from_unix(ret));
return;
}
-
- if ((rec->buf.length == state->w_key.dsize) &&
- (memcmp(rec->buf.data, state->w_key.dptr, rec->buf.length) == 0)) {
- tevent_req_done(req);
- return;
- }
-
- /*
- * Not our record, wait for the next one
- */
- subreq = messaging_read_send(state, state->ev, state->msg,
- MSG_DBWRAP_MODIFIED);
- if (tevent_req_nomem(subreq, req)) {
- return;
- }
- tevent_req_set_callback(subreq, dbwrap_record_watch_done, req);
+ tevent_req_done(req);
}
NTSTATUS dbwrap_record_watch_recv(struct tevent_req *req,