net: http: Add context net_buf pool support to HTTP client
This commit adds http_client_set_net_pkt_pool() function that allows caller to define net_buf pool that is used when sending a TCP packet. This is needed for those technologies like Bluetooth or 802.15.4 which compress the IPv6 header during send. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
a4cfee8fe6
commit
1c07ead104
|
@ -200,6 +200,18 @@ struct http_client_ctx {
|
|||
/** Server name */
|
||||
const char *server;
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
/** Network packet (net_pkt) memory pool for network contexts attached
|
||||
* to this http_client context.
|
||||
*/
|
||||
net_pkt_get_slab_func_t tx_slab;
|
||||
|
||||
/** Network data net_buf pool for network contexts attached to this
|
||||
* http_client context.
|
||||
*/
|
||||
net_pkt_get_pool_func_t data_pool;
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
|
||||
/** Is this instance HTTPS or not.
|
||||
*/
|
||||
bool is_https;
|
||||
|
@ -580,6 +592,28 @@ int https_client_init(struct http_client_ctx *http_ctx,
|
|||
* @param http_ctx HTTP context.
|
||||
*/
|
||||
void http_client_release(struct http_client_ctx *http_ctx);
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
/**
|
||||
* @brief Configure the net_pkt pool for this context.
|
||||
*
|
||||
* @details Use of this function is optional and if the pools are not set,
|
||||
* then the default TX and DATA pools are used. This needs to be called before
|
||||
* http init function, as that will setup net_context which needs the net_pkt
|
||||
* pool information.
|
||||
*
|
||||
* @param ctx HTTP client context
|
||||
* @param tx_slab Function which is used when allocating TX network packet.
|
||||
* This can be NULL in which case default TX memory pool is used.
|
||||
* @param data_pool Function which is used when allocating data network buffer.
|
||||
* This can be NULL in which case default DATA net_buf pool is used.
|
||||
*/
|
||||
int http_client_set_net_pkt_pool(struct http_client_ctx *ctx,
|
||||
net_pkt_get_slab_func_t tx_slab,
|
||||
net_pkt_get_pool_func_t data_pool);
|
||||
#else
|
||||
#define http_client_set_net_pkt_pool(...)
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
#endif /* CONFIG_HTTP_CLIENT */
|
||||
|
||||
#if defined(CONFIG_HTTP_SERVER)
|
||||
|
|
|
@ -563,6 +563,8 @@ static int tcp_connect(struct http_client_ctx *ctx)
|
|||
return ret;
|
||||
}
|
||||
|
||||
net_context_setup_pools(ctx->tcp.ctx, ctx->tx_slab, ctx->data_pool);
|
||||
|
||||
ret = net_context_bind(ctx->tcp.ctx, &ctx->tcp.local,
|
||||
addrlen);
|
||||
if (ret) {
|
||||
|
@ -1732,3 +1734,15 @@ void http_client_release(struct http_client_ctx *ctx)
|
|||
*/
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
|
||||
int http_client_set_net_pkt_pool(struct http_client_ctx *ctx,
|
||||
net_pkt_get_slab_func_t tx_slab,
|
||||
net_pkt_get_pool_func_t data_pool)
|
||||
{
|
||||
ctx->tx_slab = tx_slab;
|
||||
ctx->data_pool = data_pool;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
|
||||
|
|
Loading…
Reference in a new issue