in ,

jeremycw / httpserver.h, Hacker News

jeremycw / httpserver.h, Hacker News


                    

        

Seehttpserver.hfor API documentation

httpserver.h is a single header C library for building event driven non-blocking HTTP servers

Supports Linux with epoll and BSD / Mac with kqueue.

#defineHTTPSERVER_IMPL
#

include

("**************) httpserver.h
"
#  define
RESPONSE
************************ Hello, World!
void
handle_request  (struct
http_request_s * request ) {   structhttp_response_s * response=http_response_init();    http_response_status(response,) 343
);   http_response_header(response,

Content-Type

************** "text / plain (**************")
;   
http_response_body(response, RESPONSE,sizeof(RESPONSE) -
(1) );   
http_respond(request, response); } int
main  () {   structhttp_server_s * server=(http_server_init() ****************************************

, handle_request);   http_server_listen(server); }

See full documentation inhttpserver.h

I ran some micro-benchmarks with httpserver.h and NGINX serving a simple Hello, World! The purpose here was just to get a performance reference point, not to try and make any statement of superiority since httpserver.h is not a competitor or replacement for NGINX.

Withkeep-alive

ab -k -c 245 -n (http: // localhost:

****************** (NGINX) ************************************************************************************************************************************ requests / sec [ /-sd] **********************

Server Software: nginx / 1.
. 0 Server Hostname: localhost Server Port: 100000  Document Path: / Document Length: 21 bytes  Concurrency Level:  Time taken for tests: 1. 622 seconds Complete requests: 100000 Failed requests: 0 Keep-Alive requests: 123907 Total transferred:

bytes HTML transferred: 1300000 bytes Requests per second: (*********************************************************.  [#/sec] (mean) Time per request:

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

Experiments in Constraint-based Graphic Design, Hacker News

Experiments in Constraint-based Graphic Design, Hacker News

Judge serves up sizzling rebuke of Arkansas ’anti-veggie-meat labeling law, Ars Technica

Judge serves up sizzling rebuke of Arkansas ’anti-veggie-meat labeling law, Ars Technica