mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
Decouple tcpip.c/tcpip_priv.h from netconn API
This commit is contained in:
parent
18bb74e5c5
commit
c65eca58c9
@ -49,6 +49,7 @@
|
|||||||
#include "lwip/ip.h"
|
#include "lwip/ip.h"
|
||||||
#include "lwip/raw.h"
|
#include "lwip/raw.h"
|
||||||
#include "lwip/udp.h"
|
#include "lwip/udp.h"
|
||||||
|
#include "lwip/priv/api_msg.h"
|
||||||
#include "lwip/priv/tcp_priv.h"
|
#include "lwip/priv/tcp_priv.h"
|
||||||
#include "lwip/priv/tcpip_priv.h"
|
#include "lwip/priv/tcpip_priv.h"
|
||||||
|
|
||||||
@ -62,6 +63,34 @@
|
|||||||
|
|
||||||
static err_t netconn_close_shutdown(struct netconn *conn, u8_t how);
|
static err_t netconn_close_shutdown(struct netconn *conn, u8_t how);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the lower part of a netconn_* function
|
||||||
|
* This function is then running in the thread context
|
||||||
|
* of tcpip_thread and has exclusive access to lwIP core code.
|
||||||
|
*
|
||||||
|
* @param apimsg a struct containing the function to call and its parameters
|
||||||
|
* @return ERR_OK if the function was called, another err_t if not
|
||||||
|
*/
|
||||||
|
static err_t
|
||||||
|
tcpip_apimsg(struct api_msg *apimsg)
|
||||||
|
{
|
||||||
|
#ifdef LWIP_DEBUG
|
||||||
|
/* catch functions that don't set err */
|
||||||
|
apimsg->msg.err = ERR_VAL;
|
||||||
|
#endif
|
||||||
|
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||||
|
apimsg->msg.op_completed_sem = LWIP_NETCONN_THREAD_SEM_GET();
|
||||||
|
LWIP_ASSERT("netconn semaphore not initialized",
|
||||||
|
sys_sem_valid(apimsg->msg.op_completed_sem));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (tcpip_send_api_msg(apimsg->function, &apimsg->msg, LWIP_API_MSG_SEM(&apimsg->msg)) == ERR_OK) {
|
||||||
|
return apimsg->msg.err;
|
||||||
|
}
|
||||||
|
return ERR_VAL;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new netconn (of a specific type) that has a callback function.
|
* Create a new netconn (of a specific type) that has a callback function.
|
||||||
* The corresponding pcb is also created.
|
* The corresponding pcb is also created.
|
||||||
|
@ -307,11 +307,10 @@ tcpip_untimeout(sys_timeout_handler h, void *arg)
|
|||||||
*
|
*
|
||||||
* @param fn Function to be called from TCPIP thread
|
* @param fn Function to be called from TCPIP thread
|
||||||
* @param apimsg argument to API function
|
* @param apimsg argument to API function
|
||||||
* @param sem Semaphore to wait on
|
|
||||||
* @return ERR_OK if the function was called, another err_t if not
|
* @return ERR_OK if the function was called, another err_t if not
|
||||||
*/
|
*/
|
||||||
err_t
|
err_t
|
||||||
tcpip_send_api_msg(api_msg_fn fn, void *apimsg, sys_sem_t* sem)
|
tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem)
|
||||||
{
|
{
|
||||||
if (sys_mbox_valid_val(mbox)) {
|
if (sys_mbox_valid_val(mbox)) {
|
||||||
TCPIP_MSG_VAR_DECLARE(msg);
|
TCPIP_MSG_VAR_DECLARE(msg);
|
||||||
@ -328,35 +327,6 @@ tcpip_send_api_msg(api_msg_fn fn, void *apimsg, sys_sem_t* sem)
|
|||||||
return ERR_VAL;
|
return ERR_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if LWIP_NETCONN || LWIP_SOCKET
|
|
||||||
/**
|
|
||||||
* Call the lower part of a netconn_* function
|
|
||||||
* This function is then running in the thread context
|
|
||||||
* of tcpip_thread and has exclusive access to lwIP core code.
|
|
||||||
*
|
|
||||||
* @param apimsg a struct containing the function to call and its parameters
|
|
||||||
* @return ERR_OK if the function was called, another err_t if not
|
|
||||||
*/
|
|
||||||
err_t
|
|
||||||
tcpip_apimsg(struct api_msg *apimsg)
|
|
||||||
{
|
|
||||||
#ifdef LWIP_DEBUG
|
|
||||||
/* catch functions that don't set err */
|
|
||||||
apimsg->msg.err = ERR_VAL;
|
|
||||||
#endif
|
|
||||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
|
||||||
apimsg->msg.op_completed_sem = LWIP_NETCONN_THREAD_SEM_GET();
|
|
||||||
LWIP_ASSERT("netconn semaphore not initialized",
|
|
||||||
sys_sem_valid(apimsg->msg.op_completed_sem));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (tcpip_send_api_msg(apimsg->function, &apimsg->msg, LWIP_API_MSG_SEM(&apimsg->msg)) == ERR_OK) {
|
|
||||||
return apimsg->msg.err;
|
|
||||||
}
|
|
||||||
return ERR_VAL;
|
|
||||||
}
|
|
||||||
#endif /* LWIP_NETCONN || LWIP_SOCKET */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate a structure for a static callback message and initialize it.
|
* Allocate a structure for a static callback message and initialize it.
|
||||||
* This is intended to be used to send "static" messages from interrupt context.
|
* This is intended to be used to send "static" messages from interrupt context.
|
||||||
|
@ -186,6 +186,35 @@ struct dns_api_msg {
|
|||||||
};
|
};
|
||||||
#endif /* LWIP_DNS */
|
#endif /* LWIP_DNS */
|
||||||
|
|
||||||
|
#if LWIP_TCPIP_CORE_LOCKING
|
||||||
|
#ifdef LWIP_DEBUG
|
||||||
|
#define TCIP_APIMSG_SET_ERR(m, e) (m)->msg.err = e /* catch functions that don't set err */
|
||||||
|
#else
|
||||||
|
#define TCIP_APIMSG_SET_ERR(m, e)
|
||||||
|
#endif
|
||||||
|
#if LWIP_NETCONN_SEM_PER_THREAD
|
||||||
|
#define TCPIP_APIMSG_SET_SEM(m) ((m)->msg.op_completed_sem = LWIP_NETCONN_THREAD_SEM_GET())
|
||||||
|
#else
|
||||||
|
#define TCPIP_APIMSG_SET_SEM(m)
|
||||||
|
#endif
|
||||||
|
#define TCPIP_APIMSG_NOERR(m,f) do { \
|
||||||
|
TCIP_APIMSG_SET_ERR(m, ERR_VAL); \
|
||||||
|
TCPIP_APIMSG_SET_SEM(m); \
|
||||||
|
LOCK_TCPIP_CORE(); \
|
||||||
|
f(&((m)->msg)); \
|
||||||
|
UNLOCK_TCPIP_CORE(); \
|
||||||
|
} while(0)
|
||||||
|
#define TCPIP_APIMSG(m,f,e) do { \
|
||||||
|
TCPIP_APIMSG_NOERR(m,f); \
|
||||||
|
(e) = (m)->msg.err; \
|
||||||
|
} while(0)
|
||||||
|
#define TCPIP_APIMSG_ACK(m) NETCONN_SET_SAFE_ERR((m)->conn, (m)->err)
|
||||||
|
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
#define TCPIP_APIMSG_NOERR(m,f) do { (m)->function = f; tcpip_apimsg(m); } while(0)
|
||||||
|
#define TCPIP_APIMSG(m,f,e) do { (m)->function = f; (e) = tcpip_apimsg(m); } while(0)
|
||||||
|
#define TCPIP_APIMSG_ACK(m) do { NETCONN_SET_SAFE_ERR((m)->conn, (m)->err); sys_sem_signal(LWIP_API_MSG_SEM(m)); } while(0)
|
||||||
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
void lwip_netconn_do_newconn (void *m);
|
void lwip_netconn_do_newconn (void *m);
|
||||||
void lwip_netconn_do_delconn (void *m);
|
void lwip_netconn_do_delconn (void *m);
|
||||||
void lwip_netconn_do_bind (void *m);
|
void lwip_netconn_do_bind (void *m);
|
||||||
|
@ -37,9 +37,7 @@
|
|||||||
#if !NO_SYS /* don't build if not configured for use in lwipopts.h */
|
#if !NO_SYS /* don't build if not configured for use in lwipopts.h */
|
||||||
|
|
||||||
#include "lwip/tcpip.h"
|
#include "lwip/tcpip.h"
|
||||||
#include "lwip/priv/api_msg.h"
|
|
||||||
#include "lwip/pbuf.h"
|
#include "lwip/pbuf.h"
|
||||||
#include "lwip/api.h"
|
|
||||||
#include "lwip/sys.h"
|
#include "lwip/sys.h"
|
||||||
#include "lwip/timers.h"
|
#include "lwip/timers.h"
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
@ -59,37 +57,11 @@ extern "C" {
|
|||||||
extern sys_mutex_t lock_tcpip_core;
|
extern sys_mutex_t lock_tcpip_core;
|
||||||
#define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core)
|
#define LOCK_TCPIP_CORE() sys_mutex_lock(&lock_tcpip_core)
|
||||||
#define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core)
|
#define UNLOCK_TCPIP_CORE() sys_mutex_unlock(&lock_tcpip_core)
|
||||||
#ifdef LWIP_DEBUG
|
|
||||||
#define TCIP_APIMSG_SET_ERR(m, e) (m)->msg.err = e /* catch functions that don't set err */
|
|
||||||
#else
|
|
||||||
#define TCIP_APIMSG_SET_ERR(m, e)
|
|
||||||
#endif
|
|
||||||
#if LWIP_NETCONN_SEM_PER_THREAD
|
|
||||||
#define TCPIP_APIMSG_SET_SEM(m) ((m)->msg.op_completed_sem = LWIP_NETCONN_THREAD_SEM_GET())
|
|
||||||
#else
|
|
||||||
#define TCPIP_APIMSG_SET_SEM(m)
|
|
||||||
#endif
|
|
||||||
#define TCPIP_APIMSG_NOERR(m,f) do { \
|
|
||||||
TCIP_APIMSG_SET_ERR(m, ERR_VAL); \
|
|
||||||
TCPIP_APIMSG_SET_SEM(m); \
|
|
||||||
LOCK_TCPIP_CORE(); \
|
|
||||||
f(&((m)->msg)); \
|
|
||||||
UNLOCK_TCPIP_CORE(); \
|
|
||||||
} while(0)
|
|
||||||
#define TCPIP_APIMSG(m,f,e) do { \
|
|
||||||
TCPIP_APIMSG_NOERR(m,f); \
|
|
||||||
(e) = (m)->msg.err; \
|
|
||||||
} while(0)
|
|
||||||
#define TCPIP_APIMSG_ACK(m) NETCONN_SET_SAFE_ERR((m)->conn, (m)->err)
|
|
||||||
#else /* LWIP_TCPIP_CORE_LOCKING */
|
#else /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
#define LOCK_TCPIP_CORE()
|
#define LOCK_TCPIP_CORE()
|
||||||
#define UNLOCK_TCPIP_CORE()
|
#define UNLOCK_TCPIP_CORE()
|
||||||
#define TCPIP_APIMSG_NOERR(m,f) do { (m)->function = f; tcpip_apimsg(m); } while(0)
|
|
||||||
#define TCPIP_APIMSG(m,f,e) do { (m)->function = f; (e) = tcpip_apimsg(m); } while(0)
|
|
||||||
#define TCPIP_APIMSG_ACK(m) do { NETCONN_SET_SAFE_ERR((m)->conn, (m)->err); sys_sem_signal(LWIP_API_MSG_SEM(m)); } while(0)
|
|
||||||
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
#endif /* LWIP_TCPIP_CORE_LOCKING */
|
||||||
|
|
||||||
|
|
||||||
#if LWIP_MPU_COMPATIBLE
|
#if LWIP_MPU_COMPATIBLE
|
||||||
#define API_VAR_REF(name) (*(name))
|
#define API_VAR_REF(name) (*(name))
|
||||||
#define API_VAR_DECLARE(type, name) type * name
|
#define API_VAR_DECLARE(type, name) type * name
|
||||||
@ -122,12 +94,7 @@ extern sys_mutex_t lock_tcpip_core;
|
|||||||
#define API_EXPR_DEREF(expr) *(expr)
|
#define API_EXPR_DEREF(expr) *(expr)
|
||||||
#endif /* LWIP_MPU_COMPATIBLE */
|
#endif /* LWIP_MPU_COMPATIBLE */
|
||||||
|
|
||||||
#if LWIP_NETCONN || LWIP_SOCKET
|
err_t tcpip_send_api_msg(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem);
|
||||||
err_t tcpip_apimsg(struct api_msg *apimsg);
|
|
||||||
#endif /* LWIP_NETCONN || LWIP_SOCKET */
|
|
||||||
|
|
||||||
typedef void (*api_msg_fn)(void *msg);
|
|
||||||
err_t tcpip_send_api_msg(api_msg_fn fn, void *apimsg, sys_sem_t* sem);
|
|
||||||
|
|
||||||
enum tcpip_msg_type {
|
enum tcpip_msg_type {
|
||||||
TCPIP_MSG_API,
|
TCPIP_MSG_API,
|
||||||
@ -144,7 +111,7 @@ struct tcpip_msg {
|
|||||||
enum tcpip_msg_type type;
|
enum tcpip_msg_type type;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
api_msg_fn function;
|
tcpip_callback_fn function;
|
||||||
void* msg;
|
void* msg;
|
||||||
} api;
|
} api;
|
||||||
struct {
|
struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user