Commit Graph

440 Commits

Author SHA1 Message Date
Joris Vink b869041a14 Introduce new config option worker_accept_treshold
This configuration option limits the maximum number
of connections a worker process can accept() in a single
event loop.

It can be used to more evenly spread out incoming connections
across workers when new connections arrive in a burst.
2015-04-23 10:24:00 +02:00
Joris Vink dc6e6fb1b4 Kill NETBUF_CALL_CB_ALWAYS for incoming HTTP body
Do not let the NETBUF_CALL_CB_ALWAYS flag linger in
the netbuf we reset for the incoming HTTP body.
2015-04-21 11:30:59 +02:00
Joris Vink 4c39ac43fb Properly deal with accept() failing.
In cases where accept() failed Kore would not relinquish the
lock towards other worker processes.

This becomes evident when dealing with a high number of concurrent
connections to the point the fd table gets full. In this scenario
the worker with the full fd table will spin on attempt to accept
newer connections.

As a bonus, Kore now has allows exactly up to worker_max_connections
of connections per worker before no longer attempting to grab the
accept lock.
2015-04-20 15:17:42 +02:00
Joris Vink dfea3cf483 Place path and host in http_request into pools.
Also change the amount of times we end of doing unneccessairy strlen() calls.
2015-04-15 12:40:15 +02:00
Joris Vink 6c2e4dd831 Task improvements.
* Always start listening on the task its socket endpoint when
  called kore_task_run() instead of at kore_task_bind_request().

* Disable read events on the task its socket endpoint when
  kore_task_handle() is called for a finished task. Stops us
  from entering a busy loop until kore_task_destroy() is called.
2015-04-14 09:01:36 +02:00
Joris Vink 097a1166df Improve very heavy load handling.
Introduces two new configuration knobs:
	* socket_backlog (backlog for listen(2))
	* http_request_limit

The second one is the most interesting one.

Before, kore would iterate over all received HTTP requests
in its queue before returning out of http_process().

Under heavy load this queue can cause Kore to spend a considerable
amount of time iterating over said queue. With the http_request_limit,
kore will process at MOST http_request_limit requests before returning
back to the event loop.

This means responses to processed requests are sent out much quicker
and allows kore to handle any other incoming requests more gracefully.
2015-04-09 15:29:44 +02:00
Joris Vink b0ff041709 call setrlimit() before we drop privs. 2015-04-09 10:06:18 +02:00
Joris Vink 5f1238c2dc Merge pull request #40 from Geenz/master
Support PUT, DELETE, and HEAD methods in configs.
2015-04-09 10:00:42 +02:00
Joris Vink dc4f856c5c Use UINT_MAX for limit of worker_max_connections. 2015-04-09 08:56:12 +02:00
Geenz 2b907545ca Support PUT, DELETE, and HEAD methods in cofigs.
The primary usecase for this is RESTful APIs where PUT, DELETE, and HEAD can be useful methods to support.
2015-04-08 19:46:27 -04:00
Joris Vink af865abede Bump copyright to 2015 2015-04-07 13:08:26 +02:00
Joris Vink 1fae259603 Use stat(2) to figure out type of directory entry.
readdir(2) might not be able to give back the correct
type in the d_type member and we should properly handle
the DT_UNKNOWN value anyway.

Fixes #39.
2015-04-07 09:27:58 +02:00
Joris Vink d6ab1d7445 Add rudimentary timers to Kore.
Timers are in ms resolution and are added using
kore_timer_add(cb, interval, flags).

Both oneshot timers and continious timers are supported.
2015-04-06 18:54:35 +02:00
Joris Vink cf028f20b6 Rename kore_auth() to kore_auth_run(). 2015-04-02 13:45:42 +02:00
Joris Vink 3b7d8b29e6 Initialize has_cpp to 0. 2015-04-02 13:34:51 +02:00
Joris Vink 3a608a99bb Formatting and slight C++ build improvements.
Do not link against libstdc++ when not having any C++ files.
Let the compiler decide what subprocess to use for compiling
certain files, thus killing the CXX need. Can be overwritten
in the same old default in CC.
2015-04-02 13:33:52 +02:00
Geenz 6bd0da171d Always enable C++ support.
Per @jorisvink's suggestion.
2015-04-02 05:43:07 -04:00
Geenz 93fe8e6b42 Update Readmes 2015-04-01 21:39:40 -04:00
Geenz eab769af6b Add support for selecting C++ dialect and lib.
Otherwise, assume libstdc++ and the compiler's default dialect.
2015-04-01 20:05:09 -04:00
Geenz ba031d15de Sleep deprived typos are the best typos. 2015-04-01 19:28:26 -04:00
Geenz 5af3411513 Code style cleanup in C++ example. 2015-04-01 09:35:05 -04:00
Geenz 97ec644a9a Explicitly link libstdc++. 2015-04-01 08:32:24 -04:00
Geenz 86daf3f1b0 Add support for setting the C++ compiler.
Also make args a bit bigger.
2015-04-01 08:09:09 -04:00
Geenz 6b7f79f733 Wrap C++ support with KORE_CPP_SUPPORT 2015-04-01 07:02:53 -04:00
Geenz 45e9d26f48 Separate C and C++ files into their own lists. 2015-04-01 03:28:03 -04:00
Geenz faa1cf60c4 Add a few useful C++ specific warnings. 2015-03-31 23:09:09 -04:00
Geenz 6e52c31d59 Include .cpp files when building.
This probably isn't an ideal way to add support for also compiling C++ in a project, but for now it works for my needs.
2015-03-31 03:17:33 -04:00
Joris Vink b234b7ed65 Add HTTP_REQUEST_RETAIN_EXTRA flag to http_request
Signals Kore to not free any pointer set in req->hdlr_extra.
Useful in certain scenarios where you have data per request
bound to something in memory but do not want to lose it when
the request is freed by Kore.

Set this flag before your handler returns.
2015-03-27 23:23:21 +01:00
Joris Vink eb235b3e01 shmat() returns (void *)-1 upon error. 2015-03-25 19:42:24 +01:00
Joris Vink a4a86494b8 Bring net_recv_expand() in line with others. 2015-03-16 16:52:40 +01:00
Joris Vink a4298206a7 Fix lies in fatal message. 2015-03-16 16:50:33 +01:00
Joris Vink ad5d662556 Use net_recv_reset() if more body bytes are coming.
Unbreaks clients that send the headers first and the
actual HTTP body after X amount of time.
2015-03-16 16:45:13 +01:00
Joris Vink f8a9ece9a6 Set the x509 callback when initializing the SSL_CTX.
While here, fix a format string error.
2015-02-20 10:49:14 +01:00
Joris Vink f975453565 Set X509 verification callback and log errors.
When using client certificates Kore now calls
domain_x509_verify() and logs any certificate
verification errors that might occur.

CRL validity errors are ignored.
2015-02-20 10:43:31 +01:00
Joris Vink 0288902a1b Set crlfile to NULL when initializing. 2015-02-20 10:11:15 +01:00
Joris Vink 91c44af6f0 Always include includeSubDomains for HSTS. 2015-02-10 17:14:07 +01:00
Joris Vink 1507f88ec7 Respect keepalive when throwing HTTP errors.
Report from github issue #34
2015-02-06 10:59:15 +01:00
Joris Vink 6d90291405 Set rootdir earlier in cli_create(). 2015-02-06 09:02:52 +01:00
Joris Vink 12c07b79e6 Kill a warning when building with BENCHMARK 2015-02-04 19:40:49 +01:00
Joris Vink 6eec8166c6 "request" auth blocks should set their own response. 2015-02-04 12:04:07 +01:00
Joris Vink 2049bc72dc By default Kore now uses ECDH/DHE for TLS key exchanges.
This commit disables RSA key exchanges for TLS completely, while
introducing the requirement for always having DH parameters (ssl_dhparam).

Judging from ciphersuites most modern browsers now prefer this
change should be more than ok.
2015-02-03 13:17:59 +01:00
Joris Vink b1e5a806a6 No need to assign ret when failing here. 2015-01-19 15:32:52 +01:00
Joris Vink 67efb9b04a better brackets around some if statements. 2015-01-19 15:31:36 +01:00
Joris Vink 2ee72657e1 Brackets would be great here. 2015-01-19 15:26:53 +01:00
Joris Vink 6005c95ee6 Fix compiling under openbsd 2014-12-12 19:09:44 +01:00
Joris Vink dbe301e58c Add a patch level to our version number. 2014-12-12 13:06:41 +01:00
Andreas Pfohl 24e1d3928d Added ability to set path prefix during make. 2014-12-12 10:15:30 +01:00
Joris Vink c494126720 Make worker_clients available everywhere. 2014-12-03 20:40:44 +01:00
Joris Vink 7b286f2f70 Set correct timeout start for websockets 2014-11-25 20:00:33 +01:00
Joris Vink f867882f43 Add websocket support to Kore.
Introduces a few new api functions:

- kore_websocket_handshake(struct http_request *):
	Performs the handshake on an HTTP request (coming from page handler)

- kore_websocket_send(struct connection *, u_int8_t, void *, size_t):
	Sends data to a websocket connection.

- kore_websocket_broadcast(struct connection *, u_int8_t, void *, size_t, int):
	Broadcast the given websocket op and data to all connected
	websocket clients on the worker. Note that as of right now
	the WEBSOCKET_BROADCAST_GLOBAL scope option does not work
	yet and messages broadcasted will be restricted to workers
	only.

- kore_worker_websocket_broadcast(struct connection *, void *, void *):
	Backend function used by kore_websocket_broadcast().
	Could prove useful for developers to have access to.

A simple example is given under examples/websocket.

Known issues:
	Kore does not support PING or CONT frames just yet.
2014-11-24 11:08:34 +01:00