Commit 6c17ce62 authored by Marek Vavrusa's avatar Marek Vavrusa

Initial tcp-handler multithreading and API fixes.

Commit refs #967.
parent 79b4addb
......@@ -339,8 +339,8 @@ static int server_bind_handlers(server_t *server)
/* Create TCP handlers. */
if (!iface->handler[TCP_ID]) {
unit = dt_create(tcp_unit_size);
dt_repurpose(unit->threads[0], &tcp_master, 0);
unit = dt_create(tcp_unit_size); /*! \todo Multithreaded TCP. */
tcp_loop_unit(unit);
h = server_create_handler(server, iface->fd[TCP_ID], unit);
h->type = iface->type[TCP_ID];
h->iface = iface;
......
This diff is collapsed.
......@@ -20,10 +20,15 @@
#include <stdint.h>
#include <ev.h>
#include "knot/server/socket.h"
#include "knot/server/server.h"
#include "knot/server/dthreads.h"
/*! \brief TCP event callback. */
typedef void (*tcp_cb_t)(struct ev_loop *, ev_io*, int);
/*!
* \brief Send TCP message.
*
......@@ -51,18 +56,50 @@ int tcp_send(int fd, uint8_t *msg, size_t msglen);
int tcp_recv(int fd, uint8_t *buf, size_t len, sockaddr_t *addr);
/*!
* \brief TCP master socket runnable.
* \brief Generic TCP event loop.
*
* Run TCP handler event loop.
*
* \param thread Associated thread from DThreads unit.
* \param fd First descriptor to be watched (or -1).
* \param cb Callback on fd event.
*
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid parameters.
*/
int tcp_loop(dthread_t *thread, int fd, tcp_cb_t cb);
/*!
* \brief TCP event loop for accepting connections.
*
* \param thread Associated thread from DThreads unit.
*
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid parameters.
*/
int tcp_loop_master(dthread_t *thread);
/*!
* \brief TCP event loop for processing requests.
*
* \param thread Associated thread from DThreads unit.
*
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid parameters.
*/
int tcp_loop_worker(dthread_t *thread);
/*!
* \brief Create TCP event handler from threading unit.
*
* Accepts new TCP connections and distributes them among the rest
* of the threads in unit, which are repurposed as a TCP connection pools.
* New pools are initialized ad-hoc, function implements a cancellation point.
* Set-up threading unit for processing TCP requests.
*
* \param thread Associated thread from DThreads unit.
*
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid parameters.
*/
int tcp_master(dthread_t *thread);
int tcp_loop_unit(dt_unit_t *unit);
#endif // _KNOT_TCPHANDLER_H_
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment