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:
jani 2003-01-24 09:24:44 +00:00
parent 721d237120
commit 6d0a8a85c7
4 changed files with 10 additions and 8 deletions

View File

@ -279,7 +279,7 @@ netconn_type(struct netconn *conn)
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
err_t err_t
netconn_peer(struct netconn *conn, struct ip_addr **addr, netconn_peer(struct netconn *conn, struct ip_addr *addr,
u16_t *port) u16_t *port)
{ {
switch(conn->type) { switch(conn->type) {
@ -288,11 +288,11 @@ netconn_peer(struct netconn *conn, struct ip_addr **addr,
case NETCONN_UDP: case NETCONN_UDP:
if ((conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0) if ((conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0)
return -1; return -1;
*addr = &(conn->pcb.udp->remote_ip); *addr = (conn->pcb.udp->remote_ip);
*port = conn->pcb.udp->remote_port; *port = conn->pcb.udp->remote_port;
break; break;
case NETCONN_TCP: case NETCONN_TCP:
*addr = &(conn->pcb.tcp->remote_ip); *addr = (conn->pcb.tcp->remote_ip);
*port = conn->pcb.tcp->remote_port; *port = conn->pcb.tcp->remote_port;
break; break;
} }
@ -394,6 +394,7 @@ netconn_disconnect(struct netconn *conn)
msg->type = API_MSG_DISCONNECT; msg->type = API_MSG_DISCONNECT;
msg->msg.conn = conn; msg->msg.conn = conn;
api_msg_post(msg); api_msg_post(msg);
sys_mbox_fetch(conn->mbox, NULL);
memp_freep(MEMP_API_MSG, msg); memp_freep(MEMP_API_MSG, msg);
return conn->err; return conn->err;

View File

@ -387,6 +387,7 @@ do_disconnect(struct api_msg_msg *msg)
case NETCONN_TCP: case NETCONN_TCP:
break; break;
} }
sys_mbox_post(msg->conn->mbox, NULL);
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -87,7 +87,7 @@ lwip_accept(int s, struct sockaddr *addr, int *addrlen)
{ {
struct lwip_socket *sock; struct lwip_socket *sock;
struct netconn *newconn; struct netconn *newconn;
struct ip_addr *naddr; struct ip_addr naddr;
u16_t port; u16_t port;
int newsock; 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 */ /* get the IP address and port of the remote host */
netconn_peer(newconn, &naddr, &port); 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; ((struct sockaddr_in *)addr)->sin_port = port;
newsock = alloc_socket(newconn); 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 sockaddr *to, int tolen)
{ {
struct lwip_socket *sock; struct lwip_socket *sock;
struct ip_addr remote_addr, *addr; struct ip_addr remote_addr, addr;
u16_t remote_port, port; u16_t remote_port, port;
int ret,connected; 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 /* reset the remote address and port number
of the connection */ of the connection */
if (connected) if (connected)
netconn_connect(sock->conn, addr, port); netconn_connect(sock->conn, &addr, port);
else else
netconn_disconnect(sock->conn); netconn_disconnect(sock->conn);
return ret; return ret;

View File

@ -111,7 +111,7 @@ struct netconn * netconn_new (enum netconn_type type);
err_t netconn_delete (struct netconn *conn); err_t netconn_delete (struct netconn *conn);
enum netconn_type netconn_type (struct netconn *conn); enum netconn_type netconn_type (struct netconn *conn);
err_t netconn_peer (struct netconn *conn, err_t netconn_peer (struct netconn *conn,
struct ip_addr **addr, struct ip_addr *addr,
u16_t *port); u16_t *port);
err_t netconn_addr (struct netconn *conn, err_t netconn_addr (struct netconn *conn,
struct ip_addr **addr, struct ip_addr **addr,