++ New features:
+ 2008-01-05 Frédéric Bernon
+ * sys_arch.txt, api.h, api_lib.c, api_msg.h, api_msg.c, tcpip.c, sys.h, opt.h:
+ Introduce changes for task #7490 "Add return value to sys_mbox_post" with some
+ modifications in the sys_mbox api: sys_mbox_new take a "size" parameters which
+ indicate the number of pointers query by the mailbox. There is three defines
+ in opt.h to indicate sizes for tcpip::mbox, netconn::recvmbox, and for the
+ netconn::acceptmbox. Port maintainers, you can decide to just add this new
+ parameter in your implementation, but to ignore it to keep the previous behavior.
+ The new sys_mbox_trypost function return a value to know if the mailbox is
+ full or if the message is posted. Take a look to sys_arch.txt for more details.
+ This new function is used in tcpip_input (so, can be called in an interrupt
+ context since the function is not blocking), and in recv_udp and recv_raw.
+
2008-01-04 Frédéric Bernon, Simon Goldschmidt, Jonathan Larmour
* rawapi.txt, api.h, api_lib.c, api_msg.h, api_msg.c, sockets.c, tcp.h, tcp.c,
tcp_in.c, init.c, opt.h: rename backlog options with TCP_ prefix, limit the
Notice that lwIP implements a function with a similar name,
sys_sem_wait(), that uses the sys_arch_sem_wait() function.
-- sys_mbox_t sys_mbox_new(void)
+- sys_mbox_t sys_mbox_new(int size)
- Creates an empty mailbox.
+ Creates an empty mailbox for maximum "size" elements. Elements stored
+ in mailboxes are pointers. You have to define macros "_MBOX_SIZE"
+ in your lwipopts.h, or ignore this parameter in your implementation
+ and use a default size.
- void sys_mbox_free(sys_mbox_t mbox)
- void sys_mbox_post(sys_mbox_t mbox, void *msg)
- Posts the "msg" to the mailbox.
+ Posts the "msg" to the mailbox. This function have to block until
+ the "msg" is really posted.
+
+- err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg)
+
+ Try to post the "msg" to the mailbox. Returns ERR_MEM if this one
+ is full, else, ERR_OK if the "msg" is posted.
- u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout)
* NULL on memory error
*/
struct netconn*
-netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
- void (*callback)(struct netconn *, enum netconn_evt, u16_t len))
+netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_callback callback)
{
struct netconn *conn;
struct api_msg msg;
SYS_ARCH_INC(conn->recv_avail, p->tot_len);
/* Register event with callback */
API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
- sys_mbox_post(conn->recvmbox, buf);
+ if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) {
+ netbuf_delete(buf);
+ }
}
return 0; /* do not eat the packet */
SYS_ARCH_INC(conn->recv_avail, p->tot_len);
/* Register event with callback */
API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
- sys_mbox_post(conn->recvmbox, buf);
+ if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) {
+ netbuf_delete(buf);
+ return;
+ }
}
#endif /* LWIP_UDP */
/* Register event with callback */
API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
- sys_mbox_post(conn->acceptmbox, newconn);
+ if (sys_mbox_trypost(conn->acceptmbox, newconn) != ERR_OK) {
+ /** @todo call here a "netconn_free" */
+ LWIP_ASSERT("accept_function: not yet implemented!", 0);
+ return ERR_MEM;
+ }
return ERR_OK;
}
#endif /* LWIP_TCP */
* NULL on memory error
*/
struct netconn*
-netconn_alloc(enum netconn_type t,
- void (*callback)(struct netconn *, enum netconn_evt, u16_t len))
+netconn_alloc(enum netconn_type t, netconn_callback callback)
{
struct netconn *conn;
conn->type = t;
conn->pcb.tcp = NULL;
- if ((conn->mbox = sys_mbox_new()) == SYS_MBOX_NULL) {
+ if ((conn->mbox = sys_mbox_new(1)) == SYS_MBOX_NULL) {
memp_free(MEMP_NETCONN, conn);
return NULL;
}
- if ((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
+ if ((conn->recvmbox = sys_mbox_new(DEFAULT_RECVMBOX_SIZE)) == SYS_MBOX_NULL) {
sys_mbox_free(conn->mbox);
memp_free(MEMP_NETCONN, conn);
return NULL;
msg->conn->recvmbox = NULL;
}
if (msg->conn->acceptmbox == SYS_MBOX_NULL) {
- if ((msg->conn->acceptmbox = sys_mbox_new()) == SYS_MBOX_NULL) {
+ if ((msg->conn->acceptmbox = sys_mbox_new(DEFAULT_ACCEPTMBOX_SIZE)) == SYS_MBOX_NULL) {
msg->conn->err = ERR_MEM;
}
}
msg->type = TCPIP_MSG_INPKT;
msg->msg.inp.p = p;
msg->msg.inp.netif = inp;
- sys_mbox_post(mbox, msg);
+ if (sys_mbox_trypost(mbox, msg) != ERR_OK) {
+ memp_free(MEMP_TCPIP_MSG_INPKT, msg);
+ return ERR_MEM;
+ }
return ERR_OK;
}
return ERR_VAL;
tcpip_init_done = initfunc;
tcpip_init_done_arg = arg;
- mbox = sys_mbox_new();
+ mbox = sys_mbox_new(TCPIP_MBOX_SIZE);
#if LWIP_TCPIP_CORE_LOCKING
lock_tcpip_core = sys_sem_new(1);
#endif /* LWIP_TCPIP_CORE_LOCKING */
struct tcp_pcb;
struct udp_pcb;
struct raw_pcb;
+struct netconn;
+
+/** A callback prototype to inform about events for a netconn */
+typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len);
/** A netconn descriptor */
struct netconn {
u8_t write_delayed;
#endif /* LWIP_TCPIP_CORE_LOCKING */
/** A callback function that is informed about events for this netconn */
- void (* callback)(struct netconn *, enum netconn_evt, u16_t len);
+ netconn_callback callback;
};
/* Register an Network connection event */
#define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c)
struct
netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto,
- void (*callback)(struct netconn *, enum netconn_evt, u16_t len));
+ netconn_callback callback);
err_t netconn_delete (struct netconn *conn);
enum netconn_type netconn_type (struct netconn *conn);
void do_gethostbyname(void *arg);
#endif /* LWIP_DNS */
-struct netconn* netconn_alloc(
- enum netconn_type t,
- void (*callback)(struct netconn *, enum netconn_evt, u16_t len));
+struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
#ifdef __cplusplus
}
#define TCPIP_THREAD_PRIO 1
#endif
+/**
+ * TCPIP_MBOX_SIZE: The mailbox size for the tcpip thread messages
+ * The queue size value itself is platform-dependent, but is passed to
+ * sys_mbox_new() when tcpip_init is called.
+ */
+#ifndef TCPIP_MBOX_SIZE
+#define TCPIP_MBOX_SIZE 0
+#endif
+
/**
* SLIPIF_THREAD_NAME: The name assigned to the slipif_loop thread.
*/
#define DEFAULT_THREAD_PRIO 1
#endif
+/**
+ * DEFAULT_RECVMBOX_SIZE: The mailbox size for the incoming packets.
+ * The queue size value itself is platform-dependent, but is passed to
+ * sys_mbox_new() when the recvmbox is created.
+ */
+#ifndef DEFAULT_RECVMBOX_SIZE
+#define DEFAULT_RECVMBOX_SIZE 0
+#endif
+
+/**
+ * DEFAULT_ACCEPTMBOX_SIZE: The mailbox size for the incoming connections.
+ * The queue size value itself is platform-dependent, but is passed to
+ * sys_mbox_new() when the acceptmbox is created.
+ */
+#ifndef DEFAULT_ACCEPTMBOX_SIZE
+#define DEFAULT_ACCEPTMBOX_SIZE 0
+#endif
+
/*
----------------------------------------------
---------- Sequential layer options ----------
#define sys_sem_wait_timeout(s,t)
#define sys_arch_sem_wait(s,t)
#define sys_sem_free(s)
-#define sys_mbox_new() 0
+#define sys_mbox_new(s) 0
#define sys_mbox_fetch(m,d)
+#define sys_mbox_tryfetch(m,d)
#define sys_mbox_post(m,d)
+#define sys_mbox_trypost(m,d)
#define sys_mbox_free(m)
#define sys_thread_new(n,t,a,s,p)
*/
#define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT
+#include "lwip/err.h"
#include "arch/sys_arch.h"
typedef void (* sys_timeout_handler)(void *arg);
#endif
/* Mailbox functions. */
-sys_mbox_t sys_mbox_new(void);
+sys_mbox_t sys_mbox_new(int size);
void sys_mbox_post(sys_mbox_t mbox, void *msg);
+err_t sys_mbox_trypost(sys_mbox_t mbox, void *msg);
u32_t sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout);
#ifndef sys_arch_mbox_tryfetch /* Allow port to override with a macro */
u32_t sys_arch_mbox_tryfetch(sys_mbox_t mbox, void **msg);