diff options
Diffstat (limited to 'http.c')
-rw-r--r-- | http.c | 31 |
1 files changed, 15 insertions, 16 deletions
@@ -136,16 +136,18 @@ void mog_http_drop(struct mog_fd *mfd) } /* returns true if we can continue queue step, false if not */ -static enum mog_next http_wbuf_in_progress(struct mog_http *http) +static enum mog_next http_wbuf_in_progress(struct mog_fd *mfd) { + struct mog_http *http = &mfd->as.http; + assert(http->wbuf != MOG_WR_ERROR && "still active after write error"); - switch (mog_tryflush(mog_fd_of(http)->fd, &http->wbuf)) { + switch (mog_tryflush(mfd->fd, &http->wbuf)) { case MOG_WRSTATE_ERR: return MOG_NEXT_CLOSE; case MOG_WRSTATE_DONE: if (!http->_p.persistent) return MOG_NEXT_CLOSE; if (http->forward == NULL) - mog_http_reset(http); + mog_http_reset(mfd); assert(http->_p.buf_off == 0 && "bad offset"); return MOG_NEXT_ACTIVE; case MOG_WRSTATE_BUSY: @@ -200,7 +202,7 @@ static enum mog_next http_run(struct mog_fd *mfd, struct mog_rbuf *rbuf, TRACE(CMOGSTORED_HTTP_REQ_BEGIN(true)); http_defer_rbuf(http, rbuf, buf_len); - mog_http_reset(http); + mog_http_reset(mfd); } return MOG_NEXT_ACTIVE; } @@ -239,7 +241,7 @@ static enum mog_next __http_queue_step(struct mog_fd *mfd) assert(mfd->fd >= 0 && "http fd is invalid"); - if (http->wbuf) return http_wbuf_in_progress(http); + if (http->wbuf) return http_wbuf_in_progress(mfd); if (http->forward) return http_forward_in_progress(mfd, true); /* we may have pipelined data in http->rbuf */ @@ -312,10 +314,10 @@ parse: err507or400: if (errno == ERANGE) { - mog_http_resp(http, "507 Insufficient Storage", false); + mog_http_resp(mfd, "507 Insufficient Storage", false); } else { err400: - mog_http_resp(http, "400 Bad Request", false); + mog_http_resp(mfd, "400 Bad Request", false); } return MOG_NEXT_CLOSE; } @@ -438,15 +440,12 @@ char *mog_http_path(struct mog_http *http, char *buf) /* TODO: see if the iovec overheads of writev() is even worth it... */ -void -mog_http_resp0( - struct mog_http *http, - struct iovec *status, - bool alive) +void mog_http_resp0(struct mog_fd *mfd, struct iovec *status, bool alive) { struct iovec iov; struct mog_now *now; char *dst = iov.iov_base = mog_fsbuf_get(&iov.iov_len); + struct mog_http *http = &mfd->as.http; assert(status->iov_len * 2 + 1024 < iov.iov_len && "fsbuf too small"); @@ -471,12 +470,12 @@ mog_http_resp0( iov.iov_len = dst - (char *)iov.iov_base; assert(http->wbuf == NULL && "tried to write with wbuf"); - http->wbuf = mog_trywritev(mog_fd_of(http)->fd, &iov, 1); + http->wbuf = mog_trywritev(mfd->fd, &iov, 1); } /* call whenever we're ready to read the next HTTP request */ -void mog_http_reset(struct mog_http *http) +void mog_http_reset(struct mog_fd *mfd) { - tcp_push(mog_fd_of(http), true); - mog_http_reset_parser(http); + tcp_push(mfd, true); + mog_http_reset_parser(&mfd->as.http); } |