From 6d2642bb1a42840e809e7a73896a1631d37b15e6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 18 Jul 2013 00:25:47 +0000 Subject: split out {http,mgmt}_rbuf_grow functions This should allow easier tracing of rbuf growth, and should hopefully make the code more explicit and harder to screw up. --- http.c | 16 ++++++++++++---- mgmt.c | 15 +++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/http.c b/http.c index cc802c3..6f51cf8 100644 --- a/http.c +++ b/http.c @@ -236,6 +236,16 @@ http_client_died(struct mog_fd *mfd, size_t buf_len, int save_err) return MOG_NEXT_CLOSE; } +MOG_NOINLINE static char * +http_rbuf_grow(struct mog_fd *mfd, struct mog_rbuf **rbuf, size_t buf_len) +{ + struct mog_http *http = &mfd->as.http; + + (*rbuf)->rsize = buf_len; + http->rbuf = *rbuf = mog_rbuf_grow(*rbuf); + return *rbuf ? (*rbuf)->rptr : NULL; +} + static enum mog_next __http_queue_step(struct mog_fd *mfd) { struct mog_http *http = &mfd->as.http; @@ -288,11 +298,9 @@ parse: assert(http->wbuf == NULL && "tried to write (and failed) with partial req"); if (http->_p.buf_off >= rbuf->rcapa) { - rbuf->rsize = buf_len; - http->rbuf = rbuf = mog_rbuf_grow(rbuf); - if (!rbuf) + buf = http_rbuf_grow(mfd, &rbuf, buf_len); + if (!buf) goto err400; - buf = rbuf->rptr; } off = http->_p.buf_off; goto reread; diff --git a/mgmt.c b/mgmt.c index 6a0a12a..b80718c 100644 --- a/mgmt.c +++ b/mgmt.c @@ -214,6 +214,15 @@ static enum mog_next mgmt_run(struct mog_fd *mfd, struct mog_rbuf *rbuf, return mgmt->wbuf ? MOG_NEXT_WAIT_WR : MOG_NEXT_ACTIVE; } +MOG_NOINLINE static char * +mgmt_rbuf_grow(struct mog_fd *mfd, struct mog_rbuf **rbuf, size_t buf_len) +{ + struct mog_mgmt *mgmt = &mfd->as.mgmt; + (*rbuf)->rsize = buf_len; + mgmt->rbuf = *rbuf = mog_rbuf_grow(*rbuf); + return *rbuf ? (*rbuf)->rptr : NULL; +} + /* * this is the main event callback and called whenever mgmt * is pulled out of a queue (either idle or active) @@ -265,11 +274,9 @@ parse: assert(mgmt->wbuf == NULL && "tried to write (and failed) with partial req"); if (mgmt->buf_off >= rbuf->rcapa) { - rbuf->rsize = buf_len; - mgmt->rbuf = rbuf = mog_rbuf_grow(rbuf); - if (!rbuf) + buf = mgmt_rbuf_grow(mfd, &rbuf, buf_len); + if (!buf) goto too_large; - buf = rbuf->rptr; } off = mgmt->buf_off; goto reread; -- cgit v1.2.3-24-ge0c7