[sheepdog] [PATCH 2/9] http: avoid reading a total data in the main thread
MORITA Kazutaka
morita.kazutaka at gmail.com
Thu Oct 31 08:49:00 CET 2013
From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
It's not good to sleep a long time in the main thread.
Object storage handles a big data and we shouldn't keep whole of it in
the memory. I think we should directly use http_request_read and
http_request_write.
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
sheep/http.c | 39 +++++++++++++++++----------------------
1 file changed, 17 insertions(+), 22 deletions(-)
diff --git a/sheep/http.c b/sheep/http.c
index 88c66e4..71bfb37 100644
--- a/sheep/http.c
+++ b/sheep/http.c
@@ -20,7 +20,6 @@
struct http_request {
FCGX_Request fcgx;
int opcode;
- char *data;
size_t data_length;
};
@@ -71,19 +70,16 @@ struct http_work {
struct http_request *request;
};
-static inline int http_request_error(struct http_request *req)
+static inline void http_request_error(struct http_request *req)
{
int ret = FCGX_GetError(req->fcgx.out);
- if (ret == 0) {
- return OK;
- } else if (ret < 0) {
+ if (ret == 0)
+ return;
+ else if (ret < 0)
sd_err("failed, FCGI error %d", ret);
- return INTERNAL_SERVER_ERROR;
- } else {
+ else
sd_err("failed, %s", strerror(ret));
- return INTERNAL_SERVER_ERROR;
- }
}
static inline int http_request_write(struct http_request *req,
@@ -91,8 +87,8 @@ static inline int http_request_write(struct http_request *req,
{
int ret = FCGX_PutStr(buf, len, req->fcgx.out);
if (ret < 0)
- return http_request_error(req);
- return OK;
+ http_request_error(req);
+ return ret;
}
static inline int http_request_read(struct http_request *req,
@@ -100,16 +96,16 @@ static inline int http_request_read(struct http_request *req,
{
int ret = FCGX_GetStr(buf, len, req->fcgx.in);
if (ret < 0)
- return http_request_error(req);
- return OK;
+ http_request_error(req);
+ return ret;
}
static inline int http_request_writes(struct http_request *req, const char *str)
{
int ret = FCGX_PutS(str, req->fcgx.out);
if (ret < 0)
- return http_request_error(req);
- return OK;
+ http_request_error(req);
+ return ret;
}
__printf(2, 3)
@@ -122,8 +118,8 @@ static int http_request_writef(struct http_request *req, const char *fmt, ...)
ret = FCGX_VFPrintF(req->fcgx.out, fmt, ap);
va_end(ap);
if (ret < 0)
- return http_request_error(req);
- return OK;
+ http_request_error(req);
+ return ret;
}
static int request_init_operation(struct http_request *req)
@@ -134,10 +130,6 @@ static int request_init_operation(struct http_request *req)
p = FCGX_GetParam("REQUEST_METHOD", env);
if (!strcmp(p, "PUT")) {
req->opcode = HTTP_PUT;
- p = FCGX_GetParam("CONTENT_LENGTH", env);
- req->data_length = strtoll(p, NULL, 10);
- req->data = xmalloc(req->data_length);
- http_request_read(req, req->data, req->data_length);
} else if (!strcmp(p, "GET")) {
req->opcode = HTTP_GET;
} else if (!strcmp(p, "POST")) {
@@ -149,6 +141,10 @@ static int request_init_operation(struct http_request *req)
} else {
return BAD_REQUEST;
}
+
+ p = FCGX_GetParam("CONTENT_LENGTH", env);
+ req->data_length = strtoll(p, NULL, 10);
+
return OK;
}
@@ -215,7 +211,6 @@ static const int http_max_request_handlers = ARRAY_SIZE(http_request_handlers);
static void http_end_request(struct http_request *req)
{
FCGX_Finish_r(&req->fcgx);
- free(req->data);
free(req);
}
--
1.8.1.2
More information about the sheepdog
mailing list