net: Add functions to return connection status needed in TCP

These are internal functions needed when initiating a TCP
connection.

Change-Id: Ide5d59ac9854ec8bdea3baa97b3cde3ffa6a5e0f
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2016-04-05 10:47:05 +03:00
commit 662ce340be
3 changed files with 88 additions and 0 deletions

View file

@ -143,6 +143,19 @@ int net_recv(struct net_buf *buf);
void net_context_init(void);
/**
* @brief Get current status of the TCP connection.
*
* @details Application can call this to get the current status
* of TCP connection. The returned value maps to errno values.
* Value 0 means ok. For UDP context 0 is always returned.
*
* @param context Network context
*
* @return 0 if ok, < 0 connection status
*/
int net_context_get_connection_status(struct net_context *context);
#ifdef __cplusplus
}
#endif

View file

@ -84,6 +84,15 @@
#include <string.h>
/* Need to set the connection status in context when TCP connection is
* established.
*/
extern void net_context_set_connection_status(struct net_context *context,
int status);
void *net_context_get_internal_connection(struct net_context *context);
void net_context_set_internal_connection(struct net_context *context,
void *conn);
/*---------------------------------------------------------------------------*/
/* For Debug, logging, statistics */
/*---------------------------------------------------------------------------*/

View file

@ -482,3 +482,69 @@ void net_context_set_receiver_registered(struct net_context *context)
context->receiver_registered = true;
}
int net_context_get_connection_status(struct net_context *context)
{
if (!context) {
return -ENOENT;
}
#if !defined(CONFIG_NETWORKING_WITH_TCP)
return 0;
#else
if (context->tuple.ip_proto == IPPROTO_TCP) {
return context->connection_status;
} else {
return 0;
}
#endif
}
void net_context_set_connection_status(struct net_context *context,
int status)
{
#if !defined(CONFIG_NETWORKING_WITH_TCP)
return;
#else
if (!context) {
return;
}
if (context->tuple.ip_proto == IPPROTO_TCP) {
context->connection_status = status;
}
#endif
}
void *net_context_get_internal_connection(struct net_context *context)
{
#if !defined(CONFIG_NETWORKING_WITH_TCP)
return NULL;
#else
if (!context) {
return NULL;
}
if (context->tuple.ip_proto == IPPROTO_TCP) {
return context->conn;
} else {
return NULL;
}
#endif
}
void net_context_set_internal_connection(struct net_context *context,
void *conn)
{
#if !defined(CONFIG_NETWORKING_WITH_TCP)
return;
#else
if (!context) {
return;
}
if (context->tuple.ip_proto == IPPROTO_TCP) {
context->conn = conn;
}
#endif
}