Check state == CLOSED in tcp_bind and tcp_connect to prevent binding/connecting twice (using LWIP_ERROR: can be disabled)

This commit is contained in:
goldsimon 2007-11-25 18:37:34 +00:00
parent 4dcfdac2f5
commit 5743b11925

View File

@ -256,6 +256,8 @@ tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
{
struct tcp_pcb *cpcb;
LWIP_ERROR("tcp_connect: can only bind in state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
if (port == 0) {
port = tcp_new_port();
}
@ -343,7 +345,7 @@ tcp_listen(struct tcp_pcb *pcb)
{
struct tcp_pcb_listen *lpcb;
LWIP_ERROR("pcb not already connected", pcb->state == CLOSED, return NULL);
LWIP_ERROR("tcp_listen: pcb already connected", pcb->state == CLOSED, return NULL);
/* already listening? */
if (pcb->state == LISTEN) {
@ -474,6 +476,8 @@ tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port,
err_t ret;
u32_t iss;
LWIP_ERROR("tcp_connect: can only connected from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port));
if (ipaddr != NULL) {
pcb->remote_ip = *ipaddr;