Commit 7171fb37 authored by Marek Vavruša's avatar Marek Vavruša

requestor: generate query from processor if not provided

parent cd6673c4
......@@ -448,8 +448,9 @@ int knot_pkt_put_question(knot_pkt_t *pkt, const knot_dname_t *qname, uint16_t q
/* Check size limits. */
size_t question_len = 2 * sizeof(uint16_t) + qname_len;
if (qname_len < 0 || pkt->size + question_len > pkt->max_size)
if (qname_len < 0 || pkt->size + question_len > pkt->max_size) {
return KNOT_ESPACE;
}
/* Copy QTYPE & QCLASS */
dst += qname_len;
......
......@@ -101,10 +101,19 @@ static int request_send(struct knot_request *request, const struct timeval *time
return KNOT_ECONNREFUSED;
}
/* Send query. */
/* Send query, construct if not exists. */
knot_pkt_t *query = request->data.query;
ret = tcp_send_msg(request->data.fd, query->wire, query->size);
if (ret != query->size) {
uint8_t *wire = request->pkt_buf;
uint16_t wire_len = KNOT_WIRE_MAX_PKTSIZE;
if (query) {
wire = query->wire;
wire_len = query->size;
} else {
request->state = knot_process_out(wire, &wire_len, &request->process);
}
ret = tcp_send_msg(request->data.fd, wire, wire_len);
if (ret != wire_len) {
return KNOT_ECONN;
}
......@@ -151,7 +160,7 @@ struct knot_request *knot_requestor_make(struct knot_requestor *requestor,
const struct sockaddr *src,
knot_pkt_t *query)
{
if (requestor == NULL || query == NULL || dst == NULL) {
if (requestor == NULL || dst == NULL) {
return NULL;
}
......@@ -187,14 +196,18 @@ int knot_requestor_enqueue(struct knot_requestor *requestor, struct knot_request
/* Form a pending request. */
request->data.fd = fd;
request->state = NS_PROC_FULL; /* We have a query to be sent. */
if (requestor->mm != NULL) {
memcpy(&request->process.mm, requestor->mm, sizeof(mm_ctx_t));
} else {
mm_ctx_init(&request->process.mm);
}
knot_process_begin(&request->process, param, requestor->module);
request->state = knot_process_begin(&request->process, param, requestor->module);
/* We have a query to be sent. */
if (request->data.query) {
request->state = NS_PROC_FULL;
}
add_tail(&requestor->pending, &request->data.node);
......
......@@ -47,21 +47,21 @@ struct knot_request_data {
* \param module Response processing module.
* \param mm Memory context.
*/
void knot_requestor_init(struct knot_requestor *knot_requestor, const knot_process_module_t *module, mm_ctx_t *mm);
void knot_requestor_init(struct knot_requestor *requestor, const knot_process_module_t *module, mm_ctx_t *mm);
/*!
* \brief Clear the requestor structure and close pending queries.
*
* \param requestor Requestor instance.
*/
void knot_requestor_clear(struct knot_requestor *knot_requestor);
void knot_requestor_clear(struct knot_requestor *requestor);
/*!
* \brief Return true if there are no pending queries.
*
* \param requestor Requestor instance.
*/
bool knot_requestor_finished(struct knot_requestor *knot_requestor);
bool knot_requestor_finished(struct knot_requestor *requestor);
/*!
......@@ -74,7 +74,7 @@ bool knot_requestor_finished(struct knot_requestor *knot_requestor);
*
* \return Prepared request or NULL in case of error.
*/
struct knot_request *knot_requestor_make(struct knot_requestor *knot_requestor,
struct knot_request *knot_requestor_make(struct knot_requestor *requestor,
const struct sockaddr *addr,
const struct sockaddr *src,
knot_pkt_t *query);
......@@ -91,7 +91,7 @@ struct knot_request *knot_requestor_make(struct knot_requestor *knot_requestor,
*
* \return KNOT_EOK or error
*/
int knot_requestor_enqueue(struct knot_requestor *knot_requestor, struct knot_request *knot_request, void *param);
int knot_requestor_enqueue(struct knot_requestor *requestor, struct knot_request *request, void *param);
/*!
* \brief Close first pending request.
......@@ -100,7 +100,7 @@ int knot_requestor_enqueue(struct knot_requestor *knot_requestor, struct knot_re
*
* \return KNOT_EOK or error
*/
int knot_requestor_dequeue(struct knot_requestor *knot_requestor);
int knot_requestor_dequeue(struct knot_requestor *requestor);
/*!
* \brief Execute next pending query (FIFO).
......@@ -110,4 +110,4 @@ int knot_requestor_dequeue(struct knot_requestor *knot_requestor);
*
* \return KNOT_EOK or error
*/
int knot_requestor_exec(struct knot_requestor *knot_requestor, struct timeval *timeout);
int knot_requestor_exec(struct knot_requestor *requestor, struct timeval *timeout);
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