about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-07-18 00:25:47 +0000
committerEric Wong <normalperson@yhbt.net>2013-07-19 01:29:49 +0000
commit6d2642bb1a42840e809e7a73896a1631d37b15e6 (patch)
treeadaed302c3370ed83e0c32a1e32343b4631afd20
parent48bbaf84da51644451a3dc0c1254d51c035ccce0 (diff)
downloadcmogstored-6d2642bb1a42840e809e7a73896a1631d37b15e6.tar.gz
This should allow easier tracing of rbuf growth, and should
hopefully make the code more explicit and harder to screw up.
-rw-r--r--http.c16
-rw-r--r--mgmt.c15
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;