From a3fcb93df1571da51a0f525141c3010e7f2dcae6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Nov 2005 10:50:39 +0000 Subject: r11602: added packet_set_serialise() to allow the generic packet layer to handle optional request serialisation (this is something that is commonly needed on stream connections) (This used to be commit d860eb795693d8c292eec2a639ece4793d28dc38) --- source4/lib/stream/packet.c | 28 ++++++++++++++++++++++++++++ source4/lib/stream/packet.h | 1 + 2 files changed, 29 insertions(+) (limited to 'source4/lib/stream') diff --git a/source4/lib/stream/packet.c b/source4/lib/stream/packet.c index 971135ff9b..50687d18fa 100644 --- a/source4/lib/stream/packet.c +++ b/source4/lib/stream/packet.c @@ -41,6 +41,9 @@ struct packet_context { struct event_context *ev; size_t packet_size; void *private; + struct fd_event *fde; + BOOL serialise; + BOOL processing; }; /* @@ -115,6 +118,16 @@ void packet_set_event_context(struct packet_context *pc, struct event_context *e pc->ev = ev; } +/* + tell the packet layer to serialise requests, so we don't process two requests at once on + one connection. You must have set the event_context +*/ +void packet_set_serialise(struct packet_context *pc, struct fd_event *fde) +{ + pc->serialise = True; + pc->fde = fde; +} + /* tell the caller we have an error @@ -167,6 +180,10 @@ void packet_recv(struct packet_context *pc) size_t nread; DATA_BLOB blob; + if (pc->processing) { + return; + } + if (pc->packet_size != 0 && pc->num_read >= pc->packet_size) { goto next_partial; } @@ -262,8 +279,19 @@ next_partial: } pc->num_read -= pc->packet_size; pc->packet_size = 0; + + if (pc->serialise) { + EVENT_FD_NOT_READABLE(pc->fde); + pc->processing = True; + } status = pc->callback(pc->private, blob); + + if (pc->serialise) { + EVENT_FD_READABLE(pc->fde); + pc->processing = False; + } + if (!NT_STATUS_IS_OK(status)) { packet_error(pc, status); return; diff --git a/source4/lib/stream/packet.h b/source4/lib/stream/packet.h index 6d29264a28..b6ed8d6598 100644 --- a/source4/lib/stream/packet.h +++ b/source4/lib/stream/packet.h @@ -38,6 +38,7 @@ void packet_set_full_request(struct packet_context *pc, packet_full_request_fn_t void packet_set_tls(struct packet_context *pc, struct tls_context *tls); void packet_set_socket(struct packet_context *pc, struct socket_context *sock); void packet_set_event_context(struct packet_context *pc, struct event_context *ev); +void packet_set_serialise(struct packet_context *pc, struct fd_event *fde); void packet_recv(struct packet_context *pc); /* -- cgit