mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-12-28 18:16:13 +00:00
api.h, api_lib.c, api_msg.c: Add macro API_EVENT in the same spirit than TCP_EVENT_xxx macros to get a code more readable. It could also help to remove some code (like we have talk in "patch #5919 : Create compile switch to remove select code"), but it could be done later.
This commit is contained in:
parent
270c7c1110
commit
7077d51f1f
@ -19,6 +19,12 @@ HISTORY
|
||||
|
||||
++ New features:
|
||||
|
||||
2007-10-24 Frédéric Bernon
|
||||
* api.h, api_lib.c, api_msg.c: Add macro API_EVENT in the same spirit than
|
||||
TCP_EVENT_xxx macros to get a code more readable. It could also help to remove
|
||||
some code (like we have talk in "patch #5919 : Create compile switch to remove
|
||||
select code"), but it could be done later.
|
||||
|
||||
2007-10-08 Simon Goldschmidt
|
||||
* many files: Changed initialization: many init functions are not needed any
|
||||
more since we now rely on the compiler initializing global and static
|
||||
|
@ -385,8 +385,7 @@ netconn_accept(struct netconn *conn)
|
||||
#endif /* LWIP_SO_RCVTIMEO*/
|
||||
|
||||
/* Register event with callback */
|
||||
if (conn->callback)
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVMINUS, 0);
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, 0);
|
||||
|
||||
return newconn;
|
||||
}
|
||||
@ -449,14 +448,12 @@ netconn_recv(struct netconn *conn)
|
||||
}
|
||||
|
||||
/* Register event with callback */
|
||||
if (conn->callback) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVMINUS, len);
|
||||
}
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, len);
|
||||
|
||||
/* If we are closed, we indicate that we no longer wish to use the socket */
|
||||
if (p == NULL) {
|
||||
memp_free(MEMP_NETBUF, buf);
|
||||
/* Avoid to loose any previous error code */
|
||||
/* Avoid to lose any previous error code */
|
||||
if (conn->err == ERR_OK) {
|
||||
conn->err = ERR_CLSD;
|
||||
}
|
||||
@ -490,8 +487,7 @@ netconn_recv(struct netconn *conn)
|
||||
if (buf!=NULL) {
|
||||
conn->recv_avail -= buf->p->tot_len;
|
||||
/* Register event with callback */
|
||||
if (conn->callback)
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVMINUS, buf->p->tot_len);
|
||||
API_EVENT(conn, NETCONN_EVT_RCVMINUS, buf->p->tot_len);
|
||||
}
|
||||
#endif /* (LWIP_UDP || LWIP_RAW) */
|
||||
}
|
||||
|
@ -82,9 +82,7 @@ recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p,
|
||||
|
||||
conn->recv_avail += p->tot_len;
|
||||
/* Register event with callback */
|
||||
if (conn->callback) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
|
||||
}
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
|
||||
sys_mbox_post(conn->recvmbox, buf);
|
||||
}
|
||||
|
||||
@ -128,9 +126,7 @@ recv_udp(void *arg, struct udp_pcb *pcb, struct pbuf *p,
|
||||
|
||||
conn->recv_avail += p->tot_len;
|
||||
/* Register event with callback */
|
||||
if (conn->callback) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
|
||||
}
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len);
|
||||
sys_mbox_post(conn->recvmbox, buf);
|
||||
}
|
||||
#endif /* LWIP_UDP */
|
||||
@ -165,9 +161,7 @@ recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
||||
len = 0;
|
||||
}
|
||||
/* Register event with callback */
|
||||
if (conn->callback) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, len);
|
||||
}
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, len);
|
||||
sys_mbox_post(conn->recvmbox, p);
|
||||
|
||||
return ERR_OK;
|
||||
@ -203,7 +197,7 @@ poll_tcp(void *arg, struct tcp_pcb *pcb)
|
||||
|
||||
/**
|
||||
* Sent callback function for TCP netconns.
|
||||
* Signals the conn->sem and calls conn->callback.
|
||||
* Signals the conn->sem and calls API_EVENT.
|
||||
* netconn_write waits for conn->sem if send buffer is low.
|
||||
*
|
||||
* @see tcp.h (struct tcp_pcb.sent) for parameters and return value
|
||||
@ -223,9 +217,9 @@ sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len)
|
||||
do_close_internal(conn);
|
||||
}
|
||||
|
||||
if (conn && conn->callback) {
|
||||
if (conn) {
|
||||
if ((conn->pcb.tcp != NULL) && (tcp_sndbuf(conn->pcb.tcp) > TCP_SNDLOWAT)) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_SENDPLUS, len);
|
||||
API_EVENT(conn, NETCONN_EVT_SENDPLUS, len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -234,7 +228,7 @@ sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len)
|
||||
|
||||
/**
|
||||
* Error callback function for TCP netconns.
|
||||
* Signals conn->sem, posts to all conn mboxes and calls conn->callback.
|
||||
* Signals conn->sem, posts to all conn mboxes and calls API_EVENT.
|
||||
* The application thread has then to decide what to do.
|
||||
*
|
||||
* @see tcp.h (struct tcp_pcb.err) for parameters
|
||||
@ -252,9 +246,7 @@ err_tcp(void *arg, err_t err)
|
||||
conn->err = err;
|
||||
if (conn->recvmbox != SYS_MBOX_NULL) {
|
||||
/* Register event with callback */
|
||||
if (conn->callback) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
}
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
sys_mbox_post(conn->recvmbox, NULL);
|
||||
}
|
||||
if (conn->mbox != SYS_MBOX_NULL && conn->state == NETCONN_CONNECT) {
|
||||
@ -262,10 +254,8 @@ err_tcp(void *arg, err_t err)
|
||||
sys_mbox_post(conn->mbox, NULL);
|
||||
}
|
||||
if (conn->acceptmbox != SYS_MBOX_NULL) {
|
||||
/* Register event with callback */
|
||||
if (conn->callback) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
}
|
||||
/* Register event with callback */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
sys_mbox_post(conn->acceptmbox, NULL);
|
||||
}
|
||||
if ((conn->state == NETCONN_WRITE) || (conn->state == NETCONN_CLOSE)) {
|
||||
@ -341,9 +331,7 @@ accept_function(void *arg, struct tcp_pcb *newpcb, err_t err)
|
||||
newconn->acceptmbox = SYS_MBOX_NULL;
|
||||
newconn->err = err;
|
||||
/* Register event with callback */
|
||||
if (conn->callback) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
}
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
/* We have to set the callback here even though
|
||||
* the new socket is unknown. Mark the socket as -1. */
|
||||
newconn->callback = conn->callback;
|
||||
@ -469,13 +457,10 @@ do_close_internal(struct netconn *conn)
|
||||
tcp_arg(conn->pcb.tcp, NULL);
|
||||
conn->pcb.tcp = NULL;
|
||||
conn->err = ERR_OK;
|
||||
/* Trigger select() in socket layer */
|
||||
if (conn->callback) {
|
||||
/* this should send something else so the errorfd is set,
|
||||
not the read and write fd! */
|
||||
(*conn->callback)(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
(*conn->callback)(conn, NETCONN_EVT_SENDPLUS, 0);
|
||||
}
|
||||
/* Trigger select() in socket layer. This send should something else so the
|
||||
errorfd is set, not the read and write fd! */
|
||||
API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
|
||||
/* wake up the application task */
|
||||
sys_mbox_post(conn->mbox, NULL);
|
||||
}
|
||||
@ -510,7 +495,7 @@ do_delconn(struct api_msg_msg *msg)
|
||||
case NETCONN_TCP:
|
||||
msg->conn->state = NETCONN_CLOSE;
|
||||
do_close_internal(msg->conn);
|
||||
/* conn->callback is called inside do_close_internal, before releasing
|
||||
/* API_EVENT is called inside do_close_internal, before releasing
|
||||
the application thread, so we can return at this point! */
|
||||
return;
|
||||
#endif /* LWIP_TCP */
|
||||
@ -520,13 +505,10 @@ do_delconn(struct api_msg_msg *msg)
|
||||
}
|
||||
/* tcp netconns don't come here! */
|
||||
|
||||
/* Trigger select() in socket layer */
|
||||
if (msg->conn->callback) {
|
||||
/* this send should something else so the errorfd is set,
|
||||
not the read and write fd! */
|
||||
(*msg->conn->callback)(msg->conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
(*msg->conn->callback)(msg->conn, NETCONN_EVT_SENDPLUS, 0);
|
||||
}
|
||||
/* Trigger select() in socket layer. This send should something else so the
|
||||
errorfd is set, not the read and write fd! */
|
||||
API_EVENT(msg->conn, NETCONN_EVT_RCVPLUS, 0);
|
||||
API_EVENT(msg->conn, NETCONN_EVT_SENDPLUS, 0);
|
||||
|
||||
if (msg->conn->mbox != SYS_MBOX_NULL) {
|
||||
sys_mbox_post(msg->conn->mbox, NULL);
|
||||
@ -814,9 +796,8 @@ do_writemore(struct netconn *conn)
|
||||
}
|
||||
err = tcp_output_nagle(conn->pcb.tcp);
|
||||
conn->err = err;
|
||||
if ((conn->callback) && (err == ERR_OK) &&
|
||||
(tcp_sndbuf(conn->pcb.tcp) <= TCP_SNDLOWAT)) {
|
||||
(*conn->callback)(conn, NETCONN_EVT_SENDMINUS, len);
|
||||
if ((err == ERR_OK) && (tcp_sndbuf(conn->pcb.tcp) <= TCP_SNDLOWAT)) {
|
||||
API_EVENT(conn, NETCONN_EVT_SENDMINUS, len);
|
||||
}
|
||||
} else if (err == ERR_MEM) {
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
|
@ -53,6 +53,7 @@ extern "C" {
|
||||
* the same byte order as in the corresponding pcb.
|
||||
*/
|
||||
|
||||
/* Flags for netconn_write */
|
||||
#define NETCONN_NOCOPY 0x00
|
||||
#define NETCONN_COPY 0x01
|
||||
|
||||
@ -128,6 +129,10 @@ struct netconn {
|
||||
void (* callback)(struct netconn *, enum netconn_evt, u16_t len);
|
||||
};
|
||||
|
||||
/* Register an Network connection event */
|
||||
#define API_EVENT(c,e,l) if (c->callback) { \
|
||||
(*c->callback)(c, e, l); \
|
||||
}
|
||||
|
||||
/* Network connection functions: */
|
||||
#define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL)
|
||||
|
Loading…
Reference in New Issue
Block a user