Commit d406efa3 authored by Jan Včelák's avatar Jan Včelák 🚀

server: adapt to networking and requestor API changes

parent 675613ac
......@@ -121,7 +121,7 @@ int remote_recv(int sock, uint8_t *buf, size_t *buflen)
}
/* Receive data. */
int n = net_dns_tcp_recv(c, buf, *buflen, NULL);
int n = net_dns_tcp_recv(c, buf, *buflen, -1);
*buflen = n;
if (n <= 0) {
close(c);
......@@ -172,10 +172,10 @@ static int remote_send_chunk(int c, knot_pkt_t *query, const char *d, uint16_t l
rcu_read_lock();
conf_val_t *val = &conf()->cache.srv_tcp_reply_timeout;
struct timeval timeout = { conf_int(val), 0 };
const int timeout = conf_int(val) * 1000;
rcu_read_unlock();
ret = net_dns_tcp_send(c, resp->wire, resp->size, &timeout);
ret = net_dns_tcp_send(c, resp->wire, resp->size, timeout);
failed:
......
......@@ -94,8 +94,8 @@ static int dnsproxy_fwd(int state, knot_pkt_t *pkt, struct query_data *qdata, vo
ret = knot_requestor_enqueue(&re, req);
if (ret == KNOT_EOK) {
conf_val_t *val = &conf()->cache.srv_tcp_reply_timeout;
struct timeval tv = { conf_int(val), 0 };
ret = knot_requestor_exec(&re, &tv);
int timeout = conf_int(val) * 1000;
ret = knot_requestor_exec(&re, timeout);
} else {
knot_request_free(req, re.mm);
}
......
......@@ -277,8 +277,8 @@ static int remote_forward(struct knot_request *request, conf_remote_t *remote)
ret = knot_requestor_enqueue(&re, req);
if (ret == KNOT_EOK) {
conf_val_t *val = &conf()->cache.srv_tcp_reply_timeout;
struct timeval tv = { conf_int(val), 0 };
ret = knot_requestor_exec(&re, &tv);
const int timeout = conf_int(val) * 1000;
ret = knot_requestor_exec(&re, timeout);
} else {
knot_request_free(req, re.mm);
}
......@@ -379,9 +379,9 @@ static void send_update_response(const zone_t *zone, struct knot_request *req)
if (net_is_stream(req->fd)) {
conf_val_t *val = &conf()->cache.srv_tcp_reply_timeout;
struct timeval timeout = { conf_int(val), 0 };
int timeout = conf_int(val) * 1000;
net_dns_tcp_send(req->fd, req->resp->wire, req->resp->size,
&timeout);
timeout);
} else {
net_dgram_send(req->fd, req->resp->wire, req->resp->size,
&req->remote);
......
......@@ -114,12 +114,11 @@ static int tcp_handle(tcp_context_t *tcp, int fd,
/* Timeout. */
rcu_read_lock();
conf_val_t *val = &conf()->cache.srv_tcp_reply_timeout;
struct timeval tmout = { conf_int(val), 0 };
const int timeout = conf_int(val) * 1000;
rcu_read_unlock();
/* Receive data. */
struct timeval recv_tmout = tmout;
int ret = net_dns_tcp_recv(fd, rx->iov_base, rx->iov_len, &recv_tmout);
int ret = net_dns_tcp_recv(fd, rx->iov_base, rx->iov_len, timeout);
if (ret <= 0) {
if (ret == KNOT_EAGAIN) {
char addr_str[SOCKADDR_STRLEN] = {0};
......@@ -159,8 +158,7 @@ static int tcp_handle(tcp_context_t *tcp, int fd,
/* Send, if response generation passed and wasn't ignored. */
if (ans->size > 0 && !(state & (KNOT_STATE_FAIL|KNOT_STATE_NOOP))) {
struct timeval send_tmout = tmout;
if (net_dns_tcp_send(fd, ans->wire, ans->size, &send_tmout) != ans->size) {
if (net_dns_tcp_send(fd, ans->wire, ans->size, timeout) != ans->size) {
ret = KNOT_ECONNREFUSED;
break;
}
......
......@@ -158,8 +158,8 @@ static int zone_query_request(knot_pkt_t *query, const conf_remote_t *remote,
ret = knot_requestor_enqueue(&re, req);
if (ret == KNOT_EOK) {
conf_val_t *val = &conf()->cache.srv_tcp_reply_timeout;
struct timeval tv = { conf_int(val), 0 };
ret = knot_requestor_exec(&re, &tv);
int timeout = conf_int(val) * 1000;
ret = knot_requestor_exec(&re, timeout);
} else {
knot_request_free(req, re.mm);
}
......
......@@ -44,7 +44,7 @@ static int cmd_remote_print_reply(const knot_rrset_t *rr)
return KNOT_EOK;
}
static int cmd_remote_reply(int c, struct timeval *timeout)
static int cmd_remote_reply(int c, int timeout_ms)
{
knot_pkt_t *pkt = knot_pkt_new(NULL, KNOT_WIRE_MAX_PKTSIZE, NULL);
if (!pkt) {
......@@ -52,7 +52,7 @@ static int cmd_remote_reply(int c, struct timeval *timeout)
}
/* Read response packet. */
int n = net_dns_tcp_recv(c, pkt->wire, pkt->max_size, timeout);
int n = net_dns_tcp_recv(c, pkt->wire, pkt->max_size, timeout_ms);
if (n <= 0) {
knot_pkt_free(&pkt);
return KNOT_ECONN;
......@@ -132,7 +132,7 @@ int cmd_remote(const char *socket, const char *cmd, uint16_t rrt,
/* Default timeout. */
conf_val_t *val = &conf()->cache.srv_tcp_reply_timeout;
const struct timeval tv_reply = { conf_int(val), 0 };
const int timeout = conf_int(val) * 1000;
/* Prepare socket address. */
struct sockaddr_storage addr;
......@@ -154,8 +154,7 @@ int cmd_remote(const char *socket, const char *cmd, uint16_t rrt,
}
/* Send and free packet. */
struct timeval tv = tv_reply;
ret = net_dns_tcp_send(s, pkt->wire, pkt->size, &tv);
ret = net_dns_tcp_send(s, pkt->wire, pkt->size, timeout);
knot_pkt_free(&pkt);
/* Evaluate and wait for reply. */
......@@ -169,8 +168,7 @@ int cmd_remote(const char *socket, const char *cmd, uint16_t rrt,
/* Wait for reply. */
ret = KNOT_EOK;
while (ret == KNOT_EOK) {
tv = tv_reply;
ret = cmd_remote_reply(s, &tv);
ret = cmd_remote_reply(s, timeout);
if (ret != KNOT_EOK) {
if (ret != KNOT_ECONN) {
log_error("remote command reply: %s",
......
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