Commit c3aa9263 authored by Marek Vavrusa's avatar Marek Vavrusa

Simplified TCP handler, more less the same design as UDP handler now.

parent ce591f66
......@@ -704,23 +704,6 @@ int dt_setaffinity(dthread_t *thread, unsigned* cpu_id, size_t cpu_count)
return KNOT_EOK;
}
/*!
* \brief Set thread destructor to be called before physical thread termination.
*
* \param thread Target thread instance
* \param destructor Destructor callback.
*/
int dt_set_desctructor(dthread_t *thread, runnable_t destructor)
{
if (thread == 0) {
return KNOT_EINVAL;
}
thread->destruct = destructor;
return KNOT_EOK;
}
int dt_repurpose(dthread_t *thread, runnable_t runnable, void *data)
{
// Check
......
......@@ -225,14 +225,6 @@ int dt_stop(dt_unit_t *unit);
*/
int dt_setaffinity(dthread_t *thread, unsigned* cpu_id, size_t cpu_count);
/*!
* \brief Set thread destructor to be called before physical thread termination.
*
* \param thread Target thread instance
* \param destructor Destructor callback.
*/
int dt_set_desctructor(dthread_t *thread, runnable_t destructor);
/*!
* \brief Set thread to execute another runnable.
*
......
......@@ -305,26 +305,19 @@ static int server_bind_sockets(server_t *s)
/* Ensure no one is reading old interfaces. */
synchronize_rcu();
/* Update UDP ifacelist (reload all threads). */
dt_unit_t *tu = s->h[IO_UDP].unit;
for (unsigned i = 0; i < tu->size; ++i) {
ref_retain((ref_t *)newlist);
s->h[IO_UDP].state[i].s |= ServerReload;
if (s->state & ServerRunning) {
dt_activate(tu->threads[i]);
dt_signalize(tu->threads[i], SIGALRM);
/* Update TCP+UDP ifacelist (reload all threads). */
for (unsigned proto = IO_UDP; proto <= IO_TCP; ++proto) {
dt_unit_t *tu = s->h[proto].unit;
for (unsigned i = 0; i < tu->size; ++i) {
ref_retain((ref_t *)newlist);
s->h[proto].state[i].s |= ServerReload;
if (s->state & ServerRunning) {
dt_activate(tu->threads[i]);
dt_signalize(tu->threads[i], SIGALRM);
}
}
}
/* Update TCP ifacelist (reload master thread). */
tu = s->h[IO_TCP].unit;
ref_retain((ref_t *)newlist);
s->h[IO_TCP].state[0].s |= ServerReload;
if (s->state & ServerRunning) {
dt_activate(tu->threads[0]);
dt_signalize(tu->threads[0], SIGALRM);
}
ref_release(&oldlist->ref);
return bound;
......@@ -597,16 +590,17 @@ int server_conf_hook(const struct conf_t *conf, void *data)
}
/* Initialize I/O handlers. */
size_t udp_size = tu_size;
dt_unit_t *tu = dt_create_coherent(udp_size, &udp_master,
dt_unit_t *tu = dt_create_coherent(tu_size, &udp_master,
&udp_master_destruct, NULL);
server_init_handler(server->h + IO_UDP, server, tu, NULL);
/* Create at least CONFIG_XFERS threads for TCP for faster
* processing of massive bootstrap queries. */
tu = dt_create(MAX(tu_size * 2, CONFIG_XFERS));
tu = dt_create_coherent(MAX(tu_size * 2, CONFIG_XFERS),
&tcp_master, &tcp_master_destruct, NULL);
server_init_handler(server->h + IO_TCP, server, tu, NULL);
tcp_loop_unit(server->h + IO_TCP, tu);
/* Start if server is running. */
if (server->state & ServerRunning) {
for (unsigned i = 0; i < IO_COUNT; ++i) {
ret = dt_start(server->h[i].unit);
......
This diff is collapsed.
......@@ -76,37 +76,23 @@ 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 event loop for accepting connections.
* \brief TCP handler thread runnable.
*
* \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.
* Listens to both bound TCP sockets for client connections and
* serves TCP clients. This runnable is designed to be used as coherent
* and implements cancellation point.
*
* \param thread Associated thread from DThreads unit.
*
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid parameters.
*/
int tcp_loop_worker(dthread_t *thread);
int tcp_master(dthread_t *thread);
/*!
* \brief Create TCP event handler from threading unit.
*
* Set-up threading unit for processing TCP requests.
*
* \param ioh Associated I/O handler.
* \param thread Associated thread from DThreads unit.
*
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid parameters.
* \brief Destructor for TCP handler thread.
*/
int tcp_loop_unit(iohandler_t *ioh, dt_unit_t *unit);
int tcp_master_destruct(dthread_t *thread);
#endif // _KNOTD_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