diff --git a/src/api/api_msg.c b/src/api/api_msg.c index cfdc4a58..23c05e89 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -54,6 +54,12 @@ #include +#define SET_NONBLOCKING_CONNECT(conn, val) do { if(val) { \ + (conn)->flags |= NETCONN_FLAG_IN_NONBLOCKING_CONNECT; \ +} else { \ + (conn)->flags &= ~ NETCONN_FLAG_IN_NONBLOCKING_CONNECT; }} while(0) +#define IN_NONBLOCKING_CONNECT(conn) (((conn)->flags & NETCONN_FLAG_IN_NONBLOCKING_CONNECT) != 0) + /* forward declarations */ #if LWIP_TCP static err_t do_writemore(struct netconn *conn); @@ -362,8 +368,8 @@ err_tcp(void *arg, err_t err) (old_state == NETCONN_CONNECT)) { /* calling do_writemore/do_close_internal is not necessary since the pcb has already been deleted! */ - int was_nonblocking_connect = conn->in_non_blocking_connect; - conn->in_non_blocking_connect = 0; + int was_nonblocking_connect = IN_NONBLOCKING_CONNECT(conn); + SET_NONBLOCKING_CONNECT(conn, 0); if (!was_nonblocking_connect) { /* set error return code */ @@ -610,8 +616,7 @@ netconn_alloc(enum netconn_type t, netconn_callback callback) #if LWIP_SO_RCVBUF conn->recv_bufsize = RECV_BUFSIZE_DEFAULT; #endif /* LWIP_SO_RCVBUF */ - conn->non_blocking = 0; - conn->in_non_blocking_connect = 0; + conn->flags = 0; return conn; } @@ -871,7 +876,7 @@ do_connected(void *arg, struct tcp_pcb *pcb, err_t err) LWIP_ASSERT("conn->state == NETCONN_CONNECT", conn->state == NETCONN_CONNECT); LWIP_ASSERT("(conn->current_msg != NULL) || conn->in_non_blocking_connect", - (conn->current_msg != NULL) || conn->in_non_blocking_connect); + (conn->current_msg != NULL) || IN_NONBLOCKING_CONNECT(conn)); if (conn->current_msg != NULL) { conn->current_msg->err = err; @@ -879,8 +884,8 @@ do_connected(void *arg, struct tcp_pcb *pcb, err_t err) if ((conn->type == NETCONN_TCP) && (err == ERR_OK)) { setup_tcp(conn); } - was_blocking = !conn->in_non_blocking_connect; - conn->in_non_blocking_connect = 0; + was_blocking = !IN_NONBLOCKING_CONNECT(conn); + SET_NONBLOCKING_CONNECT(conn, 0); conn->current_msg = NULL; conn->state = NETCONN_NONE; if (!was_blocking) { @@ -935,9 +940,10 @@ do_connect(struct api_msg_msg *msg) msg->err = tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port, do_connected); if (msg->err == ERR_OK) { + u8_t non_blocking = netconn_is_nonblocking(msg->conn); msg->conn->state = NETCONN_CONNECT; - msg->conn->in_non_blocking_connect = msg->conn->non_blocking; - if (msg->conn->non_blocking) { + SET_NONBLOCKING_CONNECT(msg->conn, non_blocking); + if (non_blocking) { msg->err = ERR_INPROGRESS; } else { msg->conn->current_msg = msg; diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h index 4446a492..13771d61 100644 --- a/src/include/lwip/api.h +++ b/src/include/lwip/api.h @@ -57,6 +57,21 @@ extern "C" { #define NETCONN_COPY 0x01 #define NETCONN_MORE 0x02 +/* Flags for struct netconn.flags (u8_t) */ + +/** TCP: when data passed to netconn_write doesn't fit into the send buffer, + this temporarily stores whether to wake up the original application task + if data couldn't be sent in the first try. */ +#define NETCONN_FLAG_WRITE_DELAYED 0x01 +/** Should this netconn avoid blocking? */ +#define NETCONN_FLAG_NON_BLOCKING 0x02 +/** Was the last connect action a non-blocking one? */ +#define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04 +/** If this is set, a TCP netconn must call netconn_recved() to update + the TCP receive window (done automatically if not set). */ +#define NETCONN_FLAG_UPDATE_TCPWIN_MANUALLY 0x08 + + /* Helpers to process several netconn_types by the same code */ #define NETCONNTYPE_GROUP(t) (t&0xF0) #define NETCONNTYPE_DATAGRAM(t) (t&0xE0) @@ -148,25 +163,16 @@ struct netconn { int recv_bufsize; #endif /* LWIP_SO_RCVBUF */ s16_t recv_avail; + u8_t flags; #if LWIP_TCP + /** TCP: when data passed to netconn_write doesn't fit into the send buffer, + this temporarily stores how much is already sent. */ + size_t write_offset; /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores the message. Also used during connect and close. */ struct api_msg_msg *current_msg; - /** TCP: when data passed to netconn_write doesn't fit into the send buffer, - this temporarily stores how much is already sent. */ - size_t write_offset; -#if LWIP_TCPIP_CORE_LOCKING - /** TCP: when data passed to netconn_write doesn't fit into the send buffer, - this temporarily stores whether to wake up the original application task - if data couldn't be sent in the first try. @todo: combine in 'flags' */ - u8_t write_delayed; -#endif /* LWIP_TCPIP_CORE_LOCKING */ #endif /* LWIP_TCP */ - /** Should this netconn avoid blocking? @todo: combine in 'flags' */ - u8_t non_blocking; - /** Was the last connect action a non-blocking one? @todo: combine in 'flags' */ - u8_t in_non_blocking_connect; /** A callback function that is informed about events for this netconn */ netconn_callback callback; }; @@ -227,9 +233,12 @@ err_t netconn_gethostbyname(const char *name, ip_addr_t *addr); #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize) /** Set the blocking status of netconn calls (@todo: write/send is missing) */ -#define netconn_set_nonblocking(conn, val) ((conn)->non_blocking = (val)) +#define netconn_set_nonblocking(conn, val) do { if(val) { \ + (conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \ +} else { \ + (conn)->flags &= ~ NETCONN_FLAG_NON_BLOCKING; }} while(0) /** Get the blocking status of netconn calls (@todo: write/send is missing) */ -#define netconn_is_nonblocking(conn) ((conn)->non_blocking) +#define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0) #ifdef __cplusplus }