Hi,

I'm having troubles with tcp server based on RAW API. I'm using tcpip_callback 
function, which causes delays (about 200ms). When I call directly tcp_write 
function everything is ok (no delays). I wrote simple server to illustrate my 
problem:

// -----------------------------------------------------------------
#include "lwip/opt.h"
#include "lwip/mem.h"
#include "lwip/tcp.h"
#include "lwip/tcpip.h"

void tcpSendReply(void *ctx)
{
        unsigned char data[10] = "REPLY!!!\r\n";
        struct tcp_pcb *pcb = ctx;
        tcp_write(pcb, data, sizeof(data), TCP_WRITE_FLAG_COPY);
}

err_t callbackServerRecv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t 
err)
{
        if (err == ERR_OK && p != NULL)
        {
                tcp_recved(pcb, p->tot_len);

                // Variant 1
                //tcpip_callback_with_block(tcpSendReply, pcb, 0);
                // Variant 2
                tcpSendReply(pcb);

                pbuf_free(p);
        }
        else if (err == ERR_OK && p == NULL)
        {
                tcp_close(pcb);
        }
        return ERR_OK;
}

err_t callbackServerAccept(void *arg, struct tcp_pcb *newpcb, err_t err)
{
        tcp_recv(newpcb, callbackServerRecv);
        return ERR_OK;
}

void callbackServerInit()
{
        struct tcp_pcb *pcb;
        pcb = tcp_new();
        tcp_bind(pcb, IP_ADDR_ANY, 9923);
        pcb = tcp_listen(pcb);
        tcp_accept(pcb, callbackServerAccept);
}
// -----------------------------------------------------------------

It will be great if someone could test this server and check results in 
Wireshark (Variant 1 and 2 - see code). All you need to do is paste above code 
to your project and call callbackServerInit() function. Then on PC run 'telnet 
x.x.x.x 9923'. Server replies when you type any character.

I attach Wireshark capture files (Variant 1 i 2).

Best regards

Attachment: variant1_callback.pcap
Description: Binary data

Attachment: variant2_directly.pcap
Description: Binary data

_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users

Reply via email to