diff options
Diffstat (limited to 'http_get.c')
-rw-r--r-- | http_get.c | 27 |
1 files changed, 21 insertions, 6 deletions
@@ -197,10 +197,14 @@ void mog_http_get_open(struct mog_fd *mfd, char *buf) sb.st_mtime = 0; sb.st_size = 0; } else if (http->_p.http_method == MOG_HTTP_METHOD_HEAD) { - if (mog_stat(http->svc, path, &sb) < 0) goto err; - if (!S_ISREG(sb.st_mode)) goto forbidden; + if (mog_stat_req(http->svc, http->_p.mog_devid, path, &sb) < 0) + goto err; + if (!S_ISREG(sb.st_mode)) + goto forbidden; } else { - http->forward = mog_file_open_read(http->svc, path); + http->forward = mog_file_open_read(http->svc, + http->_p.mog_devid, path); + if (http->forward == NULL) goto err; @@ -264,14 +268,25 @@ enum mog_next mog_http_get_in_progress(struct mog_fd *mfd) count = count > max_sendfile ? max_sendfile : count; if (count == 0) goto done; + + /* + * we want to hold the semaphore across open and initial sendfile, + * so this is the only place were we conditionally hold the semaphore + */ + mog_file_ensure_wait(file_mfd); retry: w = sendfile(mfd->fd, file_mfd->fd, &file->foff, (size_t)count); if (w > 0) { - if (file->foff == file->fsize) goto done; + if (file->foff == file->fsize) + goto done; + + mog_file_post(file_mfd); return MOG_NEXT_ACTIVE; } else if (w < 0) { switch (errno) { - case_EAGAIN: return MOG_NEXT_WAIT_WR; + case_EAGAIN: + mog_file_post(file_mfd); + return MOG_NEXT_WAIT_WR; case EINTR: goto retry; } http->_p.persistent = 0; @@ -286,7 +301,7 @@ retry: (long long)file->foff); } done: - mog_file_close(http->forward); + mog_file_close(file_mfd); if (http->_p.persistent) { mog_http_reset(http); return MOG_NEXT_ACTIVE; |