mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-04 21:39:49 +00:00
Fix locking for disconnect operation (use post and fetch on the connection's mbox in the two threads like other operations).Make netconn_peer take a pointer to addr instead of pointer to pointer to addr.Addr is a 4 byte struct an IP address so use structure assignment not just pointer assignment when saving the peer.This way the address is really saved :fixes bug #1897
This commit is contained in:
parent
721d237120
commit
6d0a8a85c7
@ -279,7 +279,7 @@ netconn_type(struct netconn *conn)
|
||||
}
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
err_t
|
||||
netconn_peer(struct netconn *conn, struct ip_addr **addr,
|
||||
netconn_peer(struct netconn *conn, struct ip_addr *addr,
|
||||
u16_t *port)
|
||||
{
|
||||
switch(conn->type) {
|
||||
@ -288,11 +288,11 @@ netconn_peer(struct netconn *conn, struct ip_addr **addr,
|
||||
case NETCONN_UDP:
|
||||
if ((conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0)
|
||||
return -1;
|
||||
*addr = &(conn->pcb.udp->remote_ip);
|
||||
*addr = (conn->pcb.udp->remote_ip);
|
||||
*port = conn->pcb.udp->remote_port;
|
||||
break;
|
||||
case NETCONN_TCP:
|
||||
*addr = &(conn->pcb.tcp->remote_ip);
|
||||
*addr = (conn->pcb.tcp->remote_ip);
|
||||
*port = conn->pcb.tcp->remote_port;
|
||||
break;
|
||||
}
|
||||
@ -394,6 +394,7 @@ netconn_disconnect(struct netconn *conn)
|
||||
msg->type = API_MSG_DISCONNECT;
|
||||
msg->msg.conn = conn;
|
||||
api_msg_post(msg);
|
||||
sys_mbox_fetch(conn->mbox, NULL);
|
||||
memp_freep(MEMP_API_MSG, msg);
|
||||
return conn->err;
|
||||
|
||||
|
@ -387,6 +387,7 @@ do_disconnect(struct api_msg_msg *msg)
|
||||
case NETCONN_TCP:
|
||||
break;
|
||||
}
|
||||
sys_mbox_post(msg->conn->mbox, NULL);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
|
@ -87,7 +87,7 @@ lwip_accept(int s, struct sockaddr *addr, int *addrlen)
|
||||
{
|
||||
struct lwip_socket *sock;
|
||||
struct netconn *newconn;
|
||||
struct ip_addr *naddr;
|
||||
struct ip_addr naddr;
|
||||
u16_t port;
|
||||
int newsock;
|
||||
|
||||
@ -101,7 +101,7 @@ lwip_accept(int s, struct sockaddr *addr, int *addrlen)
|
||||
/* get the IP address and port of the remote host */
|
||||
netconn_peer(newconn, &naddr, &port);
|
||||
|
||||
((struct sockaddr_in *)addr)->sin_addr.s_addr = naddr->addr;
|
||||
((struct sockaddr_in *)addr)->sin_addr.s_addr = naddr.addr;
|
||||
((struct sockaddr_in *)addr)->sin_port = port;
|
||||
|
||||
newsock = alloc_socket(newconn);
|
||||
@ -345,7 +345,7 @@ lwip_sendto(int s, void *data, int size, unsigned int flags,
|
||||
struct sockaddr *to, int tolen)
|
||||
{
|
||||
struct lwip_socket *sock;
|
||||
struct ip_addr remote_addr, *addr;
|
||||
struct ip_addr remote_addr, addr;
|
||||
u16_t remote_port, port;
|
||||
int ret,connected;
|
||||
|
||||
@ -366,7 +366,7 @@ lwip_sendto(int s, void *data, int size, unsigned int flags,
|
||||
/* reset the remote address and port number
|
||||
of the connection */
|
||||
if (connected)
|
||||
netconn_connect(sock->conn, addr, port);
|
||||
netconn_connect(sock->conn, &addr, port);
|
||||
else
|
||||
netconn_disconnect(sock->conn);
|
||||
return ret;
|
||||
|
@ -111,7 +111,7 @@ struct netconn * netconn_new (enum netconn_type type);
|
||||
err_t netconn_delete (struct netconn *conn);
|
||||
enum netconn_type netconn_type (struct netconn *conn);
|
||||
err_t netconn_peer (struct netconn *conn,
|
||||
struct ip_addr **addr,
|
||||
struct ip_addr *addr,
|
||||
u16_t *port);
|
||||
err_t netconn_addr (struct netconn *conn,
|
||||
struct ip_addr **addr,
|
||||
|
Loading…
x
Reference in New Issue
Block a user