Skip to content

Commit 7b200dc

Browse files
author
Sebastiano Merlino
committed
Removed extraction of the url at each loop
The url was recalculated at each loop. This was unuseful and really expensive especially in presence of a big quantity of data to send or receive.
1 parent 26dffe9 commit 7b200dc

File tree

3 files changed

+99
-106
lines changed

3 files changed

+99
-106
lines changed

examples/Test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void Test::render_PUT(const http_request& r, http_response** res)
9696
int main()
9797
{
9898
// signal(SIGINT, &signal_callback_handler);
99-
webserver ws = create_webserver(8080).max_threads(5);
99+
webserver ws = create_webserver(8080)/*.max_threads(5)*/;
100100
ws_ptr = &ws;
101101
Test dt = Test();
102102
Test2 dt2 = Test2();

src/httpserver/webserver.hpp

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
You should have received a copy of the GNU Lesser General Public
1616
License along with this library; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
1818
USA
1919
*/
2020

@@ -140,12 +140,12 @@ namespace details
140140
template<typename T>
141141
http_resource_mirror(http_resource<T>* res):
142142
render(
143-
HAS_METHOD(render, T, void,
143+
HAS_METHOD(render, T, void,
144144
const http_request&, http_response**
145145
) ? functor(res, &T::render) : functor(&empty_render)
146146
),
147147
render_GET(
148-
HAS_METHOD(render_GET, T, void,
148+
HAS_METHOD(render_GET, T, void,
149149
const http_request&, http_response**
150150
) ? functor(res, &T::render_GET) :
151151
(
@@ -155,7 +155,7 @@ namespace details
155155
)
156156
),
157157
render_POST(
158-
HAS_METHOD(render_POST, T, void,
158+
HAS_METHOD(render_POST, T, void,
159159
const http_request&, http_response**
160160
) ? functor(res, &T::render_POST) :
161161
(
@@ -165,7 +165,7 @@ namespace details
165165
)
166166
),
167167
render_PUT(
168-
HAS_METHOD(render_PUT, T, void,
168+
HAS_METHOD(render_PUT, T, void,
169169
const http_request&, http_response**
170170
) ? functor(res, &T::render_PUT) :
171171
(
@@ -175,7 +175,7 @@ namespace details
175175
)
176176
),
177177
render_HEAD(
178-
HAS_METHOD(render_HEAD, T, void,
178+
HAS_METHOD(render_HEAD, T, void,
179179
const http_request&, http_response**
180180
) ? functor(res, &T::render_HEAD) :
181181
(
@@ -185,7 +185,7 @@ namespace details
185185
)
186186
),
187187
render_DELETE(
188-
HAS_METHOD(render_DELETE, T, void,
188+
HAS_METHOD(render_DELETE, T, void,
189189
const http_request&, http_response**
190190
) ? functor(res, &T::render_DELETE) :
191191
(
@@ -195,7 +195,7 @@ namespace details
195195
)
196196
),
197197
render_TRACE(
198-
HAS_METHOD(render_TRACE, T, void,
198+
HAS_METHOD(render_TRACE, T, void,
199199
const http_request&, http_response**
200200
) ? functor(res, &T::render_TRACE) :
201201
(
@@ -205,7 +205,7 @@ namespace details
205205
)
206206
),
207207
render_OPTIONS(
208-
HAS_METHOD(render_OPTIONS, T, void,
208+
HAS_METHOD(render_OPTIONS, T, void,
209209
const http_request&, http_response**
210210
) ? functor(res, &T::render_OPTIONS) :
211211
(
@@ -215,7 +215,7 @@ namespace details
215215
)
216216
),
217217
render_CONNECT(
218-
HAS_METHOD(render_CONNECT, T, void,
218+
HAS_METHOD(render_CONNECT, T, void,
219219
const http_request&, http_response**
220220
) ? functor(res, &T::render_CONNECT) :
221221
(
@@ -235,9 +235,9 @@ namespace details
235235
{
236236
private:
237237
typedef void(*supply_events_ptr)(
238-
fd_set*,
239-
fd_set*,
240-
fd_set*,
238+
fd_set*,
239+
fd_set*,
240+
fd_set*,
241241
int*
242242
);
243243

@@ -248,9 +248,9 @@ namespace details
248248
dispatch_events_ptr dispatch_events;
249249

250250
event_tuple();
251-
251+
252252
friend class ::httpserver::webserver;
253-
public:
253+
public:
254254
template<typename T>
255255
event_tuple(event_supplier<T>* es):
256256
supply_events(std::bind1st(std::mem_fun(&T::supply_events),es)),
@@ -282,9 +282,9 @@ class event_supplier
282282
}
283283

284284
void supply_events(
285-
fd_set* read_fdset,
286-
fd_set* write_fdset,
287-
fd_set* exc_fdset,
285+
fd_set* read_fdset,
286+
fd_set* write_fdset,
287+
fd_set* exc_fdset,
288288
int* max
289289
) const
290290
{
@@ -313,7 +313,7 @@ typedef void(*log_error_ptr)(const std::string&);
313313
/**
314314
* Class representing the webserver. Main class of the apis.
315315
**/
316-
class webserver
316+
class webserver
317317
{
318318
public:
319319
/**
@@ -338,9 +338,9 @@ class webserver
338338
**/
339339
explicit webserver
340340
(
341-
int port = DEFAULT_WS_PORT,
341+
int port = DEFAULT_WS_PORT,
342342
const http_utils::start_method_T& start_method = http_utils::INTERNAL_SELECT,
343-
int max_threads = 0,
343+
int max_threads = 0,
344344
int max_connections = 0,
345345
int memory_limit = 0,
346346
int connection_timeout = DEFAULT_WS_TIMEOUT,
@@ -425,8 +425,8 @@ class webserver
425425
void send_message_to_consumer(const httpserver_ska& connection_id,
426426
const std::string& message, bool to_lock = true
427427
);
428-
void register_to_topics(const std::vector<std::string>& topics,
429-
const httpserver_ska& connection_id, int keepalive_secs = -1,
428+
void register_to_topics(const std::vector<std::string>& topics,
429+
const httpserver_ska& connection_id, int keepalive_secs = -1,
430430
std::string keepalive_msg = ""
431431
);
432432
size_t read_message(const httpserver_ska& connection_id,
@@ -462,7 +462,7 @@ class webserver
462462
{
463463
return this->log_error;
464464
}
465-
465+
466466
void set_access_logger(log_access_ptr log_access)
467467
{
468468
this->log_access = log_access;
@@ -602,16 +602,16 @@ class webserver
602602
);
603603
void not_found_page(http_response** dhrs, details::modded_request* mr);
604604

605-
static int method_not_acceptable_page
605+
static int method_not_acceptable_page
606606
(
607607
const void *cls,
608608
struct MHD_Connection *connection
609609
);
610-
static void request_completed(void *cls,
611-
struct MHD_Connection *connection, void **con_cls,
610+
static void request_completed(void *cls,
611+
struct MHD_Connection *connection, void **con_cls,
612612
enum MHD_RequestTerminationCode toe
613613
);
614-
static int build_request_header (void *cls, enum MHD_ValueKind kind,
614+
static int build_request_header (void *cls, enum MHD_ValueKind kind,
615615
const char *key, const char *value
616616
);
617617
static int build_request_footer (void *cls, enum MHD_ValueKind kind,
@@ -630,7 +630,7 @@ class webserver
630630
const char* version, const char* upload_data,
631631
size_t* upload_data_size, void** con_cls
632632
);
633-
static int post_iterator
633+
static int post_iterator
634634
(
635635
void *cls,
636636
enum MHD_ValueKind kind,
@@ -640,9 +640,9 @@ class webserver
640640
const char *transfer_encoding,
641641
const char *data, uint64_t off, size_t size
642642
);
643-
static void upgrade_handler
643+
static void upgrade_handler
644644
(
645-
void *cls,
645+
void *cls,
646646
struct MHD_Connection* connection,
647647
void **con_cls, int upgrade_socket
648648
);
@@ -652,42 +652,39 @@ class webserver
652652
static void get_response(cache_entry*, http_response** res);
653653

654654
int bodyless_requests_answer(MHD_Connection* connection,
655-
const char* url, const char* method,
656-
const char* version, struct details::modded_request* mr
655+
const char* method, const char* version,
656+
struct details::modded_request* mr
657657
);
658658

659659
int bodyfull_requests_answer_first_step(MHD_Connection* connection,
660660
struct details::modded_request* mr
661661
);
662662

663663
int bodyfull_requests_answer_second_step(MHD_Connection* connection,
664-
const char* url, const char* method,
665-
const char* version, const char* upload_data,
664+
const char* method, const char* version, const char* upload_data,
666665
size_t* upload_data_size, struct details::modded_request* mr
667666
);
668667

669-
void end_request_construction(MHD_Connection* connection,
670-
struct details::modded_request* mr, const char* version,
671-
const char* st_url, const char* method,
672-
char* user, char* pass, char* digested_user
668+
void end_request_construction(MHD_Connection* connection,
669+
struct details::modded_request* mr, const char* version,
670+
const char* method, char* user, char* pass, char* digested_user
673671
);
674672

675-
int finalize_answer(MHD_Connection* connection,
676-
struct details::modded_request* mr, const char* st_url,
677-
const char* method
673+
int finalize_answer(MHD_Connection* connection,
674+
struct details::modded_request* mr, const char* method
678675
);
679676

680-
int complete_request(MHD_Connection* connection,
681-
struct details::modded_request* mr, const char* version,
682-
const char* st_url, const char* method
677+
int complete_request(MHD_Connection* connection,
678+
struct details::modded_request* mr,
679+
const char* version, const char* method
683680
);
684681

685682
bool use_internal_select()
686683
{
687684
return this->start_method == http_utils::INTERNAL_SELECT;
688685
}
689686

690-
friend int policy_callback (void *cls,
687+
friend int policy_callback (void *cls,
691688
const struct sockaddr* addr, socklen_t addrlen
692689
);
693690
friend void error_log(void* cls, const char* fmt, va_list ap);
@@ -954,7 +951,7 @@ class create_webserver
954951
render_ptr internal_error_resource
955952
)
956953
{
957-
_internal_error_resource = internal_error_resource; return *this;
954+
_internal_error_resource = internal_error_resource; return *this;
958955
}
959956

960957
private:

0 commit comments

Comments
 (0)