Skip to content

Commit

Permalink
Unlink server response message from the connection when the response …
Browse files Browse the repository at this point in the history
…is cached
  • Loading branch information
krizhanovsky committed Oct 4, 2015
1 parent 51e4ee5 commit bddf4f3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
11 changes: 9 additions & 2 deletions tempesta_fw/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ tfw_cache_copy_str(char **p, TdbVRec **trec, TfwStr *src, size_t tot_len)
TFW_DBG3("copy [%.*s](%u) to rec=%p(len=%u), p=%p"
" tot_len=%lu room=%d copied=%ld\n",
min(10, (int)src->len), (char *)src->ptr, src->len,
*trec, (*trec)->len, p, tot_len, room, copied);
*trec, (*trec)->len, *p, tot_len, room, copied);

if (!room) {
BUG_ON(tot_len < copied);
Expand Down Expand Up @@ -269,6 +269,7 @@ tfw_cache_copy_resp(struct work_struct *work)
TFW_ERR("Cache: cannot copy HTTP body\n");
goto err;
}
tot_len -= n;
ce->body_len += n;
});

Expand Down Expand Up @@ -317,8 +318,14 @@ tfw_cache_add(TfwHttpResp *resp, TfwHttpReq *req)
queue_work_on(tfw_cache_sched_work_cpu(numa_node_id()), cache_wq,
(struct work_struct *)cw);

/* Request isn't needed anymore, response is cached. */
/*
* Request isn't needed anymore, response is cached:
* free the first one and unlink from the connection the second one,
* so the server connection will create a new message when a new
* data arrives.
*/
tfw_http_conn_msg_free((TfwHttpMsg *)req);
tfw_http_conn_msg_unlink((TfwHttpMsg *)resp);
return;
out:
/* Now we don't need the request and the reponse anymore. */
Expand Down
8 changes: 4 additions & 4 deletions tempesta_fw/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ tfw_http_req_process(TfwConnection *conn, struct sk_buff *skb, unsigned int off)
BUG_ON(!conn->msg);
BUG_ON(off >= skb_len);

TFW_DBG2("Received %u client data bytes on conn=%p\n",
skb_len - off, conn);
TFW_DBG2("Received %u client data bytes on conn=%p msg=%p\n",
skb_len - off, conn, conn->msg);
/*
* Process pipelined requests in a loop
* until all data in the SKB is processed.
Expand Down Expand Up @@ -676,8 +676,8 @@ tfw_http_resp_process(TfwConnection *conn, struct sk_buff *skb,

BUG_ON(!hmresp);

TFW_DBG2("received %u server data bytes on conn=%p\n",
skb->len - off, conn);
TFW_DBG2("received %u server data bytes on conn=%p msg=%p\n",
skb->len - off, conn, hmresp);

r = ss_skb_process(skb, &data_off, tfw_http_parse_resp, hmresp);
hmresp->msg.len += data_off - off;
Expand Down
1 change: 0 additions & 1 deletion tempesta_fw/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ typedef struct {
#define FOR_EACH_HDR_FIELD_FROM(pos, end, msg, soff) \
__FOR_EACH_HDR_FIELD(pos, end, msg, soff, (msg)->h_tbl->off)


typedef void (*tfw_http_req_cache_cb_t)(TfwHttpReq *, TfwHttpResp *, void *);

/* Internal (parser) HTTP functions. */
Expand Down
12 changes: 9 additions & 3 deletions tempesta_fw/http_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,16 +669,22 @@ tfw_http_msg_write(TfwMsgIter *it, TfwHttpMsg *hm, const TfwStr *data)
return 0;
}

void
tfw_http_conn_msg_unlink(TfwHttpMsg *m)
{
if (m->conn && m->conn->msg == (TfwMsg *)m)
m->conn->msg = NULL;
}

void
tfw_http_msg_free(TfwHttpMsg *m)
{
TFW_DBG3("Free msg: %p\n", m);
TFW_DBG3("Free msg=%p\n", m);

if (!m)
return;

if (m->conn && m->conn->msg == (TfwMsg *)m)
m->conn->msg = NULL;
tfw_http_conn_msg_unlink(m);

while (1) {
/*
Expand Down
1 change: 1 addition & 0 deletions tempesta_fw/http_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ int tfw_http_msg_grow_hdr_tbl(TfwHttpMsg *hm);

TfwHttpMsg *tfw_http_msg_alloc(int type);
void tfw_http_msg_free(TfwHttpMsg *m);
void tfw_http_conn_msg_unlink(TfwHttpMsg *m);

#endif /* __TFW_HTTP_MSG_H__ */

0 comments on commit bddf4f3

Please sign in to comment.