mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-08-23 22:56:00 +00:00
netconn: add callback arg storage
This reuses the member 'int socket' by making it a union containing both int and void pointer. See bug #56593. Signed-off-by: Simon Goldschmidt <goldsimon@gmx.de> Suggested-by: Wilfred <wilfrednilsen@hotmail.com>
This commit is contained in:
parent
f37925dad2
commit
5465fdfd69
|
@ -759,10 +759,8 @@ netconn_alloc(enum netconn_type t, netconn_callback callback)
|
||||||
sys_mbox_set_invalid(&conn->acceptmbox);
|
sys_mbox_set_invalid(&conn->acceptmbox);
|
||||||
#endif
|
#endif
|
||||||
conn->state = NETCONN_NONE;
|
conn->state = NETCONN_NONE;
|
||||||
#if LWIP_SOCKET
|
|
||||||
/* initialize socket to -1 since 0 is a valid socket */
|
/* initialize socket to -1 since 0 is a valid socket */
|
||||||
conn->socket = -1;
|
conn->callback_arg.socket = -1;
|
||||||
#endif /* LWIP_SOCKET */
|
|
||||||
conn->callback = callback;
|
conn->callback = callback;
|
||||||
#if LWIP_TCP
|
#if LWIP_TCP
|
||||||
conn->current_msg = NULL;
|
conn->current_msg = NULL;
|
||||||
|
|
|
@ -661,8 +661,8 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
||||||
* so nsock->rcvevent is >= 1 here!
|
* so nsock->rcvevent is >= 1 here!
|
||||||
*/
|
*/
|
||||||
SYS_ARCH_PROTECT(lev);
|
SYS_ARCH_PROTECT(lev);
|
||||||
recvevent = (s16_t)(-1 - newconn->socket);
|
recvevent = (s16_t)(-1 - newconn->callback_arg.socket);
|
||||||
newconn->socket = newsock;
|
newconn->callback_arg.socket = newsock;
|
||||||
SYS_ARCH_UNPROTECT(lev);
|
SYS_ARCH_UNPROTECT(lev);
|
||||||
|
|
||||||
if (newconn->callback) {
|
if (newconn->callback) {
|
||||||
|
@ -1729,7 +1729,7 @@ lwip_socket(int domain, int type, int protocol)
|
||||||
set_errno(ENFILE);
|
set_errno(ENFILE);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
conn->socket = i;
|
conn->callback_arg.socket = i;
|
||||||
done_socket(&sockets[i - LWIP_SOCKET_OFFSET]);
|
done_socket(&sockets[i - LWIP_SOCKET_OFFSET]);
|
||||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
|
||||||
set_errno(0);
|
set_errno(0);
|
||||||
|
@ -2478,7 +2478,7 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
|
||||||
|
|
||||||
/* Get socket */
|
/* Get socket */
|
||||||
if (conn) {
|
if (conn) {
|
||||||
s = conn->socket;
|
s = conn->callback_arg.socket;
|
||||||
if (s < 0) {
|
if (s < 0) {
|
||||||
/* Data comes in right away after an accept, even though
|
/* Data comes in right away after an accept, even though
|
||||||
* the server task might not have created a new socket yet.
|
* the server task might not have created a new socket yet.
|
||||||
|
@ -2486,16 +2486,16 @@ event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
|
||||||
* will use the data later. Note that only receive events
|
* will use the data later. Note that only receive events
|
||||||
* can happen before the new socket is set up. */
|
* can happen before the new socket is set up. */
|
||||||
SYS_ARCH_PROTECT(lev);
|
SYS_ARCH_PROTECT(lev);
|
||||||
if (conn->socket < 0) {
|
if (conn->callback_arg.socket < 0) {
|
||||||
if (evt == NETCONN_EVT_RCVPLUS) {
|
if (evt == NETCONN_EVT_RCVPLUS) {
|
||||||
/* conn->socket is -1 on initialization
|
/* conn->socket is -1 on initialization
|
||||||
lwip_accept adjusts sock->recvevent if conn->socket < -1 */
|
lwip_accept adjusts sock->recvevent if conn->socket < -1 */
|
||||||
conn->socket--;
|
conn->callback_arg.socket--;
|
||||||
}
|
}
|
||||||
SYS_ARCH_UNPROTECT(lev);
|
SYS_ARCH_UNPROTECT(lev);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s = conn->socket;
|
s = conn->callback_arg.socket;
|
||||||
SYS_ARCH_UNPROTECT(lev);
|
SYS_ARCH_UNPROTECT(lev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -246,10 +246,10 @@ struct netconn {
|
||||||
all threads when closing while threads are waiting. */
|
all threads when closing while threads are waiting. */
|
||||||
int mbox_threads_waiting;
|
int mbox_threads_waiting;
|
||||||
#endif
|
#endif
|
||||||
/** only used for socket layer */
|
union {
|
||||||
#if LWIP_SOCKET
|
|
||||||
int socket;
|
int socket;
|
||||||
#endif /* LWIP_SOCKET */
|
void *ptr;
|
||||||
|
} callback_arg;
|
||||||
#if LWIP_SO_SNDTIMEO
|
#if LWIP_SO_SNDTIMEO
|
||||||
/** timeout to wait for sending data (which means enqueueing data for sending
|
/** timeout to wait for sending data (which means enqueueing data for sending
|
||||||
in internal buffers) in milliseconds */
|
in internal buffers) in milliseconds */
|
||||||
|
@ -373,6 +373,9 @@ err_t netconn_err(struct netconn *conn);
|
||||||
#define netconn_clear_flags(conn, clr_flags) do { (conn)->flags = (u8_t)((conn)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
|
#define netconn_clear_flags(conn, clr_flags) do { (conn)->flags = (u8_t)((conn)->flags & (u8_t)(~(clr_flags) & 0xff)); } while(0)
|
||||||
#define netconn_is_flag_set(conn, flag) (((conn)->flags & (flag)) != 0)
|
#define netconn_is_flag_set(conn, flag) (((conn)->flags & (flag)) != 0)
|
||||||
|
|
||||||
|
#define netconn_set_callback_arg(conn, arg) do { (conn)->callback_arg.ptr = (arg); } while(0)
|
||||||
|
#define netconn_get_callback_arg(conn) ((conn)->callback_arg.ptr)
|
||||||
|
|
||||||
/** 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) do { if(val) { \
|
#define netconn_set_nonblocking(conn, val) do { if(val) { \
|
||||||
netconn_set_flags(conn, NETCONN_FLAG_NON_BLOCKING); \
|
netconn_set_flags(conn, NETCONN_FLAG_NON_BLOCKING); \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user