lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lwip-users] listening connection issue


From: JM
Subject: [lwip-users] listening connection issue
Date: Tue, 16 Mar 2010 05:03:46 -0700 (PDT)

I'm using tcp_listen on 1.3.2 RAW mode and have some questions about if I'm doing everything correctly.  This is being used to configure an embedded system via a web browser.  It mostly works, but sometimes will refuse incoming connections and I have no idea why.  It always works the first time, but after that it occasionally refuses to ACK subsequent connection requests (SYN).  I'm attempting just one connection at a time.  I enabled debug and while I don't currently have the output saved (it was difficult to replicate the issue), I didn't see any errors.  I saw the SYN come in from the remote but no processing afterward.  Anyway, here's how I'm writing the code; this is my main concern:

listen_pcb is a global variable so I can close the listening port later.

void httpd_init(void)
{
  listen_pcb = tcp_new();
  tcp_bind(listen_pcb, IP_ADDR_ANY, 80);
  listen_pcb = tcp_listen(listen_pcb);
  tcp_accept(listen_pcb, http_accept);
}

conn_err never gets called but is defined.

err_t http_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
    tcp_recv(pcb, http_recv);
    tcp_err(pcb, conn_err);
    return 0;
}

err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
    unsigned char *buf_ptr;
    buf_ptr = malloc(10000);
    /* do some stuff with incoming data and generate an output string on buf_ptr */

    tcp_recved(pcb, p->tot_len);
    pbuf_free(p);

    tcp_write(pcb, buf_ptr, strlen(buf_ptr), 0);
    tcp_output(pcb);
    tcp_close(pcb);   
    free(buf_ptr);
}

I call httpd_init, and that's all.

Is calling tcp_close immediately after tcp_output a problem?  In tcp_write, I don't specify the "copy" option because MEM_SIZE isn't big enough and I really want to avoid increasing that to save RAM which would be infrequently used.  I have tried using tcp_sent callback to set a flag in order determine when all data has been sent, but discovered that waiting in http_recv for this flag doesn't work; the tcp_sent callback never gets called while in http_recv.  If all else fails, where would I look (i.e. a breakpoint) or what debug options would be most important to track this down?



#define TCP_MSS                1460
#define PBUF_POOL_BUFSIZE    512
#define PBUF_POOL_SIZE        12
#define TCP_WND             (TCP_MSS*4)
#define TCP_SND_BUF         (TCP_MSS*4)
#define MEM_SIZE            1024
#define MEMP_NUM_PBUF        10
#define MEMP_NUM_TCP_SEG     (2 * TCP_SND_QUEUELEN)       
#define TCP_SND_QUEUELEN    (4 * (TCP_SND_BUF/TCP_MSS))   

#define NO_SYS                        1
#define SYS_LIGHTWEIGHT_PROT         0
#define MEMP_NUM_UDP_PCB            2
#define LWIP_NETCONN                 0
#define LWIP_SOCKET                 0
#define LWIP_TCP                     1
#define MEM_ALIGNMENT                 4
#define MEMP_NUM_TCP_PCB             1
#define MEMP_NUM_TCP_PCB_LISTEN     2
#define ARP_TABLE_SIZE                 1
#define IP_FRAG                     0
#define MEMP_NUM_REASSDATA             0
#define LWIP_DHCP                     1
#define LWIP_DNS                     1
#define DNS_TABLE_SIZE                          1
#define DNS_USES_STATIC_BUF                     0
#define    DNS_MAX_SERVERS                1
#define ARP_QUEUEING                 1
#define MEMP_NUM_ARP_QUEUE            1


reply via email to

[Prev in Thread] Current Thread [Next in Thread]