From 527d18a52629e7ea9eb10934d8f1d3e8f74e1c0c Mon Sep 17 00:00:00 2001 From: kieranm Date: Wed, 28 Feb 2007 14:15:43 +0000 Subject: [PATCH] 2007-02-28 Kieran Mansley (based on patch from Simon Goldschmidt) * api_lib.c, tcpip.c, memp.c, memp.h: make API msg structs allocated on the stack and remove the API msg type from memp --- CHANGELOG | 4 +++ src/api/api_lib.c | 75 +++++++++++------------------------------ src/api/tcpip.c | 1 - src/core/memp.c | 3 -- src/include/lwip/memp.h | 1 - 5 files changed, 24 insertions(+), 60 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9d84347c..316a895f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -27,6 +27,10 @@ HISTORY ++ New features: + 2007-02-28 Kieran Mansley (based on patch from Simon Goldschmidt) + * api_lib.c, tcpip.c, memp.c, memp.h: make API msg structs allocated + on the stack and remove the API msg type from memp + 2007-02-26 Jonathan Larmour (based on patch from Simon Goldschmidt) * sockets.h, sockets.c: Move socket initialization to new lwip_socket_init() function. diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 0d7dd206..1e536c89 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -201,7 +201,8 @@ netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto, void (*callback)(struct netconn *, enum netconn_evt, u16_t len)) { struct netconn *conn; - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; conn = memp_malloc(MEMP_NETCONN); if (conn == NULL) { @@ -228,17 +229,11 @@ netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto, conn->callback = callback; conn->recv_avail = 0; - if((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - memp_free(MEMP_NETCONN, conn); - return NULL; - } - msg->type = API_MSG_NEWCONN; msg->msg.msg.bc.port = proto; /* misusing the port field */ msg->msg.conn = conn; api_msg_post(msg); sys_mbox_fetch(conn->mbox, NULL); - memp_free(MEMP_API_MSG, msg); if ( conn->err != ERR_OK ) { memp_free(MEMP_NETCONN, conn); @@ -266,22 +261,18 @@ netconn *netconn_new_with_callback(enum netconn_type t, err_t netconn_delete(struct netconn *conn) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; void *mem; if (conn == NULL) { return ERR_OK; } - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - return ERR_MEM; - } - msg->type = API_MSG_DELCONN; msg->msg.conn = conn; api_msg_post(msg); sys_mbox_fetch(conn->mbox, NULL); - memp_free(MEMP_API_MSG, msg); /* Drain the recvmbox. */ if (conn->recvmbox != SYS_MBOX_NULL) { @@ -378,7 +369,8 @@ err_t netconn_bind(struct netconn *conn, struct ip_addr *addr, u16_t port) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; if (conn == NULL) { return ERR_VAL; @@ -391,16 +383,12 @@ netconn_bind(struct netconn *conn, struct ip_addr *addr, } } - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - return (conn->err = ERR_MEM); - } msg->type = API_MSG_BIND; msg->msg.conn = conn; msg->msg.msg.bc.ipaddr = addr; msg->msg.msg.bc.port = port; api_msg_post(msg); sys_mbox_fetch(conn->mbox, NULL); - memp_free(MEMP_API_MSG, msg); return conn->err; } @@ -409,7 +397,8 @@ err_t netconn_connect(struct netconn *conn, struct ip_addr *addr, u16_t port) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; if (conn == NULL) { return ERR_VAL; @@ -422,36 +411,29 @@ netconn_connect(struct netconn *conn, struct ip_addr *addr, } } - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - return ERR_MEM; - } msg->type = API_MSG_CONNECT; msg->msg.conn = conn; msg->msg.msg.bc.ipaddr = addr; msg->msg.msg.bc.port = port; api_msg_post(msg); sys_mbox_fetch(conn->mbox, NULL); - memp_free(MEMP_API_MSG, msg); return conn->err; } err_t netconn_disconnect(struct netconn *conn) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; if (conn == NULL) { return ERR_VAL; } - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - return ERR_MEM; - } msg->type = API_MSG_DISCONNECT; msg->msg.conn = conn; api_msg_post(msg); sys_mbox_fetch(conn->mbox, NULL); - memp_free(MEMP_API_MSG, msg); return conn->err; } @@ -459,7 +441,8 @@ netconn_disconnect(struct netconn *conn) err_t netconn_listen(struct netconn *conn) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; if (conn == NULL) { return ERR_VAL; @@ -472,14 +455,10 @@ netconn_listen(struct netconn *conn) } } - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - return (conn->err = ERR_MEM); - } msg->type = API_MSG_LISTEN; msg->msg.conn = conn; api_msg_post(msg); sys_mbox_fetch(conn->mbox, NULL); - memp_free(MEMP_API_MSG, msg); return conn->err; } @@ -503,7 +482,8 @@ netconn_accept(struct netconn *conn) struct netbuf * netconn_recv(struct netconn *conn) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; struct netbuf *buf; struct pbuf *p; u16_t len; @@ -564,10 +544,6 @@ netconn_recv(struct netconn *conn) buf->fromaddr = NULL; /* Let the stack know that we have taken the data. */ - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - conn->err = ERR_MEM; - return buf; - } msg->type = API_MSG_RECV; msg->msg.conn = conn; if (buf != NULL) { @@ -578,7 +554,6 @@ netconn_recv(struct netconn *conn) api_msg_post(msg); sys_mbox_fetch(conn->mbox, NULL); - memp_free(MEMP_API_MSG, msg); } else { sys_mbox_fetch(conn->recvmbox, (void *)&buf); conn->recv_avail -= buf->p->tot_len; @@ -599,7 +574,8 @@ netconn_recv(struct netconn *conn) err_t netconn_send(struct netconn *conn, struct netbuf *buf) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; if (conn == NULL) { return ERR_VAL; @@ -609,10 +585,6 @@ netconn_send(struct netconn *conn, struct netbuf *buf) return conn->err; } - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - return (conn->err = ERR_MEM); - } - LWIP_DEBUGF(API_LIB_DEBUG, ("netconn_send: sending %d bytes\n", buf->p->tot_len)); msg->type = API_MSG_SEND; msg->msg.conn = conn; @@ -620,14 +592,14 @@ netconn_send(struct netconn *conn, struct netbuf *buf) api_msg_post(msg); sys_mbox_fetch(conn->mbox, NULL); - memp_free(MEMP_API_MSG, msg); return conn->err; } err_t netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; u16_t len; if (conn == NULL) { @@ -638,9 +610,6 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy) return conn->err; } - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - return (conn->err = ERR_MEM); - } msg->type = API_MSG_WRITE; msg->msg.conn = conn; @@ -683,7 +652,6 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy) } } ret: - memp_free(MEMP_API_MSG, msg); conn->state = NETCONN_NONE; return conn->err; @@ -692,14 +660,12 @@ netconn_write(struct netconn *conn, void *dataptr, u16_t size, u8_t copy) err_t netconn_close(struct netconn *conn) { - struct api_msg *msg; + struct api_msg _msg; + struct api_msg *msg = &_msg; if (conn == NULL) { return ERR_VAL; } - if ((msg = memp_malloc(MEMP_API_MSG)) == NULL) { - return (conn->err = ERR_MEM); - } conn->state = NETCONN_CLOSE; again: @@ -713,7 +679,6 @@ netconn_close(struct netconn *conn) goto again; } conn->state = NETCONN_NONE; - memp_free(MEMP_API_MSG, msg); return conn->err; } diff --git a/src/api/tcpip.c b/src/api/tcpip.c index ce8a2ca5..f0626378 100644 --- a/src/api/tcpip.c +++ b/src/api/tcpip.c @@ -176,7 +176,6 @@ tcpip_apimsg(struct api_msg *apimsg) struct tcpip_msg *msg; msg = memp_malloc(MEMP_TCPIP_MSG); if (msg == NULL) { - memp_free(MEMP_API_MSG, apimsg); return; } msg->type = TCPIP_MSG_API; diff --git a/src/core/memp.c b/src/core/memp.c index b31812d7..74aac2b8 100644 --- a/src/core/memp.c +++ b/src/core/memp.c @@ -62,7 +62,6 @@ static const u16_t memp_sizes[MEMP_MAX] = { MEM_ALIGN_SIZE(sizeof(struct tcp_seg)), MEM_ALIGN_SIZE(sizeof(struct netbuf)), MEM_ALIGN_SIZE(sizeof(struct netconn)), - MEM_ALIGN_SIZE(sizeof(struct api_msg)), MEM_ALIGN_SIZE(sizeof(struct tcpip_msg)), MEM_ALIGN_SIZE(sizeof(struct sys_timeo)) }; @@ -76,7 +75,6 @@ static const u16_t memp_num[MEMP_MAX] = { MEMP_NUM_TCP_SEG, MEMP_NUM_NETBUF, MEMP_NUM_NETCONN, - MEMP_NUM_API_MSG, MEMP_NUM_TCPIP_MSG, MEMP_NUM_SYS_TIMEOUT }; @@ -93,7 +91,6 @@ static u8_t memp_memory[MEM_ALIGNMENT - 1 + MEMP_TYPE_SIZE(MEMP_NUM_TCP_SEG, struct tcp_seg) + MEMP_TYPE_SIZE(MEMP_NUM_NETBUF, struct netbuf) + MEMP_TYPE_SIZE(MEMP_NUM_NETCONN, struct netconn) + - MEMP_TYPE_SIZE(MEMP_NUM_API_MSG, struct api_msg) + MEMP_TYPE_SIZE(MEMP_NUM_TCPIP_MSG, struct tcpip_msg) + MEMP_TYPE_SIZE(MEMP_NUM_SYS_TIMEOUT, struct sys_timeo)]; diff --git a/src/include/lwip/memp.h b/src/include/lwip/memp.h index 1cd46fa3..9f07391a 100644 --- a/src/include/lwip/memp.h +++ b/src/include/lwip/memp.h @@ -45,7 +45,6 @@ typedef enum { MEMP_NETBUF, MEMP_NETCONN, - MEMP_API_MSG, MEMP_TCPIP_MSG, MEMP_SYS_TIMEOUT,