net: http: Collect HTTP server connection information

If CONFIG_NET_DEBUG_HTTP_CONN is enabled, then start to collect
currently active HTTP connections to HTTP server.

This is only useful for debugging the HTTP connections.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2017-06-05 16:39:45 +03:00
commit ab51f67e17
3 changed files with 52 additions and 0 deletions

View file

@ -673,6 +673,10 @@ struct http_server_ctx {
/** Function that is called when data is sent to network. */
http_send_data_t send_data;
#if defined(CONFIG_NET_DEBUG_HTTP_CONN)
sys_snode_t node;
#endif
/** Network timeout */
s32_t timeout;
@ -767,6 +771,15 @@ struct http_server_ctx {
#endif /* CONFIG_HTTPS */
};
#if defined(CONFIG_NET_DEBUG_HTTP_CONN)
typedef void (*http_server_cb_t)(struct http_server_ctx *entry,
void *user_data);
void http_server_conn_foreach(http_server_cb_t cb, void *user_data);
#else
#define http_server_conn_foreach(...)
#endif /* CONFIG_NET_DEBUG_HTTP_CONN */
/**
* @brief Initialize user supplied HTTP context.
*

View file

@ -97,3 +97,10 @@ config NET_DEBUG_HTTP
depends on HTTP && NET_LOG
help
Enables HTTP output debug messages
config NET_DEBUG_HTTP_CONN
bool "Debug HTTP connections"
default n
depends on HTTP && NET_LOG
help
Enables HTTP connection tracking.

View file

@ -60,6 +60,33 @@ static void https_disable(struct http_server_ctx *ctx);
#define HTTP_STATUS_404_NF "HTTP/1.1 404 Not Found\r\n" \
"\r\n"
#if defined(CONFIG_NET_DEBUG_HTTP_CONN)
/** List of HTTP connections */
static sys_slist_t http_conn;
static void http_server_conn_add(struct http_server_ctx *ctx)
{
sys_slist_prepend(&http_conn, &ctx->node);
}
static void http_server_conn_del(struct http_server_ctx *ctx)
{
sys_slist_find_and_remove(&http_conn, &ctx->node);
}
void http_server_conn_foreach(http_server_cb_t cb, void *user_data)
{
struct http_server_ctx *ctx;
SYS_SLIST_FOR_EACH_CONTAINER(&http_conn, ctx, node) {
cb(ctx, user_data);
}
}
#else
#define http_server_conn_add(...)
#define http_server_conn_del(...)
#endif /* CONFIG_NET_DEBUG_HTTP_CONN */
static inline u16_t http_strlen(const char *str)
{
if (str) {
@ -131,6 +158,8 @@ static void req_timeout(struct k_work *work)
NET_DBG("Context %p request timeout", ctx);
net_context_unref(ctx->req.net_ctx);
http_server_conn_del(ctx);
}
static void pkt_sent(struct net_context *context,
@ -146,6 +175,7 @@ static void pkt_sent(struct net_context *context,
if (timeout == K_NO_WAIT) {
/* We can just close the context after the packet is sent. */
net_context_unref(context);
http_server_conn_del(ctx);
} else if (timeout > 0) {
NET_DBG("Context %p starting timer", ctx);
@ -405,6 +435,8 @@ static inline void new_client(struct http_server_ctx *http_ctx,
sprint_ipaddr(buf, sizeof(buf), addr),
net_ctx);
#endif /* CONFIG_NET_DEBUG_HTTP */
http_server_conn_add(http_ctx);
}
static inline void new_server(struct http_server_ctx *ctx,