mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
Merge 3 u8_t for netconn-internal status into one u8_t 'flags' to prevent waisting memory when adding more flags
This commit is contained in:
parent
6fe258c6bc
commit
a84590273d
@ -54,6 +54,12 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#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 */
|
/* forward declarations */
|
||||||
#if LWIP_TCP
|
#if LWIP_TCP
|
||||||
static err_t do_writemore(struct netconn *conn);
|
static err_t do_writemore(struct netconn *conn);
|
||||||
@ -362,8 +368,8 @@ err_tcp(void *arg, err_t err)
|
|||||||
(old_state == NETCONN_CONNECT)) {
|
(old_state == NETCONN_CONNECT)) {
|
||||||
/* calling do_writemore/do_close_internal is not necessary
|
/* calling do_writemore/do_close_internal is not necessary
|
||||||
since the pcb has already been deleted! */
|
since the pcb has already been deleted! */
|
||||||
int was_nonblocking_connect = conn->in_non_blocking_connect;
|
int was_nonblocking_connect = IN_NONBLOCKING_CONNECT(conn);
|
||||||
conn->in_non_blocking_connect = 0;
|
SET_NONBLOCKING_CONNECT(conn, 0);
|
||||||
|
|
||||||
if (!was_nonblocking_connect) {
|
if (!was_nonblocking_connect) {
|
||||||
/* set error return code */
|
/* set error return code */
|
||||||
@ -610,8 +616,7 @@ netconn_alloc(enum netconn_type t, netconn_callback callback)
|
|||||||
#if LWIP_SO_RCVBUF
|
#if LWIP_SO_RCVBUF
|
||||||
conn->recv_bufsize = RECV_BUFSIZE_DEFAULT;
|
conn->recv_bufsize = RECV_BUFSIZE_DEFAULT;
|
||||||
#endif /* LWIP_SO_RCVBUF */
|
#endif /* LWIP_SO_RCVBUF */
|
||||||
conn->non_blocking = 0;
|
conn->flags = 0;
|
||||||
conn->in_non_blocking_connect = 0;
|
|
||||||
return conn;
|
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->state == NETCONN_CONNECT", conn->state == NETCONN_CONNECT);
|
||||||
LWIP_ASSERT("(conn->current_msg != NULL) || conn->in_non_blocking_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) {
|
if (conn->current_msg != NULL) {
|
||||||
conn->current_msg->err = err;
|
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)) {
|
if ((conn->type == NETCONN_TCP) && (err == ERR_OK)) {
|
||||||
setup_tcp(conn);
|
setup_tcp(conn);
|
||||||
}
|
}
|
||||||
was_blocking = !conn->in_non_blocking_connect;
|
was_blocking = !IN_NONBLOCKING_CONNECT(conn);
|
||||||
conn->in_non_blocking_connect = 0;
|
SET_NONBLOCKING_CONNECT(conn, 0);
|
||||||
conn->current_msg = NULL;
|
conn->current_msg = NULL;
|
||||||
conn->state = NETCONN_NONE;
|
conn->state = NETCONN_NONE;
|
||||||
if (!was_blocking) {
|
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->err = tcp_connect(msg->conn->pcb.tcp, msg->msg.bc.ipaddr,
|
||||||
msg->msg.bc.port, do_connected);
|
msg->msg.bc.port, do_connected);
|
||||||
if (msg->err == ERR_OK) {
|
if (msg->err == ERR_OK) {
|
||||||
|
u8_t non_blocking = netconn_is_nonblocking(msg->conn);
|
||||||
msg->conn->state = NETCONN_CONNECT;
|
msg->conn->state = NETCONN_CONNECT;
|
||||||
msg->conn->in_non_blocking_connect = msg->conn->non_blocking;
|
SET_NONBLOCKING_CONNECT(msg->conn, non_blocking);
|
||||||
if (msg->conn->non_blocking) {
|
if (non_blocking) {
|
||||||
msg->err = ERR_INPROGRESS;
|
msg->err = ERR_INPROGRESS;
|
||||||
} else {
|
} else {
|
||||||
msg->conn->current_msg = msg;
|
msg->conn->current_msg = msg;
|
||||||
|
@ -57,6 +57,21 @@ extern "C" {
|
|||||||
#define NETCONN_COPY 0x01
|
#define NETCONN_COPY 0x01
|
||||||
#define NETCONN_MORE 0x02
|
#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 */
|
/* Helpers to process several netconn_types by the same code */
|
||||||
#define NETCONNTYPE_GROUP(t) (t&0xF0)
|
#define NETCONNTYPE_GROUP(t) (t&0xF0)
|
||||||
#define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
|
#define NETCONNTYPE_DATAGRAM(t) (t&0xE0)
|
||||||
@ -148,25 +163,16 @@ struct netconn {
|
|||||||
int recv_bufsize;
|
int recv_bufsize;
|
||||||
#endif /* LWIP_SO_RCVBUF */
|
#endif /* LWIP_SO_RCVBUF */
|
||||||
s16_t recv_avail;
|
s16_t recv_avail;
|
||||||
|
u8_t flags;
|
||||||
#if LWIP_TCP
|
#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,
|
/** TCP: when data passed to netconn_write doesn't fit into the send buffer,
|
||||||
this temporarily stores the message.
|
this temporarily stores the message.
|
||||||
Also used during connect and close. */
|
Also used during connect and close. */
|
||||||
struct api_msg_msg *current_msg;
|
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 */
|
#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 */
|
/** A callback function that is informed about events for this netconn */
|
||||||
netconn_callback callback;
|
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)
|
#define netconn_recv_bufsize(conn) ((conn)->recv_bufsize)
|
||||||
|
|
||||||
/** Set the blocking status of netconn calls (@todo: write/send is missing) */
|
/** 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) */
|
/** 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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user