MINOR: mux-quic: return qcs instance from qcc_get_qcs

Refactoring on qcc_get_qcs : return the qcs instance instead of the tree
node. This is useful to hide some eb64_entry macros for better
readability.
This commit is contained in:
Amaury Denoyelle 2022-03-29 14:57:19 +02:00
parent 8d5def0bab
commit 50742294f5
3 changed files with 17 additions and 17 deletions

View File

@ -68,7 +68,7 @@ static inline int quic_stream_is_bidi(uint64_t id)
return !quic_stream_is_uni(id);
}
struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id);
struct qcs *qcc_get_qcs(struct qcc *qcc, uint64_t id);
/* Install the <app_ops> applicative layer of a QUIC connection on mux <qcc>.
* Returns 0 on success else non-zero.

View File

@ -200,11 +200,12 @@ void qcs_notify_send(struct qcs *qcs)
* several streams, depending on the already open ones.
* Return this node if succeeded, NULL if not.
*/
struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id)
struct qcs *qcc_get_qcs(struct qcc *qcc, uint64_t id)
{
unsigned int strm_type;
int64_t sub_id;
struct eb64_node *strm_node;
struct qcs *qcs = NULL;
strm_type = id & QCS_ID_TYPE_MASK;
sub_id = id >> QCS_ID_TYPE_SHIFT;
@ -216,6 +217,7 @@ struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id)
/* unknown stream id */
goto out;
}
qcs = eb64_entry(strm_node, struct qcs, by_id);
}
else {
/* Remote streams. */
@ -244,29 +246,31 @@ struct eb64_node *qcc_get_qcs(struct qcc *qcc, uint64_t id)
* So, let's "open" these streams.
*/
int64_t i;
struct qcs *qcs;
struct qcs *tmp_qcs;
qcs = NULL;
tmp_qcs = NULL;
for (i = largest_id + 1; i <= sub_id; i++) {
uint64_t id = (i << QCS_ID_TYPE_SHIFT) | strm_type;
enum qcs_type type = id & QCS_ID_DIR_BIT ? QCS_CLT_UNI : QCS_CLT_BIDI;
qcs = qcs_new(qcc, id, type);
if (!qcs) {
tmp_qcs = qcs_new(qcc, id, type);
if (!tmp_qcs) {
/* allocation failure */
goto out;
}
qcc->strms[qcs_type].largest_id = i;
}
if (qcs)
strm_node = &qcs->by_id;
if (tmp_qcs)
qcs = tmp_qcs;
}
else {
strm_node = eb64_lookup(strms, id);
if (strm_node)
qcs = eb64_entry(strm_node, struct qcs, by_id);
}
}
return strm_node;
return qcs;
out:
return NULL;
@ -286,18 +290,16 @@ int qcc_recv(struct qcc *qcc, uint64_t id, uint64_t len, uint64_t offset,
char fin, char *data, struct qcs **out_qcs)
{
struct qcs *qcs;
struct eb64_node *strm_node;
size_t total, diff;
TRACE_ENTER(QMUX_EV_QCC_RECV, qcc->conn);
strm_node = qcc_get_qcs(qcc, id);
if (!strm_node) {
qcs = qcc_get_qcs(qcc, id);
if (!qcs) {
TRACE_DEVEL("leaving on stream not found", QMUX_EV_QCC_RECV|QMUX_EV_QCC_NQCS, qcc->conn, NULL, &id);
return 1;
}
qcs = eb64_entry(&strm_node->node, struct qcs, by_id);
*out_qcs = qcs;
if (offset > qcs->rx.offset)

View File

@ -2165,17 +2165,15 @@ static int qc_handle_uni_strm_frm(struct quic_rx_packet *pkt,
struct quic_conn *qc)
{
struct qcs *strm;
struct eb64_node *strm_node;
struct quic_rx_strm_frm *frm;
size_t strm_frm_len;
strm_node = qcc_get_qcs(qc->qcc, strm_frm->id);
if (!strm_node) {
strm = qcc_get_qcs(qc->qcc, strm_frm->id);
if (!strm) {
TRACE_PROTO("Stream not found", QUIC_EV_CONN_PSTRM, qc);
return 0;
}
strm = eb64_entry(&strm_node->node, struct qcs, by_id);
if (strm_frm->offset.key < strm->rx.offset) {
size_t diff;