samples: net: http: client: Use net_buf context pool for TX

If CONFIG_NET_CONTEXT_NET_PKT_POOL is defined, which is the
default for Bluetooth, then create the pool and use it when
sending network packets. This is needed when trying to send
TCP packets using Bluetooth IPSP.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2017-07-28 15:32:05 +03:00
parent 1c07ead104
commit c724a5730c
2 changed files with 50 additions and 0 deletions

View file

@ -34,6 +34,29 @@ static u8_t result[RESULT_BUF_SIZE];
*/
static struct http_client_ctx http_ctx;
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
NET_PKT_TX_SLAB_DEFINE(http_cli_tx, 15);
NET_PKT_DATA_POOL_DEFINE(http_cli_data, 30);
static struct k_mem_slab *tx_slab(void)
{
return &http_cli_tx;
}
static struct net_buf_pool *data_pool(void)
{
return &http_cli_data;
}
#else
#if defined(CONFIG_NET_L2_BLUETOOTH)
#error "TCP connections over Bluetooth need CONFIG_NET_CONTEXT_NET_PKT_POOL "\
"defined."
#endif /* CONFIG_NET_L2_BLUETOOTH */
#define tx_slab NULL
#define data_pool NULL
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
struct waiter {
struct http_client_ctx *ctx;
struct k_sem wait;
@ -313,6 +336,8 @@ void main(void)
panic(NULL);
}
http_client_set_net_pkt_pool(&http_ctx, tx_slab, data_pool);
ret = do_sync_reqs(&http_ctx, MAX_ITERATIONS);
if (ret < 0) {
goto out;

View file

@ -45,6 +45,29 @@ K_MEM_POOL_DEFINE(ssl_rx_pool, 4, 64, RX_FIFO_DEPTH, 4);
*/
static struct http_client_ctx https_ctx;
#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL)
NET_PKT_TX_SLAB_DEFINE(http_cli_tls_tx, 15);
NET_PKT_DATA_POOL_DEFINE(http_cli_tls_data, 30);
static struct k_mem_slab *tx_slab(void)
{
return &http_cli_tls_tx;
}
static struct net_buf_pool *data_pool(void)
{
return &http_cli_tls_data;
}
#else
#if defined(CONFIG_NET_L2_BLUETOOTH)
#error "TCP connections over Bluetooth need CONFIG_NET_CONTEXT_NET_PKT_POOL "\
"defined."
#endif /* CONFIG_NET_L2_BLUETOOTH */
#define tx_slab NULL
#define data_pool NULL
#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */
struct waiter {
struct http_client_ctx *ctx;
struct k_sem wait;
@ -379,6 +402,8 @@ void main(void)
panic(NULL);
}
http_client_set_net_pkt_pool(&https_ctx, tx_slab, data_pool);
ret = do_sync_reqs(&https_ctx, MAX_ITERATIONS);
if (ret < 0) {
failure = true;