From: Yehuda Sadeh Date: Thu, 24 Oct 2013 21:15:10 +0000 (-0700) Subject: rgw: update code to handle mongoose v4.1 X-Git-Tag: v0.75~60^2~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fc7c196faa611da05c10768bd206e070cd9f2e6b;p=ceph.git rgw: update code to handle mongoose v4.1 Signed-off-by: Yehuda Sadeh --- diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 930eb3914e87..fe615a18df10 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -431,18 +431,16 @@ done: } -static int mongoose_callback(struct mg_event *event) { - RGWProcessEnv *pe = (RGWProcessEnv *)event->user_data; +static int mongoose_callback(struct mg_connection *conn) { + struct mg_request_info *req_info = mg_get_request_info(conn); + RGWProcessEnv *pe = (RGWProcessEnv *)req_info->user_data; RGWRados *store = pe->store; RGWREST *rest = pe->rest; OpsLogSocket *olog = pe->olog; - if (event->type != MG_REQUEST_BEGIN) - return 0; - RGWRequest *req = new RGWRequest; int ret; - RGWMongoose client_io(event); + RGWMongoose client_io(conn); client_io.init(g_ceph_context); @@ -738,9 +736,14 @@ int main(int argc, const char **argv) char port_buf[32]; snprintf(port_buf, sizeof(port_buf), "%d", (int)g_conf->rgw_standalone_server_port); - const char *options[] = {"listening_ports", port_buf, "enable_keep_alive", "yes", NULL}; + char thread_pool_buf[32]; + snprintf(thread_pool_buf, sizeof(thread_pool_buf), "%d", (int)g_conf->rgw_thread_pool_size); + const char *options[] = {"listening_ports", port_buf, "enable_keep_alive", "yes", "num_threads", thread_pool_buf, NULL}; - ctx = mg_start((const char **)&options, &mongoose_callback, &pe); + struct mg_callbacks cb; + memset((void *)&cb, 0, sizeof(cb)); + cb.begin_request = mongoose_callback; + ctx = mg_start(&cb, &pe, (const char **)&options); assert(ctx); } diff --git a/src/rgw/rgw_mongoose.cc b/src/rgw/rgw_mongoose.cc index 65ce020f93f9..a941572889cc 100644 --- a/src/rgw/rgw_mongoose.cc +++ b/src/rgw/rgw_mongoose.cc @@ -17,15 +17,15 @@ int RGWMongoose::write_data(const char *buf, int len) data.append(buf, len); return 0; } - return mg_write(event->conn, buf, len); + return mg_write(conn, buf, len); } -RGWMongoose::RGWMongoose(mg_event *_event) : event(_event), header_done(false), sent_header(false), has_content_length(false) { +RGWMongoose::RGWMongoose(mg_connection *_conn) : conn(_conn), header_done(false), sent_header(false), has_content_length(false) { } int RGWMongoose::read_data(char *buf, int len) { - return mg_read(event->conn, buf, len); + return mg_read(conn, buf, len); } void RGWMongoose::flush() @@ -37,9 +37,16 @@ int RGWMongoose::complete_request() if (!sent_header) { if (!has_content_length) { header_done = false; /* let's go back to writing the header */ - int r = send_content_length(data.length()); - if (r < 0) - return r; + + if (0 && data.length() == 0) { + has_content_length = true; + print("Transfer-Enconding: %s\n", "chunked"); + data.append("0\r\n\r\n", sizeof("0\r\n\r\n")-1); + } else { + int r = send_content_length(data.length()); + if (r < 0) + return r; + } } complete_header(); @@ -58,7 +65,7 @@ int RGWMongoose::complete_request() void RGWMongoose::init_env(CephContext *cct) { env.init(cct); - struct mg_request_info *info = event->request_info; + struct mg_request_info *info = mg_get_request_info(conn); if (!info) return; @@ -129,7 +136,7 @@ int RGWMongoose::send_100_continue() { char buf[] = "HTTP/1.1 100 CONTINUE\r\n\r\n"; - return mg_write(event->conn, buf, sizeof(buf) - 1); + return mg_write(conn, buf, sizeof(buf) - 1); } int RGWMongoose::complete_header() diff --git a/src/rgw/rgw_mongoose.h b/src/rgw/rgw_mongoose.h index 9454d90a0dab..f6a7c923321d 100644 --- a/src/rgw/rgw_mongoose.h +++ b/src/rgw/rgw_mongoose.h @@ -4,13 +4,12 @@ #include "rgw_client_io.h" -struct mg_event; struct mg_connection; class RGWMongoose : public RGWClientIO { - mg_event *event; + mg_connection *conn; bufferlist header_data; bufferlist data; @@ -31,7 +30,7 @@ public: int complete_request(); int send_content_length(uint64_t len); - RGWMongoose(mg_event *_event); + RGWMongoose(mg_connection *_conn); void flush(); };