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

writev() based TCP send (much faster) and upped minimal TCP thread count.

refs #91
parent 8a430dfc
......@@ -592,7 +592,10 @@ int server_conf_hook(const struct conf_t *conf, void *data)
if (udp_size < 2) udp_size = 2;
dt_unit_t *tu = dt_create_coherent(udp_size, &udp_master, NULL);
server_init_handler(server->h + IO_UDP, server, tu, NULL);
tu = dt_create(tu_size * 2);
/* Create at least CONFIG_XFERS threads for TCP for faster
* processing of massive bootstrap queries. */
tu = dt_create(MAX(tu_size * 2, CONFIG_XFERS));
server_init_handler(server->h + IO_TCP, server, tu, NULL);
tcp_loop_unit(server->h + IO_TCP, tu);
if (server->state & ServerRunning) {
......
......@@ -25,6 +25,9 @@
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SYS_UIO_H // struct iovec (OpenBSD)
#include <sys/uio.h>
#endif // HAVE_SYS_UIO_H
#ifdef HAVE_CAP_NG_H
#include <cap-ng.h>
#endif /* HAVE_CAP_NG_H */
......@@ -403,44 +406,22 @@ static void tcp_loop_free(void *data)
int tcp_send(int fd, uint8_t *msg, size_t msglen)
{
/*! \brief TCP corking.
* \see http://vger.kernel.org/~acme/unbehaved.txt
*/
#ifdef TCP_CORK
int cork = 1;
int uncork = setsockopt(fd, SOL_TCP, TCP_CORK, &cork, sizeof(cork));
#endif
/* Flags. */
int flags = 0;
#ifdef MSG_NOSIGNAL
flags |= MSG_NOSIGNAL;
#endif
/* Send message size. */
unsigned short pktsize = htons(msglen);
int sent = send(fd, &pktsize, sizeof(pktsize), flags);
if (sent < 0) {
return KNOT_ERROR;
}
/* Send message data. */
sent = send(fd, msg, msglen, flags);
if (sent < 0) {
/* Create iovec for gathered write. */
struct iovec iov[2];
uint16_t pktsize = htons(msglen);
iov[0].iov_base = &pktsize;
iov[0].iov_len = sizeof(uint16_t);
iov[1].iov_base = msg;
iov[1].iov_len = msglen;
/* Send. */
int total_len = iov[0].iov_len + iov[1].iov_len;
int sent = writev(fd, iov, 2);
if (sent != total_len) {
return KNOT_ERROR;
}
#ifdef TCP_CORK
/* Uncork only if corked successfuly. */
if (uncork == 0) {
cork = 0;
if (setsockopt(fd, SOL_TCP, TCP_CORK, &cork, sizeof(cork)) < 0) {
dbg_net("tcp: failed to uncork socket\n");
}
}
#endif
return sent;
return msglen; /* Do not count the size prefix. */
}
int tcp_recv(int fd, uint8_t *buf, size_t len, sockaddr_t *addr)
......
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