kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit c2e4d5523528f772e8d6b86c7b1bd27d466e68f3
parent 8ff870a352e907a86f0819e217ef3dd5804c8923
Author: Joris Vink <joris@coders.se>
Date:   Fri,  1 Aug 2014 10:22:32 +0200

Add a BENCHMARK compile option which compiles without OpenSSL.

Personally use this for testing Kore its performance without
letting the OpenSSL stack get in the way too much.

Note that it leaves data structures as is, and just removes
any calls to OpenSSL (and removes the linking vs OpenSSL).

Diffstat:
Makefile | 5+++++
src/accesslog.c | 2++
src/config.c | 6++----
src/connection.c | 20++++++++++++++++++--
src/domain.c | 2++
src/kore.c | 4++++
src/net.c | 44+++++++++++++++++++++++++++++++++++---------
7 files changed, 68 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile @@ -24,6 +24,11 @@ ifneq ("$(KORE_PEDANTIC_MALLOC)", "") CFLAGS+=-DKORE_PEDANTIC_MALLOC endif +ifneq ("$(BENCHMARK)", "") + CFLAGS+=-DKORE_BENCHMARK + LDFLAGS=-rdynamic -lz +endif + ifneq ("$(PGSQL)", "") S_SRC+=src/pgsql.c LDFLAGS+=-L$(shell pg_config --libdir) -lpq diff --git a/src/accesslog.c b/src/accesslog.c @@ -175,12 +175,14 @@ kore_accesslog(struct http_request *req) } memset(logpacket.cn, '\0', sizeof(logpacket.cn)); +#if !defined(KORE_BENCHMARK) if (req->owner->cert != NULL) { if (X509_GET_CN(req->owner->cert, logpacket.cn, sizeof(logpacket.cn)) == -1) { kore_log(LOG_WARNING, "client cert without a CN?"); } } +#endif len = send(accesslog_fd[1], &logpacket, sizeof(logpacket), 0); if (len == -1) { diff --git a/src/config.c b/src/config.c @@ -128,9 +128,6 @@ kore_parse_config(void) { char *p; - if (config_file == NULL) - fatal("specify a configuration file with -c"); - kore_parse_config_file(config_file); if (!kore_module_loaded()) @@ -274,6 +271,7 @@ configure_ssl_cipher(char **argv) static int configure_ssl_dhparam(char **argv) { +#if !defined(KORE_BENCHMARK) BIO *bio; if (argv[1] == NULL) @@ -296,7 +294,7 @@ configure_ssl_dhparam(char **argv) printf("PEM_read_bio_DHparams(): %s\n", ssl_errno_s); return (KORE_RESULT_ERROR); } - +#endif return (KORE_RESULT_OK); } diff --git a/src/connection.c b/src/connection.c @@ -76,7 +76,6 @@ kore_connection_accept(struct listener *l, struct connection **out) c->deflate_started = 0; c->client_stream_id = 0; c->proto = CONN_PROTO_UNKNOWN; - c->state = CONN_STATE_SSL_SHAKE; c->wsize_initial = SPDY_INIT_WSIZE; c->idle_timer.start = 0; c->idle_timer.length = KORE_IDLE_TIMER_MAX; @@ -86,6 +85,18 @@ kore_connection_accept(struct listener *l, struct connection **out) TAILQ_INIT(&(c->spdy_streams)); TAILQ_INIT(&(c->http_requests)); +#if !defined(KORE_BENCHMARK) + c->state = CONN_STATE_SSL_SHAKE; +#else + c->state = CONN_STATE_ESTABLISHED; + c->proto = CONN_PROTO_HTTP; + if (http_keepalive_time != 0) + c->idle_timer.length = http_keepalive_time * 1000; + + net_recv_queue(c, http_header_max, NETBUF_CALL_CB_ALWAYS, NULL, + http_header_recv); +#endif + kore_worker_connection_add(c); kore_connection_start_idletimer(c); @@ -106,16 +117,18 @@ kore_connection_disconnect(struct connection *c) int kore_connection_handle(struct connection *c) { +#if !defined(KORE_BENCHMARK) int r; u_int32_t len; const u_char *data; char cn[X509_CN_LENGTH]; +#endif kore_debug("kore_connection_handle(%p) -> %d", c, c->state); - kore_connection_stop_idletimer(c); switch (c->state) { +#if !defined(KORE_BENCHMARK) case CONN_STATE_SSL_SHAKE: if (c->ssl == NULL) { c->ssl = SSL_new(primary_dom->ssl_ctx); @@ -199,6 +212,7 @@ kore_connection_handle(struct connection *c) c->state = CONN_STATE_ESTABLISHED; /* FALLTHROUGH */ +#endif /* !KORE_BENCHMARK */ case CONN_STATE_ESTABLISHED: if (c->flags & CONN_READ_POSSIBLE) { if (!net_recv_flush(c)) @@ -231,6 +245,7 @@ kore_connection_remove(struct connection *c) kore_debug("kore_connection_remove(%p)", c); +#if !defined(KORE_BENCHMARK) if (c->ssl != NULL) { SSL_shutdown(c->ssl); SSL_free(c->ssl); @@ -238,6 +253,7 @@ kore_connection_remove(struct connection *c) if (c->cert != NULL) X509_free(c->cert); +#endif close(c->fd); diff --git a/src/domain.c b/src/domain.c @@ -58,6 +58,7 @@ kore_domain_new(char *domain) void kore_domain_sslstart(struct kore_domain *dom) { +#if !defined(KORE_BENCHMARK) STACK_OF(X509_NAME) *certs; #if !defined(OPENSSL_NO_EC) @@ -138,6 +139,7 @@ kore_domain_sslstart(struct kore_domain *dom) kore_mem_free(dom->certfile); kore_mem_free(dom->certkey); +#endif } struct kore_domain * diff --git a/src/kore.c b/src/kore.c @@ -147,6 +147,7 @@ main(int argc, char *argv[]) return (0); } +#if !defined(KORE_BENCHMARK) int kore_ssl_npn_cb(SSL *ssl, const u_char **data, unsigned int *len, void *arg) { @@ -183,6 +184,7 @@ kore_ssl_sni_cb(SSL *ssl, int *ad, void *arg) return (SSL_TLSEXT_ERR_NOACK); } +#endif int kore_server_bind(const char *ip, const char *port) @@ -259,10 +261,12 @@ kore_signal(int sig) static void kore_server_sslstart(void) { +#if !defined(KORE_BENCHMARK) kore_debug("kore_server_sslstart()"); SSL_library_init(); SSL_load_error_strings(); +#endif } static void diff --git a/src/net.c b/src/net.c @@ -128,11 +128,9 @@ net_send(struct connection *c) if (nb->b_len != 0) { len = MIN(NETBUF_SEND_PAYLOAD_MAX, nb->b_len - nb->s_off); - r = SSL_write(c->ssl, (nb->buf + nb->s_off), len); - - kore_debug("net_send(%d/%d bytes), progress with %d", - nb->s_off, nb->b_len, r); +#if !defined(KORE_BENCHMARK) + r = SSL_write(c->ssl, (nb->buf + nb->s_off), len); if (r <= 0) { r = SSL_get_error(c->ssl, r); switch (r) { @@ -146,9 +144,24 @@ net_send(struct connection *c) return (KORE_RESULT_ERROR); } } +#else + r = write(c->fd, (nb->buf + nb->s_off), len); + if (r <= -1) { + switch (errno) { + case EINTR: + case EAGAIN: + c->flags &= ~CONN_WRITE_POSSIBLE; + return (KORE_RESULT_OK); + default: + kore_debug("write: %s", errno_s); + return (KORE_RESULT_ERROR); + } + } +#endif + kore_debug("net_send(%d/%d bytes), progress with %d", + nb->s_off, nb->b_len, r); nb->s_off += (size_t)r; - if (nb->stream != NULL) spdy_update_wsize(c, nb->stream, r); } @@ -194,12 +207,9 @@ net_recv(struct connection *c) return (KORE_RESULT_ERROR); } +#if !defined(KORE_BENCHMARK) r = SSL_read(c->ssl, (nb->buf + nb->s_off), (nb->b_len - nb->s_off)); - - kore_debug("net_recv(%ld/%ld bytes), progress with %d", - nb->s_off, nb->b_len, r); - if (r <= 0) { r = SSL_get_error(c->ssl, r); switch (r) { @@ -212,6 +222,22 @@ net_recv(struct connection *c) return (KORE_RESULT_ERROR); } } +#else + r = read(c->fd, (nb->buf + nb->s_off), (nb->b_len - nb->s_off)); + if (r <= 0) { + switch (errno) { + case EINTR: + case EAGAIN: + c->flags &= ~CONN_READ_POSSIBLE; + return (KORE_RESULT_OK); + default: + kore_debug("read(): %s", errno_s); + return (KORE_RESULT_ERROR); + } + } +#endif + kore_debug("net_recv(%ld/%ld bytes), progress with %d", + nb->s_off, nb->b_len, r); nb->s_off += (size_t)r; if (nb->s_off == nb->b_len ||